[Mono-devel-list] some strangeness with CustomAttributes

Jonathan Stowe jns at gellyfish.com
Fri Aug 27 04:57:44 EDT 2004


This could be entirely down to me totally misunderstanding of how this
is supposed to work.

I have some code like:

using System;
using System.Reflection;
                                                                                
public class Test
{
   public static void Main()
   {
      Assembly a = Assembly.LoadWithPartialName("Linux.User");
                                                                                
      Attribute x =
Attribute.GetCustomAttribute(a,Type.GetType("System.Reflection.AssemblyDescriptionAttribute"),true);
                                                                                
      Console.WriteLine(x);
                                                                                
   }
}


And it works fine printing the class name as I would have expected but
if I change the attribute name to a new Attribute identical to
AssemblyDescription (but with a different name) and add that to a new
assembly (and compile the code above with the definition of the new
attribute) - the new custom attribute is not visible, now I can't see
any difference in the code for the AssemblyDescription and the new one I
have created.

What is even stranger is if I do:

using System;
using System.Reflection;
                                                                                
public class Test
{
   public static void Main()
   {
      Assembly a = Assembly.LoadWithPartialName("Linux.User");
                                                                                
      object[] o = a.GetCustomAttributes(true);
                                                                                
      foreach (object x in  a.GetCustomAttributes(true))
      {
         Console.WriteLine(x.GetType());
      }
   }
}

The type of the attribute is printed out alongside all of the other ones
but I am unable to do a comparison against it's type (except by
comparing the type name).  I guess I am missing the point here or
something, but can someone explain what is going on?

/J\




More information about the Mono-devel-list mailing list