Ejemplo n.º 1
0
        /// <summary>
        /// 尝试获取属性
        /// </summary>
        /// <param name="attributeName">属性名</param>
        /// <param name="attributeDynObject">返回属性对象</param>
        /// <returns>是否成功获取</returns>
        public bool TryGetAttribute(string attributeName, out DynObject attributeDynObject)
        {
            if (string.IsNullOrEmpty(attributeName))
            {
                throw new ApplicationException(string.Format("类{0}在尝试获取标记时 输入参数为空或null", _name));
            }

            return(_attributes.TryGetValue(attributeName, out attributeDynObject));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 根据特性名获取拥有此特性的类
        /// </summary>
        /// <param name="attributeName"></param>
        /// <returns></returns>
        public List <DynClass> GetDynClassesByAttribute(string attributeName)
        {
            List <DynClass> attrs = new List <DynClass>();

            foreach (DynClass dclass in _dynClasses.Values)
            {
                DynObject dynObject = null;
                if (dclass.TryGetAttribute(attributeName, out dynObject))
                {
                    attrs.Add(dclass);
                }
            }

            return(attrs);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 添加属性
 /// </summary>
 /// <param name="attribute">属性(属性是动态对象)</param>
 public void AddAttribute(DynObject attribute)
 {
     if (attribute != null)
     {
         if (!_attributes.ContainsKey(attribute.DynClass.Name))
         {
             _attributes[attribute.DynClass.Name] = attribute;
         }
         else
         {
             throw new ApplicationException(string.Format("已经包含属性名称为{0}的属性", attribute.DynClass.Name));
         }
     }
     else
     {
         throw new ApplicationException("要添加的属性为null");
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 添加属性
 /// </summary>
 /// <param name="attribute">属性(属性是动态对象)</param>
 public void AddAttribute(DynObject attribute)
 {
     if (attribute != null)
     {
         if (!_attributes.ContainsKey(attribute.DynClass.Name))
         {
             _attributes[attribute.DynClass.Name] = attribute;
         }
         else
         {
             throw new ApplicationException(string.Format("类{0}已经包含标记名称为{1}的属性", _name, attribute.DynClass.Name));
         }
     }
     else
     {
         throw new ApplicationException(string.Format("类{0}要添加的标记为null", _name));
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 根据特性名获取拥有此特性的方法
        /// </summary>
        /// <param name="attributeName"></param>
        /// <returns></returns>
        public List <DynMethod> GetDynMethodesByAttribute(string attributeName)
        {
            List <DynMethod> attrs = new List <DynMethod>();

            foreach (DynClass dclass in _dynClasses.Values)
            {
                foreach (DynMethod dmethod in dclass.GetMethods())
                {
                    DynObject dynObject = null;
                    if (dmethod.TryGetAttribute(attributeName, out dynObject))
                    {
                        attrs.Add(dmethod);
                    }
                }
            }

            return(attrs);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 根据特性名获取拥有此特性的属性
        /// </summary>
        /// <param name="attributeName"></param>
        /// <returns></returns>
        public List <DynProperty> GetDynPropertiesByAttribute(string attributeName)
        {
            List <DynProperty> attrs = new List <DynProperty>();

            foreach (DynClass dclass in _dynClasses.Values)
            {
                foreach (DynProperty dproperty in dclass.GetProperties())
                {
                    DynObject dynObject = null;
                    if (dproperty.TryGetAttribute(attributeName, out dynObject))
                    {
                        attrs.Add(dproperty);
                    }
                }
            }

            return(attrs);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// 根据名称获取属性
 /// </summary>
 /// <param name="attributeName">属性名称</param>
 /// <returns></returns>
 public DynObject GetAttribute(string attributeName)
 {
     if (!string.IsNullOrEmpty(attributeName))
     {
         DynObject value = null;
         if (_attributes.TryGetValue(attributeName, out value))
         {
             return(value);
         }
         else
         {
             throw new ApplicationException(string.Format("不包含属性名称为{0}的属性", attributeName));
         }
     }
     else
     {
         throw new ApplicationException("属性名为空或null");
     }
 }
Ejemplo n.º 8
0
 /// <summary>
 /// 根据名称获取属性
 /// </summary>
 /// <param name="attributeName">属性名称</param>
 /// <returns></returns>
 public DynObject GetAttribute(string attributeName)
 {
     if (!string.IsNullOrEmpty(attributeName))
     {
         DynObject attribute = null;
         if (_attributes.TryGetValue(attributeName, out attribute))
         {
             return(attribute);
         }
         else
         {
             throw new ApplicationException(string.Format("动态类{0}不包含标记名称为{1}的属性", _name, attributeName));
         }
     }
     else
     {
         throw new ApplicationException(string.Format("动态类{0}在获取是否存在标记时 输入参数为空或null", _name));
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// 动态对象的Xml序列化
        /// </summary>
        /// <returns></returns>
        public static XElement ToXml(DynObject dynObject)
        {
            XElement eleDynClass = new XElement("Object");

            eleDynClass.SetAttributeValue("Class", dynObject.DynClass.Name);

            XElement eleDynProperties = new XElement("Properties");

            eleDynClass.Add(eleDynProperties);

            foreach (DynProperty entityProperty in dynObject.DynClass.GetProperties())
            {
                XElement eleDynProperty = new XElement("Property");
                eleDynProperties.Add(eleDynProperty);

                eleDynProperty.SetAttributeValue(entityProperty.Name, dynObject.GetPropertyValue(entityProperty.Name));
            }

            return(eleDynClass);
        }
Ejemplo n.º 10
0
        private string GenerateDictFormJsCode(DynObject dictForm, string templateName)
        {
            List <Rock.Dyn.Core.DynObject> formItems = dictForm["FormItems"] as List <Rock.Dyn.Core.DynObject>;

            Rock.Dyn.Core.DynObject        dataGrid    = dictForm["DataGrid"] as Rock.Dyn.Core.DynObject;
            List <Rock.Dyn.Core.DynObject> gridColumns = dataGrid["GridColumns"] as List <Rock.Dyn.Core.DynObject>;

            if (formItems.Count == 0)
            {
                return("对象模型未添加表单项");
            }
            if (gridColumns.Count == 0)
            {
                return("对象模型未添加列表项");
            }
            Dictionary <string, object> item = new Dictionary <string, object>();
            Template dictTemplate            = Template.Create("DictTemplatet", File.ReadAllText(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "bin\\Templatet\\" + templateName + ".txt", Encoding.UTF8));

            item.Add("dictForm", dictForm);
            return(dictTemplate.Render("DictTemplatet", item));
        }
Ejemplo n.º 11
0
        private string GenerateBillFormJsCode(DynObject billForm, string templateName)
        {
            List <Rock.Dyn.Core.DynObject> masterFormItems = billForm["MasterFormItems"] as List <Rock.Dyn.Core.DynObject>;

            Rock.Dyn.Core.DynObject        detailMainReferGrid        = billForm["DetailMainReferGrid"] as Rock.Dyn.Core.DynObject;
            List <Rock.Dyn.Core.DynObject> detailMainReferGridColumns = detailMainReferGrid["GridColumns"] as List <Rock.Dyn.Core.DynObject>;

            if (masterFormItems.Count == 0)
            {
                return("单据模型未添加主表列表项");
            }
            if (detailMainReferGridColumns.Count == 0)
            {
                return("单据模型未添加明细主参照列表项");
            }

            Dictionary <string, object> item = new Dictionary <string, object>();
            Template dictTemplate            = Template.Create("BillTemplatet", File.ReadAllText(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "bin\\Templatet\\" + templateName + ".txt", Encoding.UTF8));

            item.Add("billForm", billForm);
            return(dictTemplate.Render("BillTemplatet", item));
        }
Ejemplo n.º 12
0
 /// <summary>
 /// 尝试获取属性
 /// </summary>
 /// <param name="attributeName">属性名</param>
 /// <param name="attributeDynObject">返回属性对象</param>
 /// <returns>是否成功获取</returns>
 public bool TryGetAttribute(string attributeName, out DynObject attributeDynObject)
 {
     return(_attributes.TryGetValue(attributeName, out attributeDynObject));
 }
Ejemplo n.º 13
0
        public object GetDefaultValue()
        {
            DynObject dynDefaultValue = null;

            if (ContainsAttribute("DefaultValue"))
            {
                dynDefaultValue = GetAttribute("DefaultValue");
            }

            bool isHaveDefaultValue = false;

            if (dynDefaultValue != null && !string.IsNullOrEmpty(dynDefaultValue["Value"] as string))
            {
                string defaultType  = dynDefaultValue["Type"] as string;
                string defaultValue = dynDefaultValue["Value"] as string;
                switch (defaultType)
                {
                case "Direct":
                    object trueValue = null;
                    if (TryPasentValue(defaultValue, this, ref trueValue))
                    {
                        isHaveDefaultValue = true;
                        return(trueValue);
                    }
                    break;

                case "Compute":
                    return(DynStringResolver.Resolve(defaultValue));

                default:
                    break;
                }
            }

            if (!isHaveDefaultValue)
            {
                switch (CollectionType)
                {
                case CollectionType.None:
                    if (IsNotNull)
                    {
                        switch (DynType)
                        {
                        case DynType.Void:
                        case DynType.Bool:
                            return(false);

                        case DynType.Byte:
                            return(null);

                        case DynType.String:
                            return("");

                        case DynType.Struct:
                            return(null);

                        case DynType.DateTime:
                            return(DateTime.Now);

                        case DynType.Double:
                            return(0.0);

                        case DynType.Decimal:
                            return((decimal)0.0);

                        case DynType.I16:
                            return((short)0);

                        case DynType.I32:
                            return((int)0);

                        case DynType.I64:
                            return((long)0);

                        default:
                            break;
                        }
                    }
                    else
                    {
                        return(null);;
                    }

                    break;

                case CollectionType.List:
                    switch (DynType)
                    {
                    case DynType.Void:
                    case DynType.Bool:
                        return(new List <bool>());

                    case DynType.Byte:
                        return(new List <Byte>());

                    case DynType.String:
                        return(new List <String>());

                    case DynType.Struct:
                        return(new List <DynObject>());

                    case DynType.Double:
                        return(new List <Double>());

                    case DynType.Decimal:
                        return(new List <Decimal>());

                    case DynType.I16:
                        return(new List <Int16>());

                    case DynType.I32:
                        return(new List <Int32>());

                    case DynType.I64:
                        return(new List <Int64>());

                    case DynType.DateTime:
                        return(new List <DateTime>());

                    default:
                        break;
                    }

                    break;

                case CollectionType.Map:
                    return(new Dictionary <string, object>());

                case CollectionType.Set:
                    throw new ApplicationException("暂不支持Set集合类型");
                }
            }
            return(null);
        }
Ejemplo n.º 14
0
        //public void SelfValidate()
        //{
        //    SelfValidate(_propertyValues.Keys.ToArray<string>());
        //}

        //public void SelfValidate(string[] feilds)
        //{
        //    if (feilds != null)
        //    {
        //        foreach (var propertyName in feilds)
        //        {
        //            DynProperty dynProperty = GetProperty(propertyName);
        //            foreach (var validater in dynProperty.Validater)
        //            {
        //                DynObject vailidateConfig = dynProperty.ValidateConfig[validater.Key];
        //                if (vailidateConfig != null)
        //                {
        //                    validater.Value.ValidateProperty(_propertyValues[propertyName], dynProperty.ValidateConfig[validater.Key], dynProperty, this);
        //                }
        //                else
        //                {
        //                    throw new ApplicationException("给定的验证器没有 验证器配置");
        //                }
        //            }
        //        }
        //    }
        //}



        //private static void DefaultReferValidate(DynObject dynObject)
        //{
        //    //默认关联验证
        //    //不增加的
        //}

        //public void ReferValidate()
        //{
        //    ReferValidateHandle(this);
        //}
        /// <summary>
        /// 尝试获取属性
        /// </summary>
        /// <param name="attributeName">属性名</param>
        /// <param name="attributeDynObject">返回属性对象</param>
        /// <returns>是否成功获取</returns>
        public bool TryGetClassAttribute(string attributeName, out DynObject attributeDynObject)
        {
            return(this.DynClass.TryGetAttribute(attributeName, out attributeDynObject));
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 浅度克隆
        /// </summary>
        /// <returns></returns>
        public DynObject Clone()
        {
            DynObject cloneDynObject = new DynObject(this.DynClass.Name);

            DynProperty[] dynProperties = this._dynClass.GetProperties();

            foreach (var dynProperty in dynProperties)
            {
                switch (dynProperty.CollectionType)
                {
                case CollectionType.None:
                    switch (dynProperty.DynType)
                    {
                    case DynType.Void:
                        break;

                    case DynType.Bool:
                    case DynType.Byte:
                    case DynType.Double:
                    case DynType.Decimal:
                    case DynType.I16:
                    case DynType.I32:
                    case DynType.I64:
                    case DynType.String:
                    case DynType.DateTime:
                        cloneDynObject[dynProperty.Name] = this.GetPropertyValue(dynProperty.Name);
                        break;

                    case DynType.Struct:
                        break;

                    default:
                        break;
                    }
                    break;

                case CollectionType.List:
                    IList valueList = null;
                    switch (dynProperty.DynType)
                    {
                    case DynType.Void:
                        break;

                    case DynType.Bool:
                        valueList = new List <Boolean>();
                        break;

                    case DynType.Byte:
                        valueList = new List <Byte>();
                        break;

                    case DynType.Double:
                        valueList = new List <Double>();
                        break;

                    case DynType.Decimal:
                        valueList = new List <Decimal>();
                        break;

                    case DynType.I16:
                        valueList = new List <Int16>();
                        break;

                    case DynType.I32:
                        valueList = new List <Int32>();
                        break;

                    case DynType.I64:
                        valueList = new List <Int64>();
                        break;

                    case DynType.String:
                        valueList = new List <String>();
                        break;

                    case DynType.Struct:
                        break;

                    case DynType.DateTime:
                        valueList = new List <String>();
                        break;

                    default:
                        break;
                    }

                    if (valueList != null)
                    {
                        IList baseList = this.GetPropertyValue(dynProperty.Name) as IList;
                        foreach (var item in baseList)
                        {
                            valueList.Add(item);
                        }

                        cloneDynObject[dynProperty.Name] = valueList;
                    }

                    break;

                case CollectionType.Set:

                    break;

                case CollectionType.Map:
                    Dictionary <string, object> valueMap = new Dictionary <string, object>();
                    IDictionary oldmap = this.GetPropertyValue(dynProperty.Name) as IDictionary;
                    foreach (DictionaryEntry item in oldmap)
                    {
                        if (item.Value is DynObject || item.Value is ICollection)
                        {
                            valueMap.Add(item.Key as string, null);
                        }
                        else
                        {
                            valueMap.Add(item.Key as string, item.Value);
                        }
                    }
                    cloneDynObject[dynProperty.Name] = valueMap;
                    break;

                default:
                    break;
                }
            }


            return(cloneDynObject);
        }