<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Comments for Using Custom Attributes in C# - By David Clegg</title>
<link rel="alternate" type="text/plain" href="http://dn.codegear.com/article/30250" title="Using Custom Attributes in C# - By David Clegg" />
<link rel="self" type="application/atom+xml" href="http://dn.codegear.com/article/30250/feed" title="Comments for Using Custom Attributes in C# - By David Clegg" />
<id>http://dn.codegear.com/article/30250</id>
<updated>2008-12-04T11:40:05-08:00</updated>
<entry>
<title>Using Custom Attributes in C# - By David Clegg</title>
<author>
<name>David Clegg</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=40529</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=40529</id>
<updated>2007-09-25T01:15:17-07:00</updated>
<published>2007-09-25T01:15:17-07:00</published>
<summary>Using Custom Attributes in C# - By David Clegg</summary>
<content>Test to see whether Threads app is working</content>
</entry>
<entry>
<title>Using Custom Attributes in C# - By David Clegg</title>
<author>
<name>David Pizon</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=38814</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=38814</id>
<updated>2005-12-28T12:10:32-08:00</updated>
<published>2005-12-28T12:10:32-08:00</published>
<summary>Using Custom Attributes in C# - By David Clegg</summary>
<content>Mr. Clegg,Your article on custom attributes was very helpful. However, I am needing to know whether we can guarantee the order in which the attributes are returned from the getCustomAttributes(true) method. Are the attributes always returned from parent classes before the attributes of the inherited class?</content>
</entry>
<entry>
<title>re: AttributeTargets.Property and Property Type</title>
<author>
<name>Zarko Gajic</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=38331</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=38331</id>
<updated>2005-04-11T10:32:01-07:00</updated>
<published>2005-04-11T10:32:01-07:00</published>
<summary>re: AttributeTargets.Property and Property Type</summary>
<content>David, thanks. Unfortunately, and as you presumed, this is not the solution I was looking for. :(~Zarko</content>
</entry>
<entry>
<title>re: AttributeTargets.Property and Property Type</title>
<author>
<name>David Clegg</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=38330</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=38330</id>
<updated>2005-04-10T16:57:38-07:00</updated>
<published>2005-04-10T16:57:38-07:00</published>
<summary>re: AttributeTargets.Property and Property Type</summary>
<content>As far as I know there is no way to get information about the member the attribute was applied to. As a kludge, you could possibly get around this by passing the type information into the constructor of your custom attribute. It's not great, as it puts the onus on the user of the attribute to specify the correct type, so isn't foolproof. Nevertheless, I've pasted an example of this approach below :-using System;using System.Diagnostics;using System.Reflection;namespace TypeAttribute{public class TypeAttribute : Attribute{private Type fMemberType;public TypeAttribute(System.Type aMemberType) {Debug.Assert(aMemberType.IsAssignableFrom(typeof(string)), &quot;TypeAttribute can only be applied to string members&quot;);fMemberType = aMemberType;}public Type MemberType {get {return fMemberType;}}}class Test{[TypeAttribute(typeof(string))]public string fStr;[TypeAttribute(typeof(int))]public int fInt;static void Main(string[] args){MemberInfo[] members = typeof(Test).GetMembers();foreach (MemberInfo member in members) {Console.WriteLine(&quot;Reflecting {0}&quot;, member.Name);object[] attributes = member.GetCustomAttributes(true);foreach (Attribute attr in attributes) {if (attr.GetType().IsAssignableFrom(typeof(TypeAttribute))) Console.WriteLine(((TypeAttribute)attr).MemberType.ToString());}}}}}</content>
</entry>
<entry>
<title>AttributeTargets.Property and Property Type</title>
<author>
<name>Zarko Gajic</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=38326</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=38326</id>
<updated>2005-04-09T04:28:32-07:00</updated>
<published>2005-04-09T04:28:32-07:00</published>
<summary>AttributeTargets.Property and Property Type</summary>
<content>David, I've asked the following question on ms.* groups and got no answer...If I have a custom attribute (MyAttribute) with &quot;AttributeTargets.Property&quot;, is there any way from inside the attribute class to get the type of the property this attribute was applied to?I need to raise an exception if &quot;MyAttribute&quot; is attached to a non-string type of property, for example. In other words I have to make sure MyAttribute does not only target properties but also ONLY string properties.</content>
</entry>
<entry>
<title>Using Custom Attributes in C# - By David Clegg</title>
<author>
<name>Vladimir Afanasyev</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=38312</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=38312</id>
<updated>2005-03-29T23:20:30-07:00</updated>
<published>2005-03-29T23:20:30-07:00</published>
<summary>Using Custom Attributes in C# - By David Clegg</summary>
<content>Good and useful article but I think that SetCustomAttribute need to be explained here. Of course it is increase size of article. Or may be next part.</content>
</entry>
</feed>
