Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/System.Text.Json/src/System.Text.Json.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@
<Compile Include="System\Text\Json\Reader\Utf8JsonReader.TryGet.cs" />
<Compile Include="System\Text\Json\Serialization\ClassType.cs" />
<Compile Include="System\Text\Json\Serialization\ConverterList.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\DefaultDerivedDictionaryConverter.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\DefaultDerivedEnumerableConverter.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\DefaultArrayConverter.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\DefaultICollectionConverter.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\DefaultIDictionaryConverter.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\DefaultImmutableEnumerableConverter.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\DefaultImmutableDictionaryConverter.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\EnumConverterOptions.cs" />
Expand Down Expand Up @@ -89,7 +85,6 @@
<Compile Include="System\Text\Json\Serialization\JsonCamelCaseNamingPolicy.cs" />
<Compile Include="System\Text\Json\Serialization\JsonClassInfo.cs" />
<Compile Include="System\Text\Json\Serialization\JsonClassInfo.AddProperty.cs" />
<Compile Include="System\Text\Json\Serialization\JsonClassInfo.Helpers.cs" />
<Compile Include="System\Text\Json\Serialization\JsonConverter.cs" />
<Compile Include="System\Text\Json\Serialization\JsonConverterAttribute.cs" />
<Compile Include="System\Text\Json\Serialization\JsonConverterFactory.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,5 @@ internal enum ClassType : byte
Enumerable = 0x8,
// IDictionary
Dictionary = 0x10,
// Is deserialized by passing a IDictionary to its constructor
// i.e. immutable dictionaries, Hashtable, SortedList,
IDictionaryConstructible = 0x20,
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,14 @@ public static bool IsImmutableDictionary(Type type)
public override object CreateFromDictionary(ref ReadStack state, IDictionary sourceDictionary, JsonSerializerOptions options)
{
Type immutableCollectionType = state.Current.JsonPropertyInfo.RuntimePropertyType;
Type elementType = state.Current.GetElementType();

JsonClassInfo elementClassInfo = state.Current.JsonPropertyInfo.ElementClassInfo;
Type elementType = elementClassInfo.Type;

string delegateKey = DefaultImmutableEnumerableConverter.GetDelegateKey(immutableCollectionType, elementType, out _, out _);

JsonPropertyInfo propertyInfo = options.GetJsonPropertyInfoFromClassInfo(elementType, options);
JsonPropertyInfo propertyInfo = elementClassInfo.PolicyProperty ?? elementClassInfo.CreateRootProperty(options);
Debug.Assert(propertyInfo != null);
return propertyInfo.CreateImmutableDictionaryInstance(ref state, immutableCollectionType, delegateKey, sourceDictionary, options);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,47 @@ public static void RegisterImmutableCollection(Type immutableCollectionType, Typ
options.TryAddCreateRangeDelegate(delegateKey, createRangeDelegate);
}

public static bool IsImmutableEnumerable(Type type, out bool IsImmutableArray)
{
if (!type.IsGenericType)
{
IsImmutableArray = false;
return false;
}

switch (type.GetGenericTypeDefinition().FullName)
{
case ImmutableArrayGenericTypeName:
IsImmutableArray = true;
return true;
case ImmutableListGenericTypeName:
case ImmutableListGenericInterfaceTypeName:
case ImmutableStackGenericTypeName:
case ImmutableStackGenericInterfaceTypeName:
case ImmutableQueueGenericTypeName:
case ImmutableQueueGenericInterfaceTypeName:
case ImmutableSortedSetGenericTypeName:
case ImmutableHashSetGenericTypeName:
case ImmutableSetGenericInterfaceTypeName:
IsImmutableArray = false;
return true;
default:
IsImmutableArray = false;
return false;
}
}

public override IEnumerable CreateFromList(ref ReadStack state, IList sourceList, JsonSerializerOptions options)
{
Type immutableCollectionType = state.Current.JsonPropertyInfo.RuntimePropertyType;
Type elementType = state.Current.GetElementType();

JsonClassInfo elementClassInfo = state.Current.JsonPropertyInfo.ElementClassInfo;
Type elementType = elementClassInfo.Type;

string delegateKey = GetDelegateKey(immutableCollectionType, elementType, out _, out _);

JsonPropertyInfo propertyInfo = options.GetJsonPropertyInfoFromClassInfo(elementType, options);
JsonPropertyInfo propertyInfo = elementClassInfo.PolicyProperty ?? elementClassInfo.CreateRootProperty(options);
Debug.Assert(propertyInfo != null);
return propertyInfo.CreateImmutableCollectionInstance(ref state, immutableCollectionType, delegateKey, sourceList, options);
}
}
Expand Down
Loading