Beispiel #1
0
 public void Parsed()
 {
     this.fieldType = DynamicTypes.GetType(this.fieldTypeName);
     if (this.fieldType == null)
     {
         Debug.Log("DynamicTypes.WaitForType", "Couldn't find type \"" + fieldTypeName + "\".", Debug.Type.ERROR);
     }
     else
     {
         if (isProperty)
         {
             if (DynamicTypes.ParseProperty(newType, fieldType, fieldTypeName, fieldName))
             {
                 typeWaiting[newType.FullName]--;
                 if (typeWaiting[newType.FullName] == 0)
                 {
                     DynamicTypes.TypeComplete(newType);
                 }
             }
         }
         else
         {
             if (DynamicTypes.ParseField(newType, fieldType, fieldTypeName, fieldName))
             {
                 typeWaiting[newType.FullName]--;
                 if (typeWaiting[newType.FullName] == 0)
                 {
                     DynamicTypes.TypeComplete(newType);
                 }
             }
         }
     }
 }
Beispiel #2
0
 public void Parsed()
 {
     FieldType = DynamicTypes.GetType(FieldTypeName);
     if (FieldType == null)
     {
         Debug.Log("DynamicTypes.WaitForType", "Couldn't find type \"" + FieldTypeName + "\".", Debug.Type.Error);
     }
     else
     {
         if (IsProperty)
         {
             if (ParseProperty(NewType, FieldType, FieldTypeName, FieldName))
             {
                 TypeWaiting[NewType.FullName]--;
                 if (TypeWaiting[NewType.FullName] == 0)
                 {
                     TypeComplete(NewType);
                 }
             }
         }
         else
         {
             if (ParseField(NewType, FieldType, FieldTypeName, FieldName))
             {
                 TypeWaiting[NewType.FullName]--;
                 if (TypeWaiting[NewType.FullName] == 0)
                 {
                     TypeComplete(NewType);
                 }
             }
         }
     }
 }
Beispiel #3
0
        public static Type GetType(string type, bool typeLookup = true)
        {
            bool isArray   = false;
            bool isGeneric = false;

            Type[] genericTypes = new Type[0];
            int    arrayDepth   = 0;
            string baseName     = type;

            if (type.Contains("`") && type.Contains("[")) //generic type
            {
                int      ind          = type.IndexOf("`") + 1;
                int      ind2         = type.IndexOf("[", ind);
                int      genericCount = int.Parse(type.Substring(ind, ind2 - ind));
                string   param        = type.Substring(ind2 + 1, type.Length - (ind2 + 1) - 1);
                string[] p            = param.Split(new string[] { "," }, StringSplitOptions.None);
                genericTypes = new Type[genericCount];
                for (int i = 0; i < genericCount; i++)
                {
                    Type gt = GetType(p[i]);
                    if (gt == null)
                    {
                        Debug.Log("DynamicTypes", "GetType wasn't able to resolve type \"" + p[i] + "\" of generic type \"" + type + "\".", Debug.Type.ERROR);
                    }
                    else
                    {
                        genericTypes[i] = gt;
                    }
                }
                isGeneric = true;
                baseName  = type.Substring(0, ind2);
            }
            else if (type.Contains("[]")) //array type
            {
                int ind = -1;
                while ((ind = type.IndexOf("[]", ind + 1)) > 0)
                {
                    arrayDepth++;
                }
                isArray  = true;
                baseName = type.Substring(0, type.IndexOf("["));
            }

            if (DynamicTypes.Types.ContainsKey(baseName))
            {
                if (isArray)
                {
                    return(DynamicTypes.Types[baseName].MakeArrayType(arrayDepth));
                }
                if (isGeneric)
                {
                    return(DynamicTypes.Types[baseName].MakeGenericType(genericTypes));
                }
                return(DynamicTypes.Types[baseName]);
            }
            else if (DynamicTypes.BuildingTypes.ContainsKey(baseName))
            {
                if (isArray)
                {
                    return(DynamicTypes.BuildingTypes[baseName].MakeArrayType(arrayDepth));
                }
                if (isGeneric)
                {
                    return(DynamicTypes.BuildingTypes[baseName].MakeGenericType(genericTypes));
                }
                return(DynamicTypes.BuildingTypes[baseName]);
            }
            else if (typeLookup)
            {
                try
                {
                    Type t = Type.GetType(
                        baseName,
                        (name) =>
                    {
                        return(AppDomain.CurrentDomain.GetAssemblies().Where(z => z.FullName == name.FullName).FirstOrDefault());
                    },
                        (assembly, typeName, typeBool) =>
                    {
                        Type _t = DynamicTypes.GetType(typeName, false);
                        if (_t == null)
                        {
                            _t = Type.GetType(typeName);
                        }
                        return(_t);
                    },
                        false);

                    if (isArray)
                    {
                        return(t.MakeArrayType(arrayDepth));
                    }
                    if (isGeneric)
                    {
                        return(t.MakeGenericType(genericTypes));
                    }
                    return(t);
                }
                catch (Exception e)
                {
                    System.Console.WriteLine(e);
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }