Right now, without using properties, I've got this:
public void SetNumber([Array(new int[]{8})] Byte[] number)
As you can see, I am adding the ArrayAttribute
attribute to the parameter.
What I want to do is the same but on a property setter. This doesn't work:
[Array(new int[]{8})]
public Byte[] SetNumber
{
set
{
}
get
{
return null;
}
}
Is there any way of attaching the attribute to the set_SetNumber
value
method parameter?
Also, a related question. The two methods generated (the get/set) don't have the custom attribute. Can anyone explain to me why is that?
Attributes are a mechanism by which the developer can attach extra information to language entities with a generalized syntax, instead of introducing new syntactic constructs or keywords for each feature.
The __attribute__ directive is used to decorate a code declaration in C, C++ and Objective-C programming languages. This gives the declared code additional attributes that would help the compiler incorporate optimizations or elicit useful warnings to the consumer of that code.
4.11 The __packed__ Attribute This attribute, attached to struct or union type definition, specifies that each member (other than zero-width bitfields) of the structure or union is placed to minimize the memory required. When attached to an enum definition, it indicates that the smallest integral type should be used.
The naked storage-class attribute is a Microsoft-specific extension to the C language. For functions declared with the naked storage-class attribute, the compiler generates code without prolog and epilog code. You can use this feature to write your own prolog/epilog code sequences using inline assembler code.
You need to use the param
attribute target on the set
:
public Byte[] SetNumber {
[param: Array(new int[] { 8 })]
set {
}
get {
return null;
}
}
As for the second question, the custom attribute is set on the property itself, not on the property accessor methods.
Also, if your ArrayAttribute
only ever applies to parameters, it could be defined like this:
[AttributeUsage(AttributeTargets.Parameter)]
public class ArrayAttribute : Attribute {
// ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With