Support forum for Huagati DBML/EDMX Tools
5/12/2010 8:07:42 PM
 marksegura Posts: 2
|
Hi, I can't seem to figure out how to read the System.ComponentModel.Description property that is generated in the dbml file. I'm using C#. Any examples would be greatly appreciated. Thanks
|
|
0
• permalink
|
5/13/2010 8:42:44 AM
 Kristofer Andersson Moderator Posts: 331
|
Hi,
The following sample shows how to get hold of the description attribute from code:
PropertyDescriptorCollection members = TypeDescriptor.GetProperties(entity);
foreach (PropertyDescriptor member in members) { DescriptionAttribute description = (DescriptionAttribute)member.Attributes[typeof(System.ComponentModel.DescriptionAttribute)]; System.Diagnostics.Debug.WriteLine(member.Name + ": " + description.Description); }
Best regards, Kristofer
|
|
0
• permalink
|
5/13/2010 7:25:45 PM
 marksegura Posts: 2
|
Thanks Kristofer. I tried it out and it does give me some of the contents the Description tag but not quite everything which is strange to me. Here's how I was doing it:
TestDataContext td = new TestDataContext(); ISingleResult<MyObject> myObject= td.ReturnMyObjects(100);
foreach (MyObject mo in myObject) { PropertyDescriptorCollection members = TypeDescriptor.GetProperties(mo);
foreach (PropertyDescriptor member in members) { DescriptionAttribute description = (DescriptionAttribute)member.Attributes[typeof(System.ComponentModel.DescriptionAttribute)]; System.Diagnostics.Debug.WriteLine(member.Name + ": " + description.Description); } }
This gave me part of the description for the overall object. When I say part, I mean that in my dbml file, the partial class is tagged like this:
[System.ComponentModel.Description("MyTable: This is the description I want to pull from my code.\r\nIndexes:\r\nXPKMyTable (MyID);")] [Table(Name = "MyTable")]
Yet only the portion that came out was this: \r\nIndexes:\r\nXPKMyTable (MyID);
Strange right? I'm curious to how I would be able to pull the descriptions for the properties in the class (i.e. the extended properties of the columns)?
|
|
0
• permalink
|
5/18/2010 10:44:06 AM
 Kristofer Andersson Moderator Posts: 331
|
Hi,
My previous example only covered the properties in a class. If you want to get the description attribute for the class itself, you can do so by:
AttributeCollection attribs = TypeDescriptor.GetAttributes(entity); DescriptionAttribute classDescription = (DescriptionAttribute)attribs[typeof(System.ComponentModel.DescriptionAttribute)]; System.Diagnostics.Debug.WriteLine(TypeDescriptor.GetClassName(entity) + ": " + classDescription.Description);
Best regards, Kristofer
|
|
0
• permalink
|