示例#1
0
        /// <summary>
        /// 递归建立动态json对象
        /// </summary>
        /// <param name="d"></param>
        /// <param name="flags"></param>
        /// <returns></returns>
        private static dynamic BuildLoopDics(Dictionary <string, object> d, FrameDLRFlags flags)
        {
            FrameDLRObject rtn = new FrameDLRObject();

            if ((flags & FrameDLRFlags.SensitiveCase) != 0)
            {
                rtn.ignorecase = false;
            }
            else
            {
                rtn.ignorecase = true;
            }

            foreach (var item in d)
            {
                if (item.Value is Dictionary <string, object> )
                {
                    FrameDLRObject rtnloop = BuildLoopDics((Dictionary <string, object>)item.Value, flags);
                    rtn.SetValue(item.Key, (object)rtnloop);
                }
                else if (item.Value is object[])
                {
                    List <object> list = new List <object>();
                    foreach (var m in (object[])item.Value)
                    {
                        if (m is Dictionary <string, object> )
                        {
                            list.Add(BuildLoopDics((Dictionary <string, object>)m, flags));
                        }
                        else
                        {
                            list.Add(m);
                        }
                    }
                    rtn.SetValue(item.Key, list.ToArray());
                }
                else
                {
                    rtn.SetValue(item.Key, item.Value);
                }
            }

            return(rtn);
        }
示例#2
0
        public object Clone()
        {
            FrameDLRObject rtn = FrameDLRObject.CreateInstance();

            rtn.ignorecase = this.ignorecase;

            foreach (var k in this.Keys)
            {
                var obj = this.GetValue(k);
                if (obj is ICloneable)
                {
                    rtn.SetValue(k, ((ICloneable)obj).Clone());
                }
                else
                {
                    rtn.SetValue(k, obj);
                }
            }

            return(rtn);
        }
示例#3
0
        /// <summary>
        /// 通过xml建立动态对象,最简单的xml结构,如下:
        /// <xxx>
        ///     <n1></n1>
        ///     <n2></n2>
        ///     <nodes>
        ///         <nn1></nn1>
        ///         <nnn></nnn>
        ///     </nodes>
        ///     <nn></nn>
        /// </xxx>
        /// </summary>
        /// <param name="node"></param>
        /// <param name="flags"></param>
        /// <returns></returns>
        private static dynamic BuildLoopXml(XmlNodeList nodelist, FrameDLRFlags flags)
        {
            FrameDLRObject rtn = new FrameDLRObject();

            if ((flags & FrameDLRFlags.SensitiveCase) != 0)
            {
                rtn.ignorecase = false;
            }
            else
            {
                rtn.ignorecase = true;
            }

            foreach (XmlNode item in nodelist)
            {
                if (item.HasChildNodes && item.FirstChild.NodeType == XmlNodeType.Element)
                {
                    FrameDLRObject rtnloop = BuildLoopXml(item.ChildNodes, flags);
                    rtn.SetValue(item.Name, rtnloop);
                }
                else
                {
                    if (DateTimeStd.IsDateTime(item.InnerText))
                    {
                        rtn.SetValue(item.Name, DateTimeStd.ParseStd(item.InnerText).Value);
                    }
                    else
                    {
                        rtn.SetValue(item.Name, item.InnerText);
                    }
                }
            }


            return(rtn);
        }
示例#4
0
        /// <summary>
        /// 创建动态对象,通过反射将model的property转成动态对象。
        /// </summary>
        /// <param name="model"></param>
        /// <param name="flags"></param>
        /// <returns></returns>
        public static dynamic CreateInstance(object model, FrameDLRFlags flags)
        {
            FrameDLRObject rtn = CreateInstance();

            if (model != null)
            {
                if (model is Dictionary <string, object> )
                {
                    rtn = BuildLoopDics((Dictionary <string, object>)model, flags);
                }
                else if (model is Dictionary <string, FrameDLRObject> )
                {
                    rtn = BuildLoopDics((Dictionary <string, FrameDLRObject>)model, flags);
                }
                else if (model is string)
                {
                    XmlDocument xd = null;
                    if (TryParseXml(ComFunc.nvl(model), out xd))
                    {
                        rtn = BuildLoopXml(xd.FirstChild.ChildNodes, flags);
                    }
                    else
                    {
                        rtn = CreateInstance(ComFunc.nvl(model), flags);
                    }
                    return(rtn);
                }
                else if (model is XmlDocument)
                {
                    rtn = BuildLoopXml(((XmlDocument)model).FirstChild.ChildNodes, flags);
                }
                else
                {
                    var t = model.GetType();
                    rtn.ignorecase = flags == FrameDLRFlags.SensitiveCase ? false : true;
                    foreach (var p in t.GetProperties(BindingFlags.Instance | BindingFlags.Public))
                    {
                        rtn.SetValue(p.Name, p.GetValue(model));
                    }
                }
            }
            return(rtn);
        }
示例#5
0
        private static dynamic BuildLoopDics(Dictionary <string, FrameDLRObject> d, FrameDLRFlags flags)
        {
            FrameDLRObject rtn = new FrameDLRObject();

            if ((flags & FrameDLRFlags.SensitiveCase) != 0)
            {
                rtn.ignorecase = false;
            }
            else
            {
                rtn.ignorecase = true;
            }

            foreach (var item in d)
            {
                rtn.SetValue(item.Key, item.Value);
            }

            return(rtn);
        }