Hello, can you please explain me what is the significance of
[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("activityid")]
in the following code?[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("activityid")] public Microsoft.Xrm.Sdk.EntityReference ActivityId { get { return this.GetAttributeValue<Microsoft.Xrm.Sdk.EntityReference>("activityid"); } set { this.OnPropertyChanging("ActivityId"); this.SetAttributeValue("activityid", value); this.OnPropertyChanged("ActivityId"); } }
I searched for this thing and I got many posts which gave me answer as the ones in square brackets are Attributes in C#. But, then attributes are related with methods. Over here,
ActivityId
doesn't seem to be a method. So, how can[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("activityid")]
act as an attribute?Is it related to
C#
or it has got something to do withCRM
?
Asked
Active
Viewed 216 times
1

Vikram
- 3,996
- 8
- 37
- 58
-
@DavinTryon, I thought people will put comment saying it is possible duplicate of other posts. But, please read my Q properly. It says "I searched for this thing and I got many posts which gave me answer as the ones in square brackets are Attributes in C#. But, then attributes are related with methods. Over here, ActivityId doesn't seem to be a method. So, how can [Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("activityid")] act as an attribute?" – Vikram May 08 '14 at 15:52
-
1Attributes in C# can be applied to any attribute target (http://msdn.microsoft.com/en-us/library/system.attributetargets(v=vs.110).aspx) – Davin Tryon May 08 '14 at 15:52
-
3@Vikram Attributes are not limited to methods: http://msdn.microsoft.com/en-us/library/tw5zxet9.aspx – Adam Houldsworth May 08 '14 at 15:53
-
@DavinTryon and Adam Houldsworth, Thanks for the explanation and the links. But, then what will be the use of attribute when it is used with field? – Vikram May 08 '14 at 15:56
-
2@Vikram Attributes are only used via reflection or sometimes via the compiler. The intended style of use is usually the same regardless of where it is applied. – Adam Houldsworth May 08 '14 at 15:57
1 Answers
2
The confusion comes from your statement about attributes only being valid on methods. Attributes can be valid on items specified in the AttributeTargets
enum:
http://msdn.microsoft.com/en-us/library/system.attributetargets.aspx
This then puts you back to the answer being "they are attributes". That attribute has simply been applied to a property.

Adam Houldsworth
- 63,413
- 11
- 150
- 187
-
You are correct! I got it. But, then why a property would have an attribute? I mean, what is the use of it? Is it used with for 'set' inside that property? – Vikram May 08 '14 at 16:00