* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / corlib / System.Reflection / CustomAttributeData.cs
index 57a9526c331a3f0d1a438ea1f5cf57d946f2ec6f..2ebf4cfef7b7ab22226e8380775ed8abe9525cc3 100644 (file)
@@ -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)
 //
@@ -32,56 +33,94 @@ using System;
 using System.Collections.Generic;
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
+using System.Text;
 
 namespace System.Reflection {
 
+       [ComVisible (true)]
+       [Serializable]
        public sealed class CustomAttributeData {
+               ConstructorInfo ctorInfo;
+               IList<CustomAttributeTypedArgument> ctorArgs;
+               IList<CustomAttributeNamedArgument> namedArgs;
 
-               [MonoTODO]
+               internal CustomAttributeData (ConstructorInfo ctorInfo, object [] ctorArgs, object [] namedArgs)
+               {
+                       this.ctorInfo = ctorInfo;
+                       
+                       this.ctorArgs = Array.AsReadOnly<CustomAttributeTypedArgument> 
+                               (ctorArgs != null ? UnboxValues<CustomAttributeTypedArgument> (ctorArgs) : new CustomAttributeTypedArgument [0]);
+                       
+                       this.namedArgs = Array.AsReadOnly<CustomAttributeNamedArgument> 
+                               (namedArgs != null ? UnboxValues<CustomAttributeNamedArgument> (namedArgs) : new CustomAttributeNamedArgument [0]);
+               }
+
+               [ComVisible (true)]
                public ConstructorInfo Constructor {
                        get {
-                               throw new NotImplementedException ();
+                               return ctorInfo;
                        }
                }
 
-               [MonoTODO]
-               [CLSCompliant (false)]
                public IList<CustomAttributeTypedArgument> ConstructorArguments {
                        get {
-                               throw new NotImplementedException ();
+                               return ctorArgs;
                        }
                }
 
-               [MonoTODO]
-               [CLSCompliant (false)]
                public IList<CustomAttributeNamedArgument> NamedArguments {
                        get {
-                               throw new NotImplementedException ();
+                               return namedArgs;
                        }
                }
 
-               [MonoTODO]
-               [CLSCompliant (false)]
-               public static IList<CustomAttributeData> GetCustomAttributes (Assembly yarget) {
-                       throw new NotImplementedException ();
+               public static IList<CustomAttributeData> GetCustomAttributes (Assembly target) {
+                       return MonoCustomAttrs.GetCustomAttributesData (target);
                }
 
-               [MonoTODO]
-               [CLSCompliant (false)]
                public static IList<CustomAttributeData> GetCustomAttributes (MemberInfo target) {
-                       throw new NotImplementedException ();
+                       return MonoCustomAttrs.GetCustomAttributesData (target);
                }
 
-               [MonoTODO]
-               [CLSCompliant (false)]
                public static IList<CustomAttributeData> GetCustomAttributes (Module target) {
-                       throw new NotImplementedException ();
+                       return MonoCustomAttrs.GetCustomAttributesData (target);
                }
 
-               [MonoTODO]
-               [CLSCompliant (false)]
                public static IList<CustomAttributeData> GetCustomAttributes (ParameterInfo target) {
-                       throw new NotImplementedException ();
+                       return MonoCustomAttrs.GetCustomAttributesData (target);
+               }
+
+               public override string ToString ()
+               {
+                       StringBuilder sb = new StringBuilder ();
+
+                       sb.Append ("[" + ctorInfo.DeclaringType.Name + " (");
+                       for (int i = 0; i < ctorArgs.Count; i++) {
+                               sb.Append (ctorArgs [i].ToString ());
+                               if (i + 1 < ctorArgs.Count)
+                                       sb.Append (", ");
+                       }
+
+                       if (namedArgs.Count > 0)
+                               sb.Append (", ");
+                       
+                       for (int j = 0; j < namedArgs.Count; j++) {
+                               sb.Append (namedArgs [j].ToString ());
+                               if (j + 1 < namedArgs.Count)
+                                       sb.Append (", ");
+                       }
+                       sb.AppendFormat (")]");
+
+                       return sb.ToString ();
+               }
+
+               static T [] UnboxValues<T> (object [] values)
+               {
+                       T [] retval = new T [values.Length];
+                       for (int i = 0; i < values.Length; i++)
+                               retval [i] = (T) values [i];
+
+                       return retval;
                }
        }