Skip to content

Commit 719b890

Browse files
committed
Demo project in C#
1 parent 3ca3e2e commit 719b890

File tree

6 files changed

+179
-0
lines changed

6 files changed

+179
-0
lines changed

Demo.CS/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
5+
</startup>
6+
</configuration>

Demo.CS/Demo.CS.csproj

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{3F5E30BE-D053-4B94-A671-88CA9C0754B9}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>Demo.CS</RootNamespace>
11+
<AssemblyName>Demo.CS</AssemblyName>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<PlatformTarget>AnyCPU</PlatformTarget>
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<PlatformTarget>AnyCPU</PlatformTarget>
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="System" />
36+
<Reference Include="System.Configuration" />
37+
<Reference Include="System.Core" />
38+
<Reference Include="System.Xml.Linq" />
39+
<Reference Include="Microsoft.CSharp" />
40+
<Reference Include="System.Net.Http" />
41+
<Reference Include="System.Xml" />
42+
</ItemGroup>
43+
<ItemGroup>
44+
<Compile Include="Program.cs" />
45+
<Compile Include="Properties\AssemblyInfo.cs" />
46+
</ItemGroup>
47+
<ItemGroup>
48+
<None Include="App.config" />
49+
<None Include="packages.config" />
50+
<None Include="users.csv" />
51+
</ItemGroup>
52+
<ItemGroup>
53+
<ProjectReference Include="..\CSVSerializer.NET\CSVSerializer.csproj">
54+
<Project>{0c962c28-b003-49a6-8991-1e6636583efe}</Project>
55+
<Name>CSVSerializer</Name>
56+
</ProjectReference>
57+
</ItemGroup>
58+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
59+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
60+
Other similar extension points exist, see Microsoft.Common.targets.
61+
<Target Name="BeforeBuild">
62+
</Target>
63+
<Target Name="AfterBuild">
64+
</Target>
65+
-->
66+
</Project>

Demo.CS/Program.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System;
2+
using System.IO;
3+
using CSVSerializer; //import the library, also from Project > Add Reference... > Choose the DLL file
4+
5+
namespace Demo.CS
6+
{
7+
/**
8+
* This is a simple application that will show you how to use the library
9+
* <see cref="https://github.com/LucaMozzo/CSVSerializer.NET"/>
10+
*/
11+
class Program
12+
{
13+
static void Main(string[] args)
14+
{
15+
const string fileName = "users.csv";
16+
17+
// 1. Make sure the file exists, the exception is not handled
18+
if (!File.Exists(fileName))
19+
{
20+
Console.WriteLine("File not found!");
21+
goto exit;
22+
}
23+
24+
// 2. Create a deserializer object with the file name as argument for the constructor
25+
Deserializer deserializer = new Deserializer(fileName);
26+
27+
// 3. Use Document type to organize the extracted values
28+
Document doc = deserializer.Deserialize();
29+
30+
// 4. Loop through the headers
31+
foreach (String s in doc.Headers)
32+
Console.Write(s + "\t");
33+
Console.WriteLine("");
34+
35+
// 5. Loop through the rows
36+
foreach (Row r in doc.Rows)
37+
{
38+
// 6. Loop through the values
39+
foreach (Value v in r.Values)
40+
Console.Write(v + "\t");
41+
Console.WriteLine("");
42+
}
43+
44+
//Let's change some stuff...
45+
doc.Rows[0].UpdateValue(0, new Value("Michael"));
46+
doc.Rows[0].UpdateValue(2, new Value(64));
47+
48+
// 7. Serializer part - Create a serializer
49+
Serializer serializer = new Serializer(doc, "users_.csv");
50+
serialize(serializer);
51+
exit: Console.ReadLine();
52+
}
53+
54+
//we need to create another method because Main can't be async
55+
private async static void serialize(Serializer s)
56+
{
57+
if (await s.Serialize())
58+
Console.WriteLine("Successfully serialized");
59+
else
60+
Console.WriteLine("An error has occurred");
61+
}
62+
}
63+
}

Demo.CS/Properties/AssemblyInfo.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("Demo.CS")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("Demo.CS")]
13+
[assembly: AssemblyCopyright("Copyright © 2016")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("3f5e30be-d053-4b94-a671-88ca9c0754b9")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

Demo.CS/packages.config

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="EnterpriseLibrary.TransientFaultHandling" version="6.0.1304.0" targetFramework="net45" />
4+
<package id="EnterpriseLibrary.TransientFaultHandling.Data" version="6.0.1304.1" targetFramework="net45" />
5+
</packages>

Demo.CS/users.csv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"name","surname","age"
2+
"Tom","Hale",22
3+
"Mike","Collier",54

0 commit comments

Comments
 (0)