X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2Fcorlib%2FSystem.Reflection%2FCustomAttributeTypedArgument.cs;h=c73e32c9a949f817af86a8ae42ed854606be4613;hb=7f030179c484ebd5afbbbf63e81a5cb37a7a7f48;hp=ec0fd49bda218518e21440407f0a41395994ab79;hpb=601f4125e59673eafdfb78957be34125bd09c00a;p=mono.git diff --git a/mcs/class/corlib/System.Reflection/CustomAttributeTypedArgument.cs b/mcs/class/corlib/System.Reflection/CustomAttributeTypedArgument.cs index ec0fd49bda2..c73e32c9a94 100644 --- a/mcs/class/corlib/System.Reflection/CustomAttributeTypedArgument.cs +++ b/mcs/class/corlib/System.Reflection/CustomAttributeTypedArgument.cs @@ -3,6 +3,7 @@ // // Author: // Zoltan Varga (vargaz@gmail.com) +// Carlos Alberto Cortez (calberto.cortez@gmail.com) // // Copyright (C) 2004 Novell, Inc (http://www.novell.com) // @@ -26,34 +27,103 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // -#if NET_2_0 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; + +#if NET_4_0 + public +#endif + CustomAttributeTypedArgument (Type argumentType, object value) + { + if (argumentType == null) + throw new ArgumentNullException ("argumentType"); + + 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); + } + } + +#if NET_4_0 + public CustomAttributeTypedArgument (object value) + { + if (value == null) + throw new ArgumentNullException ("value"); + + this.argumentType = value.GetType (); + this.value = value; + } +#endif - [MonoTODO] public Type ArgumentType { get { - throw new NotImplementedException (); + return argumentType; } } - [MonoTODO] public object Value { get { - throw new NotImplementedException (); + return value; } } + + public override string 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); + } } } -#endif