internal static bool TryBuildImmutableForArrayContract(Type underlyingType, Type collectionItemType, out Type createdType, out ObjectConstructor <object> parameterizedCreator) { if (underlyingType.IsGenericType()) { Type underlyingTypeDefinition = underlyingType.GetGenericTypeDefinition(); string name = underlyingTypeDefinition.FullName; ImmutableCollectionTypeInfo definition = ArrayContractImmutableCollectionDefinitions.FirstOrDefault(d => d.ContractTypeName == name); if (definition != null) { Type createdTypeDefinition = underlyingTypeDefinition.Assembly().GetType(definition.CreatedTypeName); Type builderTypeDefinition = underlyingTypeDefinition.Assembly().GetType(definition.BuilderTypeName); if (createdTypeDefinition != null && builderTypeDefinition != null) { MethodInfo mb = builderTypeDefinition.GetMethods().FirstOrDefault(m => m.Name == "CreateRange" && m.GetParameters().Length == 1); if (mb != null) { createdType = createdTypeDefinition.MakeGenericType(collectionItemType); MethodInfo method = mb.MakeGenericMethod(collectionItemType); parameterizedCreator = JsonTypeReflector.ReflectionDelegateFactory.CreateParametrizedConstructor(method); return(true); } } } } createdType = null; parameterizedCreator = null; return(false); }
internal static bool TryBuildImmutableForDictionaryContract(Type underlyingType, Type keyItemType, Type valueItemType, out Type createdType, out MethodBase parameterizedCreator) { if (underlyingType.IsGenericType()) { string name = underlyingType.GetGenericTypeDefinition().FullName; ImmutableCollectionTypeInfo definition = DictionaryContractImmutableCollectionDefinitions.FirstOrDefault(d => d.ContractTypeName == name); if (definition != null) { Type createdTypeDefinition = Type.GetType(definition.CreatedTypeName + ", System.Collections.Immutable"); Type builderTypeDefinition = Type.GetType(definition.BuilderTypeName + ", System.Collections.Immutable"); if (createdTypeDefinition != null && builderTypeDefinition != null) { MethodInfo mb = builderTypeDefinition.GetMethods().FirstOrDefault(m => { ParameterInfo[] parameters = m.GetParameters(); return(m.Name == "CreateRange" && parameters.Length == 1 && parameters[0].ParameterType.IsGenericType() && parameters[0].ParameterType.GetGenericTypeDefinition() == typeof(IEnumerable <>)); }); if (mb != null) { createdType = createdTypeDefinition.MakeGenericType(keyItemType, valueItemType); parameterizedCreator = mb.MakeGenericMethod(keyItemType, valueItemType); return(true); } } } } createdType = null; parameterizedCreator = null; return(false); }
internal static bool TryBuildImmutableForArrayContract(Type underlyingType, Type collectionItemType, out Type createdType, out MethodBase parameterizedCreator) { if (underlyingType.IsGenericType()) { string name = underlyingType.GetGenericTypeDefinition().FullName; ImmutableCollectionTypeInfo definition = ArrayContractImmutableCollectionDefinitions.FirstOrDefault(d => d.ContractTypeName == name); if (definition != null) { Type createdTypeDefinition = Type.GetType(definition.CreatedTypeName + ", System.Collections.Immutable"); Type builderTypeDefinition = Type.GetType(definition.BuilderTypeName + ", System.Collections.Immutable"); if (createdTypeDefinition != null && builderTypeDefinition != null) { MethodInfo mb = builderTypeDefinition.GetMethods().FirstOrDefault(m => m.Name == "CreateRange" && m.GetParameters().Length == 1); if (mb != null) { createdType = createdTypeDefinition.MakeGenericType(collectionItemType); parameterizedCreator = mb.MakeGenericMethod(collectionItemType); return(true); } } } } createdType = null; parameterizedCreator = null; return(false); }
internal static bool TryBuildImmutableForDictionaryContract(Type underlyingType, Type keyItemType, Type valueItemType, out Type createdType, out ObjectConstructor <object> parameterizedCreator) { if (underlyingType.IsGenericType()) { Type genericTypeDefinition = underlyingType.GetGenericTypeDefinition(); string name = genericTypeDefinition.FullName; ImmutableCollectionTypeInfo info = DictionaryContractImmutableCollectionDefinitions.FirstOrDefault <ImmutableCollectionTypeInfo>(d => d.ContractTypeName == name); if (info != null) { Type type = genericTypeDefinition.Assembly().GetType(info.CreatedTypeName); Type type3 = genericTypeDefinition.Assembly().GetType(info.BuilderTypeName); if ((type != null) && (type3 != null)) { if (< > c.< > 9__25_1 == null) { } MethodInfo info2 = type3.GetMethods().FirstOrDefault <MethodInfo>(< > c.< > 9__25_1 = new Func <MethodInfo, bool>(< > c.< > 9. < TryBuildImmutableForDictionaryContract > b__25_1)); if (info2 != null) { Type[] typeArguments = new Type[] { keyItemType, valueItemType }; createdType = type.MakeGenericType(typeArguments); Type[] typeArray2 = new Type[] { keyItemType, valueItemType }; MethodInfo method = info2.MakeGenericMethod(typeArray2); parameterizedCreator = JsonTypeReflector.ReflectionDelegateFactory.CreateParameterizedConstructor(method); return(true); } } } } createdType = null; parameterizedCreator = null; return(false); }
internal static bool TryBuildImmutableForDictionaryContract(Type underlyingType, Type keyItemType, Type valueItemType, [NotNullWhen(true)] out Type createdType, [NotNullWhen(true)] out ObjectConstructor <object> parameterizedCreator) { if (underlyingType.IsGenericType()) { Type underlyingTypeDefinition = underlyingType.GetGenericTypeDefinition(); string name = underlyingTypeDefinition.FullName; ImmutableCollectionTypeInfo definition = DictionaryContractImmutableCollectionDefinitions.FirstOrDefault(d => d.ContractTypeName == name); if (definition != null) { Type createdTypeDefinition = underlyingTypeDefinition.Assembly().GetType(definition.CreatedTypeName); Type builderTypeDefinition = underlyingTypeDefinition.Assembly().GetType(definition.BuilderTypeName); if (createdTypeDefinition != null && builderTypeDefinition != null) { MethodInfo mb = builderTypeDefinition.GetMethods().FirstOrDefault(m => { ParameterInfo[] parameters = m.GetParameters(); return(m.Name == "CreateRange" && parameters.Length == 1 && parameters[0].ParameterType.IsGenericType() && parameters[0].ParameterType.GetGenericTypeDefinition() == typeof(IEnumerable <>)); }); if (mb != null) { createdType = createdTypeDefinition.MakeGenericType(keyItemType, valueItemType); MethodInfo method = mb.MakeGenericMethod(keyItemType, valueItemType); parameterizedCreator = JsonTypeReflector.ReflectionDelegateFactory.CreateParameterizedConstructor(method); return(true); } } } } createdType = null; parameterizedCreator = null; return(false); }