vb.net - Nullable(Of ) : type of parameter for <Attribute>. Does it work? -


i'm trying use type boolean parameter.

<attributeusage(attributetargets.method, inherited:=true, allowmultiple:=false)> public class myattribute              inherits attribute   property mycondition boolean end class 

i'm facing problem that, in object myattribute, i'm not able if boolean property has value false:

  • because of presence of parameter (e: mycondition:=false)

or,

  • because no parameter passed , property has value false because of initialization of object.

i though using property nullable(of boolean) instead, doesn't seem allowed?

property mycondition nullable(of boolean) 

error message "property or field 'mycondition' not have valid attribute type."

is there walk-around situation? workable parameter type string (that null on instantiation) ?

i believe can use simple data types can represented literal constant in code (e.g. 100, true, "test"). why nullable(of boolean) not working you. can, however, accomplish trying creating actual property handlers:

<attributeusage(attributetargets.method, inherited:=true, allowmultiple:=false)> public class myattribute     inherits attribute      public property mycondition boolean                     return _mycondition         end         set(byval value boolean)             _mycondition = value             _explicitlyset = true         end set     end property     private _mycondition boolean = false      public readonly property explicitlyset boolean                     return _explicitlyset         end     end property     private _explicitlyset boolean = false end class 

alternatively, make read-only nullable property , use constructor set it:

<attributeusage(attributetargets.method, inherited:=true, allowmultiple:=false)> public class myattribute     inherits attribute      public sub new()     end sub      public sub new(mycondition boolean)         _mycondition = mycondition     end sub      public readonly property mycondition nullable(of boolean)                     return _mycondition         end     end property     private _mycondition nullable(of boolean) end class 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -