﻿<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <description><![CDATA[Comments for Using Custom Attributes in C# - By David Clegg]]></description>
    <title><![CDATA[Comments for Using Custom Attributes in C# - By David Clegg]]></title>
    <link>http://dn.codegear.com/article/30250</link>
    <!-- source: http://dn.codegear.com/article/30250/feed-->
    <dc:date>2008-12-04T11:43:11-08:00</dc:date>
    <item>
      <description><![CDATA[Test to see whether Threads app is working]]></description>
      <title><![CDATA[Using Custom Attributes in C# - By David Clegg]]></title>
      <managingEditor>
	 (David Clegg)
</managingEditor>
      <guid isPermaLink="true">http://threads.codegear.com/threads/threads.exe/view?commentid=40529</guid>
      <dc:date>2007-09-25T01:15:17-07:00</dc:date>
      <pubDate>2007-09-25T01:15:17-07:00</pubDate>
      <source url="http://dn.codegear.com/article/30250/feed">Comments for Using Custom Attributes in C# - By David Clegg</source>
    </item>
    <item>
      <description><![CDATA[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?]]></description>
      <title><![CDATA[Using Custom Attributes in C# - By David Clegg]]></title>
      <managingEditor>
	 (David Pizon)
</managingEditor>
      <guid isPermaLink="true">http://threads.codegear.com/threads/threads.exe/view?commentid=38814</guid>
      <dc:date>2005-12-28T12:10:32-08:00</dc:date>
      <pubDate>2005-12-28T12:10:32-08:00</pubDate>
      <source url="http://dn.codegear.com/article/30250/feed">Comments for Using Custom Attributes in C# - By David Clegg</source>
    </item>
    <item>
      <description><![CDATA[David, thanks. Unfortunately, and as you presumed, this is not the solution I was looking for. :(~Zarko]]></description>
      <title><![CDATA[re: AttributeTargets.Property and Property Type]]></title>
      <managingEditor>
	 (Zarko Gajic)
</managingEditor>
      <guid isPermaLink="true">http://threads.codegear.com/threads/threads.exe/view?commentid=38331</guid>
      <dc:date>2005-04-11T10:32:01-07:00</dc:date>
      <pubDate>2005-04-11T10:32:01-07:00</pubDate>
      <source url="http://dn.codegear.com/article/30250/feed">Comments for Using Custom Attributes in C# - By David Clegg</source>
    </item>
    <item>
      <description><![CDATA[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)), "TypeAttribute can only be applied to string members");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("Reflecting {0}", member.Name);object[] attributes = member.GetCustomAttributes(true);foreach (Attribute attr in attributes) {if (attr.GetType().IsAssignableFrom(typeof(TypeAttribute))) Console.WriteLine(((TypeAttribute)attr).MemberType.ToString());}}}}}]]></description>
      <title><![CDATA[re: AttributeTargets.Property and Property Type]]></title>
      <managingEditor>
	 (David Clegg)
</managingEditor>
      <guid isPermaLink="true">http://threads.codegear.com/threads/threads.exe/view?commentid=38330</guid>
      <dc:date>2005-04-10T16:57:38-07:00</dc:date>
      <pubDate>2005-04-10T16:57:38-07:00</pubDate>
      <source url="http://dn.codegear.com/article/30250/feed">Comments for Using Custom Attributes in C# - By David Clegg</source>
    </item>
    <item>
      <description><![CDATA[David, I've asked the following question on ms.* groups and got no answer...If I have a custom attribute (MyAttribute) with "AttributeTargets.Property", 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 "MyAttribute" 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.]]></description>
      <title><![CDATA[AttributeTargets.Property and Property Type]]></title>
      <managingEditor>
	 (Zarko Gajic)
</managingEditor>
      <guid isPermaLink="true">http://threads.codegear.com/threads/threads.exe/view?commentid=38326</guid>
      <dc:date>2005-04-09T04:28:32-07:00</dc:date>
      <pubDate>2005-04-09T04:28:32-07:00</pubDate>
      <source url="http://dn.codegear.com/article/30250/feed">Comments for Using Custom Attributes in C# - By David Clegg</source>
    </item>
    <item>
      <description><![CDATA[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.]]></description>
      <title><![CDATA[Using Custom Attributes in C# - By David Clegg]]></title>
      <managingEditor>
	 (Vladimir Afanasyev)
</managingEditor>
      <guid isPermaLink="true">http://threads.codegear.com/threads/threads.exe/view?commentid=38312</guid>
      <dc:date>2005-03-29T23:20:30-07:00</dc:date>
      <pubDate>2005-03-29T23:20:30-07:00</pubDate>
      <source url="http://dn.codegear.com/article/30250/feed">Comments for Using Custom Attributes in C# - By David Clegg</source>
    </item>
    <generator>Atom 1.0 XSLT Transform v1 (http://atom.geekhood.net)</generator>
  </channel>
</rss>