示例#1
0
        protected virtual IBaseComponent DeserializeComponent(XElement element)
        {
            IBaseComponent component = null;

            //As long as we have a defined class and type, try to instantiate the corresponding component.
            if (element.Attribute("class") != null && element.Attribute("type") != null)
            {
                string assembly;

                if (element.Attribute("assembly") != null)
                {
                    assembly = element.Attribute("assembly").Value;
                }
                else
                {
                    assembly = Assembly.GetExecutingAssembly().FullName;
                }

                Type   classType       = Type.GetType(String.Format("{0},{1}", element.Attribute("class").Value, assembly));
                string stringInterface = element.Attribute("type").Value;

                //Find the proper interface designated by the entity definition so we can store it properly in the GameObject...
                Type interfaceType = classType.GetInterface(stringInterface);

                component = GetComponent(classType);

                component.InterfaceType = interfaceType;
                component.ConcreteType  = classType;

                component.Deserialize(element);
            }

            return(component);
        }