I’m trying to use the type Boolean for some parameter.
<AttributeUsage(AttributeTargets.Method, Inherited:=True, AllowMultiple:=False)>
Public Class MyAttribute
Inherits Attribute
Property MyCondition As Boolean
End Class
I’m facing the problem that, in my object MyAttribute, I’m not able to say if the boolean property has the value False:
- because of the presence of the parameter (e: MyCondition:=false)
or,
- because no parameter was passed and my property has the value False because of the initialization of my object.
I though about using a property Nullable(Of Boolean) instead, but this doesn’t seem to be allowed?
Property MyCondition As Nullable(of Boolean)
Error message “Property or field ‘MyCondition’ does not have a valid attribute type.”
Is there a walk-around this situation? Is the only workable parameter type is String (that is null on instantiation) ?
I believe that you can only use simple data types that can be represented as a literal constant in code (e.g. 100, True, “Test”). That is probably why Nullable(Of Boolean) is not working for you. You can, however, accomplish what you are trying to do by creating actual property handlers:
Alternatively, you could make it a read-only nullable property and use a constructor to set it: