Skip to content

Commit

Permalink
Set warning as errors for all nuget projects and added documentation …
Browse files Browse the repository at this point in the history
…for Newtonsoft project

+semver:minor
  • Loading branch information
Ankit Vijay committed Jun 26, 2020
1 parent d64a7e2 commit a7917b9
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Enumeration.ModelBinder/Enumeration.ModelBinder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Authors>Ankit Vijay</Authors>
<Description>Custom model binder to allow Enumeration class pass as a query string parameter.</Description>
<PackageDescription>Custom model binder to allow Enumeration class pass as a query string parameter.</PackageDescription>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Authors>Ankit Vijay</Authors>
<Description>Newtonsoft.Json serialization support for Enumeration class.</Description>
<PackageDescription>Newtonsoft.Json serialization support for Enumeration class.</PackageDescription>
Expand All @@ -28,4 +29,4 @@
<ProjectReference Include="..\Enumeration\Enumeration.csproj" />
</ItemGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
<AssemblyName>AV.Enumeration.SystemTextJson</AssemblyName>
<RootNamespace>AV.Enumeration.SystemTextJson</RootNamespace>
<PackageTags>systemtextjson;serialization;enumeration;enum</PackageTags>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Authors>Ankit Vijay</Authors>
<Description>System.Text.Json serialization support for Enumeration class.</Description>
<PackageDescription>System.Text.Json serialization support for Enumeration class.</PackageDescription>
Expand Down
22 changes: 22 additions & 0 deletions src/Enumeration.SystemTextJson/EnumerationJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,31 @@

namespace AV.Enumeration.SystemTextJson
{
/// <summary>
/// Converts an <see cref="Enumeration"/> to or from JSON.
/// </summary>
public class EnumerationJsonConverter : JsonConverter<Enumeration>
{
private const string NameProperty = "Name";

/// <summary>
/// Determines whether the specified type can be converted to <see cref="Enumeration"/>
/// </summary>
/// <param name="objectType"></param>
/// <returns><c>true</c> if the type is subclass of type <see cref="Enumeration"/>; otherwise, <c>false</c>.</returns>

public override bool CanConvert(Type objectType)
{
return objectType.IsSubclassOf(typeof(Enumeration));
}

/// <summary>
/// Reads and converts the JSON to type <see cref="Enumeration"/>
/// </summary>
/// <param name="reader">The reader</param>
/// <param name="typeToConvert">The type to convert.</param>
/// <param name="options">An object that specifies serialization options to use.</param>
/// <returns>The converted value of type <see cref="Enumeration"/></returns>
public override Enumeration Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
switch (reader.TokenType)
Expand All @@ -29,6 +45,12 @@ public override Enumeration Read(ref Utf8JsonReader reader, Type typeToConvert,
}
}

/// <summary>
/// Writes a specified <see cref="Enumeration"/> value as JSON.
/// </summary>
/// <param name="writer">The writer to write to.</param>
/// <param name="value">The value to convert to the JSON.</param>
/// <param name="options">An object that specifies serialization options to use.</param>
public override void Write(Utf8JsonWriter writer, Enumeration value, JsonSerializerOptions options)
{
if (value is null)
Expand Down
6 changes: 4 additions & 2 deletions src/Enumeration/Enumeration.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;

Expand Down Expand Up @@ -39,6 +40,7 @@ public abstract class Enumeration : IComparable
/// This constructor should not be called from the derived class.
/// It is helpful in doing JSON Serialization or mapping through Automapper.
/// </remarks>
[ExcludeFromCodeCoverage]
protected Enumeration()
{
}
Expand Down Expand Up @@ -107,8 +109,8 @@ public static int AbsoluteDifference(Enumeration firstValue, Enumeration secondV
/// <param name="valueOrName">The <typeparamref name="TEnumeration"/> value or name.</param>
/// <param name="enumeration">The <typeparamref name="TEnumeration"/> instance.</param>
/// <returns>
/// <c>true</c> if the instance <see cref="Enumeration"/> contains <typeparamref name="TEnumeration"/> with the specified name,
/// <c>false</c>, otherwise.
/// <c>true</c> if the instance <see cref="Enumeration"/> contains <typeparamref name="TEnumeration"/> with the specified name;
/// otherwise, <c>false</c>.
/// </returns>
public static bool TryGetFromValueOrName<TEnumeration>(
string valueOrName,
Expand Down
2 changes: 2 additions & 0 deletions src/Enumeration/Enumeration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

<Authors>Ankit Vijay</Authors>
<Description>Enumeration class as an alternate to Enum types.</Description>
<PackageDescription>Enumeration class as an alternate to Enum types.</PackageDescription>
Expand Down

0 comments on commit a7917b9

Please sign in to comment.