c# - How do I get all class properties that accomplish a requisit established in its attribute value? -
to clarify this, a little example: The question is: How do I get properties only, where the bool parameter This is what I found: Any suggestions would be very apreciated. thank you in advanced. I think using Linq's query syntax will be a bit easier.
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; }
isListed to
true on
myAttrib ?
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? }}}}
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
Post a Comment