예제 #1
0
        private KeyValuePair <FlowSourceObjectBase, KeyValuePair <string, string>[]>[] ReadSources(XmlReader reader, FlowSourceManager manager)
        {
            var ret = new List <KeyValuePair <FlowSourceObjectBase, KeyValuePair <string, string>[]> >();

            while (reader.Read())
            {
                if (reader.IsStartElement())
                {
                    switch (reader.Name)
                    {
                    case "Source":
                        var fullName = reader.GetAttribute("FullName");
                        var ID       = int.Parse(reader.GetAttribute("ID"), CultureInfo.InvariantCulture);
                        var scopeId  = ParseId(reader.GetAttribute("ScopeID"));
                        var source   = FlowSourceObjectManager.CreateSource(fullName);
                        if (source == null)
                        {
                            throw new ArgumentException(String.Format("{0} not found", fullName));
                        }
                        source.Id      = ID;
                        source.ScopeId = scopeId;
                        var defaultValues = ReadValues(reader.ReadSubtree(), source);
                        ret.Add(new KeyValuePair <FlowSourceObjectBase, KeyValuePair <string, string>[]>(source, defaultValues));
                        manager.AddFlowSourceObject(source);
                        break;
                    }
                }
            }
            reader.Close();

            return(ret.ToArray());
        }
예제 #2
0
        public static IEnumerable <AssemblyAndType> EnumerateFromFile(string filePath, Type[] enumerateTypes)
        {
            if (!File.Exists(filePath))
            {
                Console.WriteLine("{0} does not exist.", filePath);
                yield break;
            }

            var asm = System.Reflection.Assembly.LoadFrom(filePath);

            foreach (Type t in asm.GetTypes())
            {
                if (t.IsClass && t.IsPublic && !t.IsAbstract)
                {
                    var asmAndType = new AssemblyAndType(asm, t);
                    foreach (Type enumerateType in enumerateTypes)
                    {
                        if (t.IsSubclassOf(enumerateType))
                        {
                            yield return(asmAndType);
                        }
                    }

                    if (!ShouldBeIgnored(t))
                    {
                        if (t.IsSubclassOf(typeof(FlowSourceObjectBase)))
                        {
                            FlowSourceObjectManager.AddFlowSourceObject(asmAndType);
                        }
                        else if (t.IsSubclassOf(typeof(TypeConverterBase)))
                        {
                            TypeConverterManager.AddConverter((TypeConverterBase)asmAndType.Assembly.CreateInstance(asmAndType.Type.FullName));
                        }
                        else if (t.IsSubclassOf(typeof(TypeConverterFromBase)))
                        {
                            TypeConverterManager.AddConverter((TypeConverterFromBase)asmAndType.Assembly.CreateInstance(asmAndType.Type.FullName));
                        }
                        else if (t.IsSubclassOf(typeof(TypeConverterToBase)))
                        {
                            TypeConverterManager.AddConverter((TypeConverterToBase)asmAndType.Assembly.CreateInstance(asmAndType.Type.FullName));
                        }
                        else if (t.IsSubclassOf(typeof(TypeFormatterBase)))
                        {
                            TypeFormatterManager.AddFormatter((TypeFormatterBase)asmAndType.Assembly.CreateInstance(asmAndType.Type.FullName));
                        }
                        else if (t.IsSubclassOf(typeof(TypeSerializerBase)))
                        {
                            TypeSerializerManager.AddSerializer((TypeSerializerBase)asmAndType.Assembly.CreateInstance(asmAndType.Type.FullName));
                        }
                    }
                }
            }
        }