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 fullName = genericTypeDefinition.FullName;
         ImmutableCollectionsUtils.ImmutableCollectionTypeInfo immutableCollectionTypeInfo = ImmutableCollectionsUtils.DictionaryContractImmutableCollectionDefinitions.FirstOrDefault <ImmutableCollectionsUtils.ImmutableCollectionTypeInfo>((ImmutableCollectionsUtils.ImmutableCollectionTypeInfo d) => d.ContractTypeName == fullName);
         if (immutableCollectionTypeInfo != null)
         {
             Type type  = genericTypeDefinition.Assembly().GetType(immutableCollectionTypeInfo.CreatedTypeName);
             Type type1 = genericTypeDefinition.Assembly().GetType(immutableCollectionTypeInfo.BuilderTypeName);
             if (type != null && type1 != null)
             {
                 MethodInfo methodInfo = ((IEnumerable <MethodInfo>)type1.GetMethods()).FirstOrDefault <MethodInfo>((MethodInfo m) => {
                     ParameterInfo[] parameters = m.GetParameters();
                     if (!(m.Name == "CreateRange") || (int)parameters.Length != 1 || !parameters[0].ParameterType.IsGenericType())
                     {
                         return(false);
                     }
                     return(parameters[0].ParameterType.GetGenericTypeDefinition() == typeof(IEnumerable <>));
                 });
                 if (methodInfo != null)
                 {
                     createdType = type.MakeGenericType(new Type[] { keyItemType, valueItemType });
                     MethodInfo methodInfo1 = methodInfo.MakeGenericMethod(new Type[] { keyItemType, valueItemType });
                     parameterizedCreator = JsonTypeReflector.ReflectionDelegateFactory.CreateParameterizedConstructor(methodInfo1);
                     return(true);
                 }
             }
         }
     }
     createdType          = null;
     parameterizedCreator = null;
     return(false);
 }
Exemplo n.º 2
0
 // Token: 0x06000F9A RID: 3994 RVA: 0x0005BCD0 File Offset: 0x00059ED0
 internal static bool TryBuildImmutableForDictionaryContract(Type underlyingType, Type keyItemType, Type valueItemType, [Nullable(2)][NotNullWhen(true)] out Type createdType, [Nullable(new byte[]
 {
     2,
     1
 })][NotNullWhen(true)] out ObjectConstructor <object> parameterizedCreator)
 {
     if (underlyingType.IsGenericType())
     {
         Type   genericTypeDefinition = underlyingType.GetGenericTypeDefinition();
         string name = genericTypeDefinition.FullName;
         ImmutableCollectionsUtils.ImmutableCollectionTypeInfo immutableCollectionTypeInfo = ImmutableCollectionsUtils.DictionaryContractImmutableCollectionDefinitions.FirstOrDefault((ImmutableCollectionsUtils.ImmutableCollectionTypeInfo d) => d.ContractTypeName == name);
         if (immutableCollectionTypeInfo != null)
         {
             Type type  = genericTypeDefinition.Assembly().GetType(immutableCollectionTypeInfo.CreatedTypeName);
             Type type2 = genericTypeDefinition.Assembly().GetType(immutableCollectionTypeInfo.BuilderTypeName);
             if (type != null && type2 != null)
             {
                 MethodInfo methodInfo = type2.GetMethods().FirstOrDefault(delegate(MethodInfo m)
                 {
                     ParameterInfo[] parameters = m.GetParameters();
                     return(m.Name == "CreateRange" && parameters.Length == 1 && parameters[0].ParameterType.IsGenericType() && parameters[0].ParameterType.GetGenericTypeDefinition() == typeof(IEnumerable <>));
                 });
                 if (methodInfo != null)
                 {
                     createdType = type.MakeGenericType(new Type[]
                     {
                         keyItemType,
                         valueItemType
                     });
                     MethodInfo method = methodInfo.MakeGenericMethod(new Type[]
                     {
                         keyItemType,
                         valueItemType
                     });
                     parameterizedCreator = JsonTypeReflector.ReflectionDelegateFactory.CreateParameterizedConstructor(method);
                     return(true);
                 }
             }
         }
     }
     createdType          = null;
     parameterizedCreator = null;
     return(false);
 }