Beispiel #1
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));
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public void Serialize(XElement element, object value)
        {
            Type   type     = null;
            string typeText = "";

            if (value == null)
            {
                typeText = "(null)";
            }
            else
            {
                type     = value.GetType();
                typeText = type.FullName;
            }
            var valueElem = new XElement("Value", new XAttribute("Type", typeText));

            element.Add(valueElem);
            if (type.IsArray && value != null)
            {
                var elemType = type = type.GetElementType();
                var array    = (Array)value;
                for (var i = 0; i < array.Length; i++)
                {
                    var newElem = CreateElement(String.Format("[{0}]", i));
                    valueElem.Add(newElem);
                    Serialize(newElem, array.GetValue(i));
                }
            }
            else
            {
                var serializer = TypeSerializerManager.GetSerializer(type);
                if (serializer == null)
                {
                    if (value == null)
                    {
                        valueElem.Value = "(null)";
                    }
                    else
                    {
                        valueElem.Value = value.ToString();
                    }
                }
                else
                {
                    serializer.Serialize(this, valueElem, value);
                }
            }
        }