X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2Fcorlib%2FSystem.Reflection%2FCustomAttributeTypedArgument.cs;h=41520a144b53c26bd1ad9f0c4499a3fe11f035ba;hb=4323fbeaebf249f016dfdd6dc9b3b52a515f87c4;hp=3ebf3ac20a0bd7ee151b391e48eac1bfcc6509b1;hpb=b011be898ecf9fa5739dfd664d25f1d5f9f06de3;p=mono.git diff --git a/mcs/class/corlib/System.Reflection/CustomAttributeTypedArgument.cs b/mcs/class/corlib/System.Reflection/CustomAttributeTypedArgument.cs index 3ebf3ac20a0..41520a144b5 100644 --- a/mcs/class/corlib/System.Reflection/CustomAttributeTypedArgument.cs +++ b/mcs/class/corlib/System.Reflection/CustomAttributeTypedArgument.cs @@ -31,12 +31,12 @@ using System; using System.Runtime.InteropServices; +using System.Collections.ObjectModel; namespace System.Reflection { -#if NET_2_0 [ComVisible (true)] -#endif + [Serializable] public struct CustomAttributeTypedArgument { Type argumentType; object value; @@ -45,6 +45,17 @@ namespace System.Reflection { { this.argumentType = argumentType; this.value = value; + + // MS seems to convert arrays into a ReadOnlyCollection + if (value is Array) { + Array a = (Array)value; + + Type etype = a.GetType ().GetElementType (); + CustomAttributeTypedArgument[] new_value = new CustomAttributeTypedArgument [a.GetLength (0)]; + for (int i = 0; i < new_value.Length; ++i) + new_value [i] = new CustomAttributeTypedArgument (etype, a.GetValue (i)); + this.value = new ReadOnlyCollection (new_value); + } } public Type ArgumentType { @@ -61,14 +72,40 @@ namespace System.Reflection { public override string ToString () { - string val = value.ToString (); + string val = value != null ? value.ToString () : String.Empty; if (argumentType == typeof (string)) return "\"" + val + "\""; if (argumentType == typeof (Type)) return "typeof (" + val + ")"; + if (argumentType.IsEnum) + return "(" + argumentType.Name + ")" + val; return val; } + + public override bool Equals (object obj) + { + if (!(obj is CustomAttributeTypedArgument)) + return false; + CustomAttributeTypedArgument other = (CustomAttributeTypedArgument) obj; + return other.argumentType == argumentType && + value != null ? value.Equals (other.value) : (object) other.value == null; + } + + public override int GetHashCode () + { + return (argumentType.GetHashCode () << 16) + (value != null ? value.GetHashCode () : 0); + } + + public static bool operator == (CustomAttributeTypedArgument left, CustomAttributeTypedArgument right) + { + return left.Equals (right); + } + + public static bool operator != (CustomAttributeTypedArgument left, CustomAttributeTypedArgument right) + { + return !left.Equals (right); + } } }