Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Dynamic Attribute Arguments

Is there a way to do the following? I see that the Attribute Arguments must be a constant expression, so how would I work around this? If I dont want to load some properties into a datagridview using binding, whats the next best alternative?

  class TestObj
  {
     private bool isBrowsable = false;

     [Browsable(isBrowsable)]
     public string String1
     {
        get
        {
           return "Foo";
        }
     }
     [Browsable(isBrowsable)]
     public string String2
     {
        get
        {
           return "Baz";
        }
     }
  }
like image 373
SwDevMan81 Avatar asked Dec 30 '22 20:12

SwDevMan81


1 Answers

You can provide dynamic custom type information at runtime by implementing the ICustomTypeDescriptor interface - but this is quite a bit of work at not nearly as simple as decorating properties with attributes.

like image 98
Daniel Brückner Avatar answered Jan 08 '23 13:01

Daniel Brückner