コード例 #1
0
        /// <inheritdoc />
        protected sealed override void DeserializeElement(XmlReader reader, bool serializeCollectionKey)
        {               //****************************************
            Type     MyOutputType;
            Assembly OutputAssembly;
            string   TypeName;

            //****************************************

            // Check we have a Type attribute
            if (!reader.MoveToAttribute("Type"))
            {
                Debug.Print("Output has no Type");

                return;
            }

            OutputType = reader.Value;

            //****************************************

            if (OutputType.IndexOf(',') == -1)
            {             // No Assembly definition, just a Type
                TypeName       = OutputType;
                OutputAssembly = typeof(OutputConfig).Assembly;
                MyOutputType   = OutputAssembly.GetType(typeof(FileOutput).Namespace + System.Type.Delimiter + TypeName);
            }
            else
            {             // Assembly definition, split
                string[] SplitType = OutputType.Split(',');

                OutputAssembly = Assembly.Load(string.Join(",", SplitType, 1, SplitType.Length - 1));

                if (OutputAssembly == null)
                {
                    Debug.Print("Output Assembly is missing");

                    reader.Skip();
                    return;
                }

                MyOutputType = OutputAssembly.GetType(SplitType[0]);
            }

            if (MyOutputType == null)
            {
                Debug.Print("Output Type is missing");

                reader.Skip();
                return;
            }

            Output = Activator.CreateInstance(MyOutputType, reader) as LogOutput;

            if (Output == null)
            {
                Debug.Print("Output could not be created");

                reader.Skip();
                return;
            }

            reader.Read();
        }