Skip to content

Commit

Permalink
Add some XML comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ardalis committed Jan 17, 2024
1 parent b7f7dc1 commit f1c7a54
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/SmartEnum.EFCore/SmartEnumConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

namespace Ardalis.SmartEnum.EFCore
{
/// <summary>
///
/// </summary>
/// <typeparam name="TEnum"></typeparam>
/// <typeparam name="TValue"></typeparam>
public class SmartEnumConverter<TEnum, TValue> : ValueConverter<TEnum, TValue>
where TEnum : SmartEnum<TEnum, TValue>
where TValue : IEquatable<TValue>, IComparable<TValue>
Expand Down Expand Up @@ -34,6 +39,12 @@ private static MethodInfo GetBaseFromValueMethod(Type objectType, Type valueType
return null;
}

/// <summary>
///
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public static TEnum GetFromValue(TValue value)
{
if (!CanConvert(typeof(TEnum)))
Expand All @@ -46,6 +57,9 @@ public static TEnum GetFromValue(TValue value)
return method.Invoke(null, new[] { (object)value }) as TEnum;
}

/// <summary>
///
/// </summary>
public SmartEnumConverter() : base(item => item.Value, key => GetFromValue(key), null)
{
}
Expand Down
16 changes: 16 additions & 0 deletions src/SmartEnum.JsonNet/SmartFlagEnumNameConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,26 @@ public class SmartFlagEnumNameConverter<TEnum, TValue> : JsonConverter<TEnum>
where TEnum : SmartFlagEnum<TEnum, TValue>
where TValue : struct, IComparable<TValue>, IEquatable<TValue>
{
/// <summary>
/// Default to true.
/// </summary>
public override bool CanRead => true;

/// <summary>
/// Defaults to true
/// </summary>
public override bool CanWrite => true;

/// <summary>
///
/// </summary>
/// <param name="reader"></param>
/// <param name="objectType"></param>
/// <param name="existingValue"></param>
/// <param name="hasExistingValue"></param>
/// <param name="serializer"></param>
/// <returns></returns>
/// <exception cref="JsonSerializationException"></exception>
public override TEnum ReadJson(JsonReader reader, Type objectType, TEnum existingValue, bool hasExistingValue, JsonSerializer serializer)
{
switch (reader.TokenType)
Expand Down
18 changes: 18 additions & 0 deletions src/SmartEnum.MessagePack/SmartEnumValueFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ public class SmartEnumValueFormatter<TEnum, TValue> : IMessagePackFormatter<TEnu
where TEnum : SmartEnum<TEnum, TValue>
where TValue : struct, IEquatable<TValue>, IComparable<TValue>
{
/// <summary>
///
/// </summary>
/// <param name="writer"></param>
/// <param name="value"></param>
/// <param name="options"></param>
public void Serialize(ref MessagePackWriter writer, TEnum value, MessagePackSerializerOptions options)
{
if (value is null)
Expand Down Expand Up @@ -79,6 +85,12 @@ private void Write(ref MessagePackWriter writer, TValue value)
throw new ArgumentOutOfRangeException(nameof(value), $"{typeof(TValue)} is not supported."); // should not get to here
}

/// <summary>
///
/// </summary>
/// <param name="reader"></param>
/// <param name="options"></param>
/// <returns></returns>
public TEnum Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
{
if (reader.TryReadNil())
Expand All @@ -89,6 +101,12 @@ public TEnum Deserialize(ref MessagePackReader reader, MessagePackSerializerOpti
return SmartEnum<TEnum, TValue>.FromValue(Read(ref reader));
}

/// <summary>
///
/// </summary>
/// <param name="reader"></param>
/// <returns></returns>
/// <exception cref="ArgumentOutOfRangeException"></exception>
public TValue Read(ref MessagePackReader reader)
{
if (typeof(TValue) == typeof(bool))
Expand Down
13 changes: 13 additions & 0 deletions src/SmartEnum.ProtoBufNet/SmartEnunNameSurrogate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ namespace Ardalis.SmartEnum.ProtoBufNet
using System;
using ProtoBuf;

/// <summary>
///
/// </summary>
/// <typeparam name="TEnum"></typeparam>
/// <typeparam name="TValue"></typeparam>
[ProtoContract]
public class SmartEnumNameSurrogate<TEnum, TValue>
where TEnum : SmartEnum<TEnum, TValue>
Expand All @@ -11,6 +16,10 @@ public class SmartEnumNameSurrogate<TEnum, TValue>
[ProtoMember(1, IsRequired = true)]
string Name { get; set; }

/// <summary>
///
/// </summary>
/// <param name="smartEnum"></param>
public static implicit operator SmartEnumNameSurrogate<TEnum, TValue>(TEnum smartEnum)
{
if (smartEnum is null)
Expand All @@ -19,6 +28,10 @@ public static implicit operator SmartEnumNameSurrogate<TEnum, TValue>(TEnum smar
return new SmartEnumNameSurrogate<TEnum, TValue> { Name = smartEnum.Name };
}

/// <summary>
///
/// </summary>
/// <param name="surrogate"></param>
public static implicit operator TEnum(SmartEnumNameSurrogate<TEnum, TValue> surrogate)
{
if (surrogate is null)
Expand Down

0 comments on commit f1c7a54

Please sign in to comment.