/// <summary>添加单个属性</summary> /// <param name="field">字段</param> public CodeMemberProperty AddProperty(IDataColumn field) { //String name = FieldNames[field.Name]; var name = field.Name; var p = new CodeMemberProperty(); p.Attributes = MemberAttributes.Public | MemberAttributes.Final; p.Name = name; p.Type = new CodeTypeReference(field.DataType); p.AddSummary(field.Description); // 特性 if (!field.Description.IsNullOrWhiteSpace()) { p.AddAttribute <DescriptionAttribute>(field.Description); } if (!field.DisplayName.IsNullOrWhiteSpace() && field.DisplayName != field.Name) { p.AddAttribute <DisplayNameAttribute>(field.DisplayName); } p.AddAttribute <DataObjectFieldAttribute>(field.PrimaryKey, field.Identity, field.Nullable, field.Length); p.AddAttribute <BindColumnAttribute>(field.ID, field.ColumnName, field.Description, field.Default == null ? null : field.Default, field.RawType, field.Precision, field.Scale, field.IsUnicode); p.HasGet = true; p.HasSet = true; var f = ("_" + p.Name).ToExp(); p.GetStatements.Add(f.Return()); var changing = "OnPropertyChanging".Invoke(p.Name, "$value"); var changed = "OnPropertyChanged".Invoke(p.Name); p.SetStatements.Add(changing.IfTrue(f.Assign("$value"), changed.ToStat())); Class.Members.Add(p); return(p); }
/// <summary> /// Marks the given code property as a collection property /// </summary> /// <param name="property">The property</param> public static void MarkCollectionProperty(this CodeMemberProperty property) { property.AddAttribute(typeof(DesignerSerializationVisibilityAttribute), DesignerSerializationVisibility.Content); }
/// <summary>添加单个属性</summary> /// <param name="field">字段</param> public CodeMemberProperty AddProperty(IDataColumn field) { //String name = FieldNames[field.Name]; var name = field.Name; var p = new CodeMemberProperty(); p.Attributes = MemberAttributes.Public | MemberAttributes.Final; p.Name = name; p.Type = new CodeTypeReference(field.DataType); //p.Comments.Add(AddSummary(field.Description)); p.AddSummary(field.Description); // 特性 //if (!field.Description.IsNullOrWhiteSpace()) //{ // p.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(DescriptionAttribute)), new CodeAttributeArgument(new CodePrimitiveExpression(field.Description)))); // p.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(DisplayNameAttribute)), new CodeAttributeArgument(new CodePrimitiveExpression(field.Description)))); //} if (!field.Description.IsNullOrWhiteSpace()) { p.AddAttribute <DescriptionAttribute>(field.Description); } if (!field.DisplayName.IsNullOrWhiteSpace() && field.DisplayName != field.Name) { p.AddAttribute <DisplayNameAttribute>(field.DisplayName); } //p.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(DataObjectFieldAttribute)), // new CodeAttributeArgument(new CodePrimitiveExpression(field.PrimaryKey)), // new CodeAttributeArgument(new CodePrimitiveExpression(field.Identity)), // new CodeAttributeArgument(new CodePrimitiveExpression(field.Nullable)), // new CodeAttributeArgument(new CodePrimitiveExpression(field.Length)) // )); //p.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(BindColumnAttribute)), // new CodeAttributeArgument(new CodePrimitiveExpression(field.ID)), // new CodeAttributeArgument(new CodePrimitiveExpression(field.ColumnName)), // new CodeAttributeArgument(new CodePrimitiveExpression(field.Description)), // new CodeAttributeArgument(new CodePrimitiveExpression(field.Default == null ? null : field.Default)), // new CodeAttributeArgument(new CodePrimitiveExpression(field.RawType)), // new CodeAttributeArgument(new CodePrimitiveExpression(field.Precision)), // new CodeAttributeArgument(new CodePrimitiveExpression(field.Scale)), // new CodeAttributeArgument(new CodePrimitiveExpression(field.IsUnicode)) // )); p.AddAttribute <DataObjectFieldAttribute>(field.PrimaryKey, field.Identity, field.Nullable, field.Length); p.AddAttribute <BindColumnAttribute>(field.ID, field.ColumnName, field.Description, field.Default == null ? null : field.Default, field.RawType, field.Precision, field.Scale, field.IsUnicode); p.HasGet = true; p.HasSet = true; var f = ("_" + p.Name).ToExp(); //p.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(null, "_" + p.Name))); p.GetStatements.Add(f.Return()); //var changing = new CodeMethodInvokeExpression(null, "OnPropertyChanging", new CodePrimitiveExpression(p.Name), new CodeVariableReferenceExpression("value")); //var changed = new CodeMethodInvokeExpression(null, "OnPropertyChanged", new CodePrimitiveExpression(p.Name)); var changing = "OnPropertyChanging".Invoke(p.Name, "$value"); var changed = "OnPropertyChanged".Invoke(p.Name); //var cas = new CodeAssignStatement(); //cas.Left = new CodeFieldReferenceExpression(null, "_" + p.Name); //cas.Right = new CodeVariableReferenceExpression("value"); //var cas = f.Assign("$value".ToExp()); //p.SetStatements.Add(new CodeConditionStatement(changing, cas, changed.ToStat())); p.SetStatements.Add(changing.IfTrue(f.Assign("$value"), changed.ToStat())); Class.Members.Add(p); return(p); }