c# - Unique Property Attribute value per class -


here attribute class:

[attributeusage(attributetargets.property, allowmultiple = false, inherited = true)] public class tagattribute : attribute {     public tagattribute (string tag)     {         tag = tag;     }      public string tag { get; set; } } 

the idea create class , decorate each property tag attribute , tag value. example: property name have attribute tag("userid")

one of validations need check tag value ("userid") unique per class properties. meaning no other property has tag same value ("userid")

i'm pretty sure there simple way linq casting must done , i'd appreciate :)

thanks in advance :)

this code print duplicate tags in given assembly, , list of properties have tag:

assembly asm = ... var propertiesbytag =     t in asm.gettypes()     p in t.getproperties()     in p.getcustomattributes(typeof(tagattribute)).cast<tagattribute>()     group p a.tag g     select new     {         tag = g.key,         properties = g.toarray()     }      foreach (var dup in propertiesbytag.where(x => x.properties.length > 1))     {         console.writeline("duplicated tag: {0}", dup.tag);         foreach(var p in dup.properties)             console.writeline("\t{0}.{1}", p.declaringtype.name, p.name);     } 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -