Can I define properties in partial classes, then mark them with attributes in another partial class?

前端 未结 5 1199
野趣味
野趣味 2020-12-02 06:17

Is there a way I can have a generated code file like so:

public partial class A {
public string a {get; set;}
}

and then in another file:

5条回答
  •  借酒劲吻你
    2020-12-02 07:07

    This is my answer
    different class files or you can combine the metadatas in a same file but keep the namespace the same..so they can see each other obviously.

    keep in mind when you update your model like add more columns you have to update the project class too.

    --your model class
    public partial class A {
        public string a {get; set;}
    }
    
    --your project class 
    public class Ametadata {
         [Attribute("etc")]
         public string a {get; set;}
    }
    
    
    [MetadataType(typeof(Ametadata))]
    public partial class A
    {
    }
    

提交回复
热议问题