Esempio n. 1
0
        /// <summary>
        /// 动态类型的Xml序列化
        /// </summary>
        /// <param name="dynClass"></param>
        /// <returns></returns>
        public static XElement ToXml(DynClass dynClass)
        {
            XElement eleDynClass = new XElement("Class");

            eleDynClass.SetAttributeValue("Namespace", dynClass.Namespace ?? "");
            eleDynClass.SetAttributeValue("Name", dynClass.Name ?? "");
            eleDynClass.SetAttributeValue("BaseName", dynClass.BaseClass.Name ?? "");
            eleDynClass.SetAttributeValue("InterfaceNames", string.Join(",", dynClass.InterfaceNames.ToArray()));

            XElement eleDynProperties = new XElement("Properties");

            eleDynClass.Add(eleDynProperties);

            foreach (DynProperty dynProperty in dynClass.GetProperties())
            {
                XElement eleDynProperty = new XElement("Property");
                eleDynProperties.Add(eleDynProperty);

                // 设置DynProperty
                eleDynProperty.SetAttributeValue("ID", dynProperty.ID.ToString());
                eleDynProperty.SetAttributeValue("Name", dynProperty.Name);

                //ToDo:这两个属性是对象,等待程序完善后,再仔细考虑怎样处理
                eleDynProperty.SetAttributeValue("CurrentClassName", dynProperty.CurrentDynClass.Name);
                eleDynProperty.SetAttributeValue("ClassName", dynProperty.DynClass.Name);

                eleDynProperty.SetAttributeValue("Type", Enum.GetName(typeof(DynType), dynProperty.DynType));
                //eleDynProperty.SetAttributeValue("InheritEntityName", dynProperty.InheritEntityName);
                //eleDynProperty.SetAttributeValue("IsArray", dynProperty.IsArray.ToString());
                //eleDynProperty.SetAttributeValue("IsInherited", dynProperty.IsInherited.ToString());
                //eleDynProperty.SetAttributeValue("IsQueryProperty", dynProperty.IsQueryProperty.ToString());

                XElement eleDynAttributes = new XElement("Attributes");
                eleDynProperty.Add(eleDynAttributes);

                foreach (DynObject dynAttribute in dynProperty.Attributes)
                {
                    XElement eleDynAttribute = new XElement("Attribute");
                    eleDynAttributes.Add(eleDynAttribute);

                    //ToDo: 等待DynAttribute完善后添加
                    eleDynAttribute.SetAttributeValue("Name", "");
                }
            }

            XElement eleClassDynAttributes = new XElement("Attributes");

            eleDynClass.Add(eleClassDynAttributes);

            foreach (DynObject dynAttribute in dynClass.Attributes)
            {
                XElement eleDynAttribute = new XElement("Attribute");
                eleClassDynAttributes.Add(eleDynAttribute);

                //ToDo: 等待DynAttribute完善后添加
                eleDynAttribute.SetAttributeValue("Name", "");
            }

            return(eleDynClass);
        }
Esempio n. 2
0
        /// <summary>
        /// 基于实体类型构造对象
        /// </summary>
        /// <param name="className">类名</param>
        /// <param name="isHaveDefualt">是否成带默认值的对象</param>
        public DynObject(string className, bool isHaveDefualt)
        {
            DynClass dynClass = DynTypeManager.GetClass(className);

            if (dynClass == null)
            {
                throw new ApplicationException(string.Format("不存在名称为{0}的动态类", className));
            }

            _dynClass = dynClass;

            if (isHaveDefualt)
            {
                var properties = _dynClass.GetProperties();
                foreach (DynProperty dynProperty in properties)
                {
                    SetDefaultValue(dynProperty);
                }
            }
        }