private static NodeBase XmlElementToBTNode(XmlElement xmlEle, NodeParent nodeParent = null)
        {
            string type = xmlEle.GetAttribute("type");
            Type   t    = Type.GetType(type);

            if (t == null)
            {
                return(null);
            }
            NodeBase node = Activator.CreateInstance(t) as NodeBase;

            if (node == null)
            {
                return(null);
            }

            node.name = xmlEle.Name;

            if (nodeParent != null)
            {
                nodeParent.AddChild(node);
            }

            XmlNodeList childNodes = xmlEle.ChildNodes;

            if (childNodes.Count > 0)
            {
                foreach (var xmlNode in childNodes)
                {
                    XmlElement childEle = xmlNode as XmlElement;
                    switch (childEle.Name)
                    {
                    case "param":
                        foreach (var xmlParam in childEle.ChildNodes)
                        {
                            XmlElement xe = xmlParam as XmlElement;
                            if (xe != null)
                            {
                                string name            = xe.Name;
                                string typeInfo        = xe.GetAttribute("type");
                                string serializedValue = xe.GetAttribute("value");
                                object value           = ParamInfoProcessor.Load(Type.GetType(typeInfo), serializedValue);
                                node.GetType().GetField(name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).SetValue(node, value);
                            }
                        }
                        break;

                    case "children":
                        foreach (var xmlChild in childEle.ChildNodes)
                        {
                            XmlElementToBTNode(xmlChild as XmlElement, node as NodeParent);
                        }
                        break;
                    }
                }
            }
            return(node);
        }
Beispiel #2
0
        internal int ExtractParamInfo()
        {
            if (paramInfo == null)
            {
                List <ParamInfo> paramInfo = new List <ParamInfo>();

                var fields = ReflectionUtils.GetNodeParamFields(this.GetType());

                foreach (var field in fields)
                {
                    paramInfo.Add(new ParamInfo
                    {
                        name            = field.Name,
                        type            = field.FieldType,
                        serializedValue = ParamInfoProcessor.Save(field.FieldType, field.GetValue(this))
                    });
                }
                this.paramInfo = paramInfo.ToArray();
            }
            return(paramInfo.Length);
        }