-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move over to ISerdeInfo interface (#183)
Allows more customization for different info implementations, and sets the stage for handling unions, which will have different capabilities than other types.
- Loading branch information
Showing
122 changed files
with
805 additions
and
633 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
|
||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using System.Reflection.Metadata; | ||
|
||
namespace Serde; | ||
|
||
/// <summary> | ||
/// Provides info for an arbitrary type that can be serialized or deserialized. | ||
/// </summary> | ||
public interface ISerdeInfo | ||
{ | ||
string TypeName { get; } | ||
TypeKind Kind { get; } | ||
|
||
/// <summary> | ||
/// The number of serializable or deserializable fields or properties on the type. | ||
/// </summary> | ||
int FieldCount { get; } | ||
|
||
/// <summary> | ||
/// Get the field name as a string for the field at the given index. The index must be valid. | ||
/// </summary> | ||
string GetStringSerializeName(int index); | ||
|
||
/// <summary> | ||
/// Get the field name as a UTF8 string for the field at the given index. The index must be valid. | ||
/// </summary> | ||
Utf8Span GetSerializeName(int index); | ||
|
||
/// <summary> | ||
/// Get the attributes for the field at the given index. The index must be valid. This list may be | ||
/// modified from the original set of attributes in source code or metadata to reflect only the | ||
/// attributes that are relevant to serialization or deserialization. | ||
/// </summary> | ||
IList<CustomAttributeData> GetCustomAttributeData(int index); | ||
|
||
/// <summary> | ||
/// Search the fields for one with the given name and return its index. Returns | ||
/// <see cref="IDeserializeType.IndexNotFound"/> if not found. | ||
/// </summary> | ||
int TryGetIndex(Utf8Span fieldName); | ||
|
||
public enum TypeKind | ||
{ | ||
Primitive, | ||
CustomType, | ||
Enumerable, | ||
Dictionary, | ||
Enum, | ||
/// <summary> | ||
/// Represents a closed union of types. Any type that returns this value from <see | ||
/// cref="Kind"/> must also implement <see cref="IUnionSerdeInfo"/>. | ||
/// </summary> | ||
Union | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Provides info for a "closed union" of types that can be serialized or deserialized. | ||
/// </summary> | ||
public interface IUnionSerdeInfo : ISerdeInfo | ||
{ | ||
TypeKind ISerdeInfo.Kind => TypeKind.Union; | ||
|
||
IEnumerable<ISerdeInfo> CaseInfos { get; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.