Adds dictionary to codegen (#838)
* Adds Dictionary serialization rule for codegen * Adds Tidy for Dictionary. By default will remove key/value pairs where the key or value is either null or deleted. Only works for ISerializable keys or values (or both).
This commit is contained in:
parent
2890f5c3ec
commit
a4d9a3bdc2
4 changed files with 285 additions and 2 deletions
|
|
@ -19,6 +19,7 @@ namespace SerializationGenerator
|
|||
{
|
||||
public static partial class SymbolMetadata
|
||||
{
|
||||
public const string DICTIONARY_CLASS = "System.Collections.Generic.Dictionary`2";
|
||||
public const string LIST_CLASS = "System.Collections.Generic.List`1";
|
||||
public const string HASHSET_CLASS = "System.Collections.Generic.HashSet`1";
|
||||
public const string IPADDRESS_CLASS = "System.Net.IPAddress";
|
||||
|
|
@ -43,9 +44,9 @@ namespace SerializationGenerator
|
|||
SymbolEqualityComparer.Default
|
||||
) == true;
|
||||
|
||||
public static bool IsList(this ISymbol symbol, Compilation compilation) =>
|
||||
public static bool IsDictionary(this ISymbol symbol, Compilation compilation) =>
|
||||
(symbol as INamedTypeSymbol)?.ConstructedFrom.Equals(
|
||||
compilation.GetTypeByMetadataName(LIST_CLASS),
|
||||
compilation.GetTypeByMetadataName(DICTIONARY_CLASS),
|
||||
SymbolEqualityComparer.Default
|
||||
) == true;
|
||||
|
||||
|
|
@ -55,6 +56,12 @@ namespace SerializationGenerator
|
|||
SymbolEqualityComparer.Default
|
||||
) == true;
|
||||
|
||||
public static bool IsList(this ISymbol symbol, Compilation compilation) =>
|
||||
(symbol as INamedTypeSymbol)?.ConstructedFrom.Equals(
|
||||
compilation.GetTypeByMetadataName(LIST_CLASS),
|
||||
SymbolEqualityComparer.Default
|
||||
) == true;
|
||||
|
||||
public static bool IsPrimitiveFromTypeDisplayString(string type) =>
|
||||
type is "bool" or "sbyte" or "short" or "int" or "long" or "byte" or "ushort"
|
||||
or "uint" or "ulong" or "float" or "double" or "string" or "decimal";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue