c# - How do I get all class properties that accomplish a requisit established in its attribute value? -


itemprop = "text">

to clarify this, a little example:

  the public class book {[MyAttrib (isListed = True)] public string name; [MyAritibb (ILIITIST = False)] Public DateTime release date; [My ettrib (iiilit ist = true)] public ink page number; [MyAttrib (IILITIT = false)] Public float price; }   

The question is: How do I get properties only, where the bool parameter isListed to true on myAttrib ?

This is what I found:

  propertyinfo [] myProps = myBookInstance GetType (). GetProperties (). Where (x => (x.GetCustomAttributes (type MyAttrib, false)). Lantel & gt; 0). ToArray ();   

myProps found book , but from now on all the properties, I can not understand how to exclude them when it's < Code> isListed parameter false returns

  foreach (MyProps in PropertyInfo prop) {object [] attributes = myProps.GetCustomAttributes (incorrect). Agrech (object at attribute) {MyAtib Mayet = At ​​MyTreab; If (myAtt! = Null) {If (myAtt.isListed.Equals (false)) // If true, should I add this property to other property info []? // Is there any way to filter? }}}}   

Any suggestions would be very apreciated. thank you in advanced.

I think using Linq's query syntax will be a bit easier.

  on proplist = myBookInstance.GetType (PROP) .GetProperties () go attrib = prop.GetCustomAttributes (typeof (MyAttrib), Incorrect) .Cast from & lt; MyAttrib & gt ;! () .FirstOrDefault () where attrib = null & amp; & Amp; Choose Attrib.isList Sahara;    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -