Esempio n. 1
0
        public TypeFabrication Fabricate(string def)
        {
            TypeFabrication result = new TypeFabrication();
              List<String> genericDefs = null;
              string cnt = "0";

              genericDefs = this.SplitDefTypes(def);
              if (genericDefs.Count > 0)
              {
            def = genericDefs.First();
            genericDefs.RemoveAt(0);
              }

              cnt = FindGenericCnt(def);
              List<TypeFabrication> generics = new List<TypeFabrication>();
              for (int i = 0; i < genericDefs.Count; i++)
            generics.Add(Fabricate(genericDefs[i]));

              string[] elements = def.Split(',');
              FillFabricationWithElements(result, elements);

              result.GenericCnt = Convert.ToInt32(cnt);
              result.GenericTypes.Clear();
              result.GenericTypes.AddRange(generics);

              result.CanInstantiate(false);
              return result;
        }
Esempio n. 2
0
        protected virtual Boolean CreateInstance(ModuleConfig config)
        {
            TypeFabrication moduleType = typeFactory.Fabricate(config.Type);

            moduleType.BaseType = typeFactory.FindBaseType(moduleType);
            if (moduleType.FindBaseType() && moduleType.FindCreateType())
            {
                config.Instance = moduleType.Fabricate();
            }
            IEnumerator enumerator = config.PropertyConfigCollection.GetEnumerator();

            while (enumerator.MoveNext())
            {
                PropertyConfig propertyConfig = enumerator.Current as PropertyConfig;
                propertyReferences[propertyConfig.UniqueId] = propertyConfig;
                propertyConfig.Parent = config;
            }
            return(config.Instance != null);
        }
Esempio n. 3
0
        protected virtual void FindParentGenerics(ModuleConfig config, TypeFabrication moduleType)
        {
            ModuleConfig parentConfig = config.Parent;

            while (moduleType.GenericTypes.Count < moduleType.GenericCnt)
            {
                if (parentConfig == null)
                {
                    break;
                }

                TypeFabrication parentType = typeFactory.Fabricate(parentConfig.Type);
                if (parentType.GenericTypes.Count == moduleType.GenericCnt)
                {
                    moduleType.GenericTypes.AddRange(parentType.GenericTypes);
                    break;
                }

                parentConfig = parentConfig.Parent;
            }
        }
Esempio n. 4
0
        protected virtual void FindParentGenerics(ModuleConfig config, TypeFabrication moduleType)
        {
            ModuleConfig parentConfig = config.Parent;
              while (moduleType.GenericTypes.Count < moduleType.GenericCnt)
              {
            if (parentConfig == null)
              break;

            TypeFabrication parentType = typeFactory.Fabricate(parentConfig.Type);
            if (parentType.GenericTypes.Count == moduleType.GenericCnt)
            {
              moduleType.GenericTypes.AddRange(parentType.GenericTypes);
              break;
            }

            parentConfig = parentConfig.Parent;
              }
        }
Esempio n. 5
0
 public Type FindBaseType(TypeFabrication fab)
 {
     Type result = null;
       if (fab != null)
       {
     bool findAssembly = fab.Assembly != "";
     result = FindInAssemblyList(fab, pluginAssemblies.AsEnumerable().GetEnumerator());
     if (result == null)
       result = FindInAssemblyList(fab, preloadedAssemblies.AsEnumerable().GetEnumerator());
       }
       return result;
 }
Esempio n. 6
0
        protected Type FindInAssemblyList(TypeFabrication fab, IEnumerator<Assembly> enumerator)
        {
            Type result = null;
              bool deepSearch = DeepSearch && (String.IsNullOrWhiteSpace(fab.Namespace));
              bool findAssembly = fab.Assembly != "";

              while ((result == null) && (enumerator.MoveNext()))
              {
            Assembly assembly = enumerator.Current;
            if (assembly.GetName().Name == fab.Assembly)
              result = assembly.GetType(fab.FullName);
            else
            {
              result = assembly.GetType(fab.FullName);
              if ((result == null) && (deepSearch))
            result = FindInAssembly(fab, assembly);
            }
              }
              return result;
        }
Esempio n. 7
0
 protected Type FindInAssembly(TypeFabrication fab, Assembly assembly)
 {
     IEnumerator<TypeInfo> et = assembly.DefinedTypes.GetEnumerator();
       while (et.MoveNext())
       {
     if (et.Current.Name.ToLower().Equals(fab.Name.ToLower()))
       return et.Current.AsType();
       }
       return null;
 }
Esempio n. 8
0
 protected void FillFabricationWithElements(TypeFabrication result, string[] elements)
 {
     for (int i = 0; i < elements.Count(); i++)
       {
     elements[i] = elements[i].Trim();
     if (elements[i].StartsWith("Version="))
       result.Version = elements[i].Replace("Version=", "").Trim();
     else if (elements[i].StartsWith("Culture="))
       result.Culture = elements[i].Replace("Culture=", "").Trim();
     else if (elements[i].StartsWith("PublicKeyToken="))
       result.PublicKeyToken = elements[i].Replace("PublicKeyToken=", "").Trim();
     else if (i == 1)
     {
       result.Assembly = elements[i].Trim();
     }
     else if (i == 0)
     {
       if (elements[i].Contains('.'))
       {
     result.Name = elements[i].Substring(elements[i].LastIndexOf('.') + 1).Trim();
     result.Namespace = elements[i].Substring(0, elements[i].LastIndexOf('.')).Trim();
       }
       else
     result.Name = elements[i].Trim();
       if (result.Name.Contains("`"))
     result.Name = result.Name.Substring(0, result.Name.IndexOf("`"));
     }
       }
 }