Exemple #1
0
 public static string ToString(Type t)
 {
     SerializedType.SerializedTypeData data = default(SerializedType.SerializedTypeData);
     if (t == null)
     {
         return(string.Empty);
     }
     data.typeName  = string.Empty;
     data.isGeneric = t.ContainsGenericParameters;
     if (data.isGeneric && t.IsGenericType)
     {
         data.typeName = SerializedType.ToShortTypeName(t.GetGenericTypeDefinition());
     }
     else if (data.isGeneric && t.IsArray)
     {
         data.typeName = "T[]";
     }
     else if (data.isGeneric)
     {
         data.typeName = "T";
     }
     else
     {
         data.typeName = SerializedType.ToShortTypeName(t);
     }
     return(SerializedType.ToString(data));
 }
Exemple #2
0
 public static bool IsBaseTypeGeneric(string serializedTypeString)
 {
     if (string.IsNullOrEmpty(serializedTypeString))
     {
         return(false);
     }
     SerializedType.SerializedTypeData serializedTypeData = SerializedType.SplitTypeString(serializedTypeString);
     return(serializedTypeData.isGeneric || serializedTypeData.genericTypeName != string.Empty);
 }
Exemple #3
0
 private static string ToString(SerializedType.SerializedTypeData data)
 {
     return(string.Concat(new string[]
     {
         data.typeName,
         "#",
         data.genericTypeName,
         "#",
         (!data.isGeneric) ? "0" : "1"
     }));
 }
Exemple #4
0
        public static string SetGenericArgumentType(string serializedTypeString, Type type)
        {
            if (SerializedType.IsGeneric(serializedTypeString))
            {
                SerializedType.SerializedTypeData data = SerializedType.SplitTypeString(serializedTypeString);
                data.genericTypeName = data.typeName;
                data.isGeneric       = false;
                string typeName = data.typeName;
                if (typeName != null)
                {
                    if (SerializedType.< > f__switch$map1 == null)
                    {
                        SerializedType.< > f__switch$map1 = new Dictionary <string, int>(2)
                        {
                            {
                                "T",
                                0
                            },
                            {
                                "T[]",
                                1
                            }
                        };
                    }
                    int num;
                    if (SerializedType.< > f__switch$map1.TryGetValue(typeName, out num))
                    {
                        if (num == 0)
                        {
                            data.typeName = SerializedType.ToShortTypeName(type);
                            goto IL_105;
                        }
                        if (num == 1)
                        {
                            data.typeName = SerializedType.ToShortTypeName(type.MakeArrayType());
                            goto IL_105;
                        }
                    }
                }
                data.typeName = SerializedType.ToShortTypeName(Type.GetType(data.typeName, true).GetGenericTypeDefinition().MakeGenericType(new Type[]
                {
                    type
                }));
IL_105:
                return(SerializedType.ToString(data));
            }
            if (SerializedType.IsBaseTypeGeneric(serializedTypeString))
            {
                throw new ArgumentException("Trying to set a different generic type. Reset old one first.");
            }
            throw new ArgumentException("Trying to set generic argument type for non generic type.");
        }
Exemple #5
0
 public static string ResetGenericArgumentType(string serializedTypeString)
 {
     if (string.IsNullOrEmpty(serializedTypeString))
     {
         throw new ArgumentException("Cannot reset generic argument type for null type.");
     }
     SerializedType.SerializedTypeData data = SerializedType.SplitTypeString(serializedTypeString);
     if (string.IsNullOrEmpty(data.genericTypeName))
     {
         throw new ArgumentException("Cannot reset generic argument type, previous generic type unknown.");
     }
     data.typeName        = data.genericTypeName;
     data.isGeneric       = true;
     data.genericTypeName = string.Empty;
     return(SerializedType.ToString(data));
 }
Exemple #6
0
 public static bool CanAssignFromGenericType(string serializedTypeString, Type t)
 {
     SerializedType.SerializedTypeData data = SerializedType.SplitTypeString(serializedTypeString);
     if (!data.isGeneric)
     {
         return(false);
     }
     if (!t.IsGenericType)
     {
         return(data.typeName == "T" || data.typeName == "T[]");
     }
     if (data.typeName == "T" || data.typeName == "T[]")
     {
         return(false);
     }
     Type[] genericArguments = t.GetGenericArguments();
     return(genericArguments.Length == 1 && !genericArguments[0].IsGenericType && t.GetGenericTypeDefinition() == SerializedType.FromString(data).GetGenericTypeDefinition());
 }
Exemple #7
0
 private static Type FromString(SerializedType.SerializedTypeData data)
 {
     return(Type.GetType(data.typeName, true));
 }