示例#1
0
 public static Type FromString(string serializedTypeString)
 {
     if (string.IsNullOrEmpty(serializedTypeString) || SerializedType.IsGeneric(serializedTypeString))
     {
         return(null);
     }
     return(Type.GetType(SerializedType.SplitTypeString(serializedTypeString).typeName, true));
 }
示例#2
0
 private static string StripAllFromTypeNameString(string str, string toStrip)
 {
     for (int num = str.IndexOf(toStrip); num != -1; num = str.IndexOf(toStrip, num))
     {
         str = SerializedType.StripTypeNameString(str, num);
     }
     return(str);
 }
示例#3
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);
 }
示例#4
0
 public void SetGenericArgumentType(Type type)
 {
     if (!this.isGeneric)
     {
         return;
     }
     this.m_TypeString = SerializedType.SetGenericArgumentType(this.m_TypeString, type);
     this.value        = Property.TryGetDefaultValue(this.type);
 }
示例#5
0
 private static SerializedType.SerializedTypeData SplitTypeString(string serializedTypeString)
 {
     if (string.IsNullOrEmpty(serializedTypeString))
     {
         throw new ArgumentException("Cannot parse serialized type string, it is empty.");
     }
     SerializedType.SerializedTypeData result;
     result.isGeneric       = SerializedType.IsGeneric(serializedTypeString);
     result.typeName        = serializedTypeString.Substring(0, serializedTypeString.IndexOf('#'));
     result.genericTypeName = serializedTypeString.Substring(result.typeName.Length + 1, serializedTypeString.IndexOf('#', result.typeName.Length + 1) - result.typeName.Length - 1);
     return(result);
 }
示例#6
0
        private static string ToShortTypeName(Type t)
        {
            string text = t.AssemblyQualifiedName;

            if (string.IsNullOrEmpty(text))
            {
                return(string.Empty);
            }
            text = SerializedType.StripAllFromTypeNameString(text, ", Version");
            text = SerializedType.StripAllFromTypeNameString(text, ", Culture");
            return(SerializedType.StripAllFromTypeNameString(text, ", PublicKeyToken"));
        }
示例#7
0
 public static string GetFullName(Type t)
 {
     if (!t.IsGenericType)
     {
         return(SerializedType.SafeTypeName(t));
     }
     if (t.GetGenericTypeDefinition() != typeof(List <>))
     {
         throw new ArgumentException("Internal error: got unsupported generic type");
     }
     return(string.Format("System.Collections.Generic.List<{0}>", SerializedType.SafeTypeName(t.GetGenericArguments()[0])));
 }
示例#8
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.");
        }
示例#9
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));
 }
示例#10
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());
 }
示例#11
0
        private CodeExpression ConvertArrayToCodeExpression(object o)
        {
            CSharpCodeProvider cSharpCodeProvider = new CSharpCodeProvider();
            StringBuilder      stringBuilder      = new StringBuilder();

            foreach (object current in ((IEnumerable)o))
            {
                if (stringBuilder.Length != 0)
                {
                    stringBuilder.Append(',');
                }
                StringWriter stringWriter = new StringWriter();
                cSharpCodeProvider.GenerateCodeFromExpression(this.ConvertSingleValueToCodeExpression(current), stringWriter, new CodeGeneratorOptions());
                stringBuilder.AppendFormat(stringWriter.ToString(), new object[0]);
                stringWriter.Close();
            }
            return(new CodeSnippetExpression(string.Format("new {0} {{ {1} }}", SerializedType.GetFullName(this.type), stringBuilder)));
        }
示例#12
0
 public void ResetGenericArgumentType()
 {
     this.m_TypeString = SerializedType.ResetGenericArgumentType(this.m_TypeString);
 }
示例#13
0
 public void SetGenericArgumentType(Type type)
 {
     this.m_DataTypeString = SerializedType.SetGenericArgumentType(this.m_DataTypeString, type);
 }