[Mono-devel-list] Null Attributes arguments

Marek Safar marek.safar at seznam.cz
Thu Dec 9 11:26:33 EST 2004


Hello Kelly,

>--- Marek Safar <marek.safar at seznam.cz> wrote:
>
>  
>
>>>using System;
>>>      
>>>
>>[X (null)]
>>class X : Attribute {
>>	int ID;
>>	public X () {}
>>        public X (object o) { ID = 55; }
>>	
>>        static int Main ()
>>	{
>>	    object[] attrs =
>>typeof(X).GetCustomAttributes(typeof (X),false);
>>	    if (attrs.Length != 1)
>>		return 2;
>>	    
>>	    X x = attrs [0] as X;
>>	    if (x.ID != 55)
>>		return 2;
>>	    
>>	    Console.WriteLine("OK");
>>	    return 0;
>>	}
>>}
>>    
>>
>
>What is the value of the argument ("object o") passed
>to the constructor of X in this case by the compiler? 
>Is it *null* or something else?
>  
>
Yes, it is *null*

>Shouldn't the test check that it is what is expected
>as well, and of the correct type?
>  
>
Yes, I could improve the test to test whether o == null inside 
parametric ctor.

Thanks
Marek




More information about the Mono-devel-list mailing list