The following example marks a property as appropriate to merge.
|
<MergableProperty(True)> _
Public Property MyProperty() As Integer
Get
' Insert code here.
Return 0
End Get
Set
' Insert code here.
End Set
End Property
|
|
[MergableProperty(true)]
public int MyProperty {
get {
// Insert code here.
return 0;
}
set {
// Insert code here.
}
}
|
|
public:
[MergableProperty(true)]
property int MyProperty
{
int get()
{
// Insert code here.
return 0;
}
void set( int value )
{
// Insert code here.
}
}
|
|
/** @attribute MergableProperty(true)
*/
/** @property
*/
public int get_MyProperty()
{
// Insert code here.
return 0;
} //get_MyProperty
/** @property
*/
public void set_MyProperty(int value)
{
// Insert code here.
} //set_MyProperty
|
|
public MergableProperty(true)
function get MyProperty() : int{
// Insert code here.
return 0
}
function set MyProperty(value : int){
// Insert code here.
}
|
The next example shows how to check the value of the MergablePropertyAttribute for MyProperty. First the code gets a PropertyDescriptorCollection with all the properties for the object. Next it indexes into the PropertyDescriptorCollection to get MyProperty. Then it returns the attributes for this property and saves them in the attributes variable.
The example presents two different ways of checking the value of the MergablePropertyAttribute. In the second code fragment, the example calls the Equals method with a static value. In the last code fragment, the example uses the AllowMerge property to check the value.
|
' Gets the attributes for the property.
Dim attributes As AttributeCollection = _
TypeDescriptor.GetProperties(Me)("MyProperty").Attributes
' Checks to see if the value of the MergablePropertyAttribute is Yes.
If attributes(GetType(MergablePropertyAttribute)).Equals(MergablePropertyAttribute.Yes) Then
' Insert code here.
End If
' This is another way to see if the property is bindable.
Dim myAttribute As MergablePropertyAttribute = _
CType(attributes(GetType(MergablePropertyAttribute)), MergablePropertyAttribute)
If myAttribute.AllowMerge Then
' Insert code here.
End If
|
|
// Gets the attributes for the property.
AttributeCollection attributes =
TypeDescriptor.GetProperties(this)["MyProperty"].Attributes;
// Checks to see if the value of the MergablePropertyAttribute is Yes.
if(attributes[typeof(MergablePropertyAttribute)].Equals(MergablePropertyAttribute.Yes)) {
// Insert code here.
}
// This is another way to see if the property is bindable.
MergablePropertyAttribute myAttribute =
(MergablePropertyAttribute)attributes[typeof(MergablePropertyAttribute)];
if(myAttribute.AllowMerge) {
// Insert code here.
}
|
|
// Gets the attributes for the property.
AttributeCollection^ attributes = TypeDescriptor::GetProperties( this )[ "MyProperty" ]->Attributes;
// Checks to see if the value of the MergablePropertyAttribute is Yes.
if ( attributes[ MergablePropertyAttribute::typeid ]->Equals( MergablePropertyAttribute::Yes ) )
{
// Insert code here.
}
// This is another way to see if the property is bindable.
MergablePropertyAttribute^ myAttribute = dynamic_cast<MergablePropertyAttribute^>(attributes[ MergablePropertyAttribute::typeid ]);
if ( myAttribute->AllowMerge )
{
// Insert code here.
}
|
|
// Gets the attributes for the property.
AttributeCollection attributes =
TypeDescriptor.GetProperties(this).get_Item(
"MyProperty").get_Attributes();
// Checks to see if the value of the MergablePropertyAttribute is Yes.
if (attributes.get_Item(
MergablePropertyAttribute.class.ToType()).Equals
(MergablePropertyAttribute.Yes)) {
// Insert code here.
}
// This is another way to see if the property is bindable.
MergablePropertyAttribute myAttribute = ((MergablePropertyAttribute)
(attributes.get_Item(MergablePropertyAttribute.class.ToType())));
if (myAttribute.get_AllowMerge()) {
// Insert code here.
}
|
|
// Gets the attributes for the property.
var attributes : AttributeCollection = TypeDescriptor.GetProperties(this)["MyProperty"].Attributes
// Checks to see if the value of the MergablePropertyAttribute is Yes.
if(attributes(MergablePropertyAttribute).Equals(MergablePropertyAttribute.Yes)){
// Insert code here.
}
// This is another way to see if the property is bindable.
var myAttribute : MergablePropertyAttribute = MergablePropertyAttribute(attributes(MergablePropertyAttribute))
if(myAttribute.AllowMerge){
// Insert code here.
}
|
If you marked a class with the MergablePropertyAttribute, use the following code to check the value.
|
Dim attributes As AttributeCollection = TypeDescriptor.GetAttributes(MyProperty)
If attributes(GetType(MergablePropertyAttribute)).Equals(MergablePropertyAttribute.Yes) Then
' Insert code here.
End If
|
|
AttributeCollection attributes =
TypeDescriptor.GetAttributes(MyProperty);
if(attributes[typeof(MergablePropertyAttribute)].Equals(MergablePropertyAttribute.Yes)) {
// Insert code here.
}
|
|
AttributeCollection^ attributes = TypeDescriptor::GetAttributes( MyProperty );
if ( attributes[ MergablePropertyAttribute::typeid ]->Equals( MergablePropertyAttribute::Yes ) )
{
// Insert code here.
}
|
|
AttributeCollection attributes =
TypeDescriptor.GetAttributes("MyProperty");
if (attributes.get_Item(
MergablePropertyAttribute.class.ToType()).Equals(
MergablePropertyAttribute.Yes)) {
// Insert code here.
}
|
|
var attributes : AttributeCollection = TypeDescriptor.GetAttributes(MyProperty)
if(attributes(MergablePropertyAttribute).Equals(MergablePropertyAttribute.Yes)){
// Insert code here.
}
|