Skip to content

Commit

Permalink
Merge pull request aaubry#235 from aaubry/fix-samples
Browse files Browse the repository at this point in the history
Fix samples
  • Loading branch information
aaubry authored Jan 23, 2017
2 parents 43ee53a + 1947d1d commit ca20316
Show file tree
Hide file tree
Showing 31 changed files with 1,197 additions and 55 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
bin
obj
tools

# mstest test results
TestResults
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) Antoine Aubry and contributors

// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -23,6 +23,7 @@
using YamlDotNet.PerformanceTests.Lib;
using System.IO;
using YamlDotNet.RepresentationModel.Serialization;
using YamlDotNet.RepresentationModel.Serialization.NamingConventions;

namespace YamlDotNet.PerformanceTests.v2_2_0
{
Expand All @@ -34,7 +35,7 @@ public static void Main(string[] args)
runner.Run(new Program(), args);
}

private readonly Serializer _serializer = new Serializer();
private readonly Serializer _serializer = new Serializer(namingConvention: new CamelCaseNamingConvention());

public void Serialize (TextWriter writer, object graph)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) Antoine Aubry and contributors

// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -23,6 +23,7 @@
using System.IO;
using YamlDotNet.RepresentationModel.Serialization;
using YamlDotNet.PerformanceTests.Lib;
using YamlDotNet.RepresentationModel.Serialization.NamingConventions;

namespace YamlDotNet.PerformanceTests.v2_3_0
{
Expand All @@ -34,7 +35,7 @@ public static void Main(string[] args)
runner.Run(new Program(), args);
}

private readonly Serializer _serializer = new Serializer();
private readonly Serializer _serializer = new Serializer(namingConvention: new CamelCaseNamingConvention());

public void Serialize (TextWriter writer, object graph)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) Antoine Aubry and contributors

// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -23,6 +23,7 @@
using System.IO;
using YamlDotNet.Serialization;
using YamlDotNet.PerformanceTests.Lib;
using YamlDotNet.Serialization.NamingConventions;

namespace YamlDotNet.PerformanceTests.v3_8_0
{
Expand All @@ -34,7 +35,7 @@ public static void Main(string[] args)
runner.Run(new Program(), args);
}

private readonly Serializer _serializer = new Serializer();
private readonly Serializer _serializer = new Serializer(namingConvention: new CamelCaseNamingConvention());

public void Serialize (TextWriter writer, object graph)
{
Expand Down
47 changes: 47 additions & 0 deletions PerformanceTests/YamlDotNet.PerformanceTests.v4.0.0/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) Antoine Aubry and contributors

// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using System;
using System.IO;
using YamlDotNet.Serialization;
using YamlDotNet.PerformanceTests.Lib;
using YamlDotNet.Serialization.NamingConventions;

namespace YamlDotNet.PerformanceTests.v4_0_0
{
public class Program : ISerializerAdapter
{
public static void Main(string[] args)
{
var runner = new PerformanceTestRunner();
runner.Run(new Program(), args);
}

private readonly Serializer _serializer = new SerializerBuilder()
.WithNamingConvention(new CamelCaseNamingConvention())
.Build();

public void Serialize(TextWriter writer, object graph)
{
_serializer.Serialize(writer, graph);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) Antoine Aubry and contributors

// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using System.Reflection;
using System.Runtime.CompilerServices;

// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle ("YamlDotNet.PerformanceTests.v4.0.0")]
[assembly: AssemblyDescription ("")]
[assembly: AssemblyConfiguration ("")]
[assembly: AssemblyCompany ("")]
[assembly: AssemblyProduct ("")]
[assembly: AssemblyCopyright ("aaubry")]
[assembly: AssemblyTrademark ("")]
[assembly: AssemblyCulture ("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion ("1.0.*")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>12.0.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{747DD2E9-2A0A-4D5E-8D97-85AA9AC5A036}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>YamlDotNet.PerformanceTests.v4_0_0</RootNamespace>
<AssemblyName>YamlDotNet.PerformanceTests.v4_0.0</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="YamlDotNet, Version=4.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\YamlDotNet.4.0.0\lib\net35\YamlDotNet.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Program.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<ProjectReference Include="..\YamlDotNet.PerformanceTests.Lib\YamlDotNet.PerformanceTests.Lib.csproj">
<Project>{773B71D6-FEE5-4E4D-8717-5C5EF58D6F17}</Project>
<Name>YamlDotNet.PerformanceTests.Lib</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="YamlDotNet" version="4.0.0" targetFramework="net35" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ public static void Main(string[] args)
runner.Run(new Program(), args);
}

private readonly Serializer _serializer = new SerializerBuilder().Build();
private readonly Serializer _serializer = new SerializerBuilder()
.WithNamingConvention(new CamelCaseNamingConvention())
.Build();

public void Serialize(TextWriter writer, object graph)
{
Expand Down
42 changes: 42 additions & 0 deletions YamlDotNet.Samples/ConvertYamlToJson.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.IO;
using Xunit.Abstractions;
using YamlDotNet.Serialization;
using YamlDotNet.Samples.Helpers;

namespace YamlDotNet.Samples
{
public class ConvertYamlToJson
{
private readonly ITestOutputHelper output;

public ConvertYamlToJson(ITestOutputHelper output)
{
this.output = output;
}

[Sample(
Title = "Convert YAML to JSON",
Description = "Shows how to convert a YAML document to JSON."
)]
public void Main()
{
// convert string/file to YAML object
var r = new StringReader(@"
scalar: a scalar
sequence:
- one
- two
");
var deserializer = new Deserializer();
var yamlObject = deserializer.Deserialize(r);

var serializer = new SerializerBuilder()
.JsonCompatible()
.Build();

var json = serializer.Serialize(yamlObject);

output.WriteLine(json);
}
}
}
Loading

0 comments on commit ca20316

Please sign in to comment.