[Mono-list] Possible semantics difference between mcs and csc

Paolo Molaro lupus@ximian.com
Fri, 3 Jan 2003 16:23:10 +0100


On 01/01/03 Artur Karazniewicz wrote:
> ValidatorAttribute[] validators = 
> (ValidatorAttribute[])Attribute.GetCustomAttributes(fieldInfo, 
> typeof(ValidatorAttribute));
> 
> this probably works on windows (mcs). This is strange a bit - since
> Attribute.GetCustomAttributes returns Attribute[] - and
> looks like mcs/.NET casts Attribute[] to ValidatorAttribute[]
> (I'm new to C# - i'm not sure maybe this type of cast
> is allowed in .NET - i mean mcs/.NET casts all elements of array
> of Attribute to array of subtype of Attribyte (ValidatorAttribute in 
> this case)). mcs/mono throws   System.InvalidCastException.
[...]

On 01/01/03 A Rafael D Teixeira wrote:
> I use array casting a lot: because that is the way to get fixed-size arrays 
> from arraylists, assembled element by element, with method ToArray(). So it 
> is certainly a valid cast on C#, and mcs must allow it.

It's not a mcs issue, but a runtime one. 
GetCustomAttributes (..., attributeType) returns an array of the given
type, not simply an array of Attribute.
It's fixed in cvs now.

lupus

-- 
-----------------------------------------------------------------
lupus@debian.org                                     debian/rules
lupus@ximian.com                             Monkeys do it better