Using the same bunch of attributes in many classes in C# -


i trying use same bunch of attributes in many classes. how can achieve in c#?

if unclear trying achieve, please have @ example:

public class {     public string property1 { get; set; }     public string property2 { get; set; }     public string property3 { get; set; }      [attribute1]     [attribute2]     [attribute3]     public string foo { get; set; } }  public class b {     public string property4 { get; set; }     public string property5 { get; set; }     public string property6 { get; set; }      [attribute1]     [attribute2]     [attribute3]     public string foo { get; set; } } 

basically foo has same bunch of attributes each time, copy-paste not option, since error-prone.

in particular example work inherit a , b class:

public class c {     [attribute1]     [attribute2]     [attribute3]     public string foo { get; set; } } 

but having more properties foo, cannot achieved, since c# not allow multi-inheritance.

you might consider making c interface , adorning interface property attributes - solves multi inheritance issue.

public interface ic {     [attribute1]     [attribute2]     [attribute3]     string foo { get; set; } } 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -