Example #1
0
        private void CheckCommandProperty(CommonProperty commandProperty)
        {
            if (commandProperty.IsNot(typeof(ICommand)) || commandProperty.IsNot(typeof(RelayCommand)))
            {
                const string errorMessage = "Patching command property type must be ICommand or RelayCommand";

                log.Error(errorMessage);
                throw new PropertyPatchingException(errorMessage, commandProperty.FullName);
            }

            if (char.IsLower(commandProperty.Name.First()))
            {
                const string errorMessage = "First character of property name must be to upper case";

                log.Error(errorMessage);
                throw new PropertyPatchingException(errorMessage, commandProperty.FullName);
            }

            // ReSharper disable once InvertIf
            if (!commandProperty.Name.EndsWith(commandPropertyEndsWith))
            {
                var errorMessage = $"Patching command property name must be ends with '{commandPropertyEndsWith}'";

                log.Error(errorMessage);
                throw new PropertyPatchingException(errorMessage, commandProperty.FullName);
            }
        }
        public void TestCommonProperty()
        {
            var prop = new CommonProperty("platform", "anycpu");

            Assert.AreEqual("platform", prop.Name);
            Assert.AreEqual("anycpu", prop.EvaluatedValue);
            Assert.AreEqual("Property platform = anycpu", prop.ToString());

            prop.PropertyChanged += PropOnPropertyChanged;
            prop.Name             = "Foobar";
            prop.EvaluatedValue   = "eggs";
        }
        /// <summary>
        /// 获取实体属性的参数和SQL
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        private List <ParamSqlModel> GetParamSQLByEntityProp(TEntity entity)
        {
            List <ParamSqlModel> paramSqlModels = new List <ParamSqlModel>();

            //获取公共属性
            CommonProperty cmmonProperty = (CommonProperty)entity;

            //如果没有变更则返回null
            if (cmmonProperty.ChanageProperty.Count == 0)
            {
                return(null);
            }

            //循环遍历属性得到SQL脚本和参数
            foreach (PropertyInfo prop in entity.GetType().GetProperties())
            {
                ParamSqlModel paramSqlModel = new ParamSqlModel();

                //如果不包含在变更集里面则跳出
                if (cmmonProperty.ChanageProperty.ContainsKey(prop.Name) == false)
                {
                    continue;
                }

                //获取属性数据库信息
                EntityPropColumnAttributes columnAttribute = columnAttrList.Where(w => w.propName.ToLower() == prop.Name.ToLower()).First();

                //字段
                paramSqlModel.Field         = columnAttribute.fieldName;
                paramSqlModel.IsDbGenerated = columnAttribute.isDbGenerated;
                paramSqlModel.IsPrimaryKey  = columnAttribute.isPrimaryKey;

                //SQL字符
                string propSql = columnAttribute.fieldName + "=@" + columnAttribute.fieldName;
                paramSqlModel.SQL = propSql;

                //参数添加
                object       val   = prop.GetValue(entity, null);
                SqlParameter param = new SqlParameter("@" + columnAttribute.fieldName, val ?? DBNull.Value);
                DbType       dbtype;
                Enum.TryParse(prop.PropertyType.Name, out dbtype);
                param.DbType = dbtype;

                //参数赋值
                paramSqlModel.Param = param;

                paramSqlModels.Add(paramSqlModel);
            }
            return(paramSqlModels);
        }
        private void CheckProperty(CommonProperty property)
        {
            if (property.IsInheritedFrom(typeof(ICommand)))
            {
                const string errorMessage = "Patching property type cannot be inherited from ICommand";

                log.Error(errorMessage);
                throw new PropertyPatchingException(errorMessage, property.FullName);
            }

            // ReSharper disable once InvertIf
            if (char.IsLower(property.Name.First()))
            {
                const string errorMessage = "First character of property name must be to upper case";

                log.Error(errorMessage);
                throw new PropertyPatchingException(errorMessage, property.FullName);
            }
        }
Example #5
0
 public static bool Is(this CommonProperty commonProperty, Type type)
 {
     return(commonProperty.ReflectionProperty.PropertyType.Instance == type);
 }
Example #6
0
 public static TAttribute GetReflectionAttribute <TAttribute>(this CommonProperty commonProperty) where TAttribute : Attribute
 {
     return((TAttribute)commonProperty.ReflectionProperty.Attributes.FirstOrDefault(attribute => attribute.AttributeType.Instance == typeof(TAttribute))?.Instance);
 }
Example #7
0
 public static bool IsNotInheritedFrom(this CommonProperty commonProperty, Type type)
 {
     return(!commonProperty.IsInheritedFrom(type));
 }
Example #8
0
 public static bool IsInheritedFrom(this CommonProperty commonProperty, Type type)
 {
     return(type.IsAssignableFrom(commonProperty.ReflectionProperty.PropertyType.Instance));
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     order = GetOrderInfo();
     if (!IsPostBack)
     {
         rpBind();
         IsCPCPBind();
     }
 }
        private void PatchProprty(MonoCecilAssembly monoCecilAssembly, CommonType viewModelBase, CommonType viewModel, CommonProperty property)
        {
            CheckProperty(property);

            var propertyName = property.Name;

            log.Debug($"Property name: {propertyName}");

            var backgroundFieldName = $"{char.ToLower(propertyName.First())}{propertyName.Substring(1)}";

            log.Debug($"Background field name: {backgroundFieldName}");

            var backgroundField = viewModel.Fields.FirstOrDefault(field => field.Name == backgroundFieldName)?.MonoCecilField;

            if (backgroundField == null)
            {
                backgroundField = monoCecilFactory.CreateField(backgroundFieldName, FieldAttributes.Private, property.MonoCecilProperty.PropertyType);
                viewModel.MonoCecilType.AddField(backgroundField);
                log.Debug("Background field was created");
            }
            else
            {
                log.Debug("Background field was connected");
            }

            GenerateGetMethodBody(property.MonoCecilProperty, backgroundField);
            GenerateSetMethodBody(monoCecilAssembly, viewModelBase, property.MonoCecilProperty, propertyName, backgroundField);
        }