Adjust sleeping values
[mono.git] / mcs / class / corlib / System.Reflection / ParameterInfo.cs
index 045354633174f0ccbfa842dacd64e3fd03bcf989..6de8aeb01aff97b98b0d619884c40841b77b3e34 100644 (file)
 using System.Reflection.Emit;
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
+using System.Collections.Generic;
 
 namespace System.Reflection
 {
-#if NET_2_0
        [ComVisible (true)]
        [ComDefaultInterfaceAttribute (typeof (_ParameterInfo))]
-#endif
        [Serializable]
        [ClassInterfaceAttribute (ClassInterfaceType.None)]
        public class ParameterInfo : ICustomAttributeProvider, _ParameterInfo {
@@ -46,6 +45,7 @@ namespace System.Reflection
                protected int PositionImpl;
                protected ParameterAttributes AttrsImpl;
                private UnmanagedMarshal marshalAs;
+               //ParameterInfo parent;
 
                protected ParameterInfo () {
                }
@@ -64,6 +64,30 @@ namespace System.Reflection
                        }
                }
 
+               /*FIXME this constructor looks very broken in the position parameter*/
+               internal ParameterInfo (ParameterInfo pinfo, Type type, MemberInfo member, int position) {
+                       this.ClassImpl = type;
+                       this.MemberImpl = member;
+                       if (pinfo != null) {
+                               this.NameImpl = pinfo.Name;
+                               this.PositionImpl = pinfo.Position - 1; // ParameterInfo.Position is zero-based
+                               this.AttrsImpl = (ParameterAttributes) pinfo.Attributes;
+                       } else {
+                               this.NameImpl = null;
+                               this.PositionImpl = position - 1;
+                               this.AttrsImpl = ParameterAttributes.None;
+                       }
+               }
+
+               internal ParameterInfo (ParameterInfo pinfo, MemberInfo member) {
+                       this.ClassImpl = pinfo.ParameterType;
+                       this.MemberImpl = member;
+                       this.NameImpl = pinfo.Name;
+                       this.PositionImpl = pinfo.Position;
+                       this.AttrsImpl = pinfo.Attributes;
+                       //this.parent = pinfo;
+               }
+
                /* to build a ParameterInfo for the return type of a method */
                internal ParameterInfo (Type type, MemberInfo member, UnmanagedMarshal marshalAs) {
                        this.ClassImpl = type;
@@ -99,56 +123,49 @@ namespace System.Reflection
                        get {return AttrsImpl;}
                }
                public virtual object DefaultValue {
-                       get {return DefaultValueImpl;}
+                       get {
+                               if (ClassImpl == typeof (Decimal)) {
+                                       /* default values for decimals are encoded using a custom attribute */
+                                       DecimalConstantAttribute[] attrs = (DecimalConstantAttribute[])GetCustomAttributes (typeof (DecimalConstantAttribute), false);
+                                       if (attrs.Length > 0)
+                                               return attrs [0].Value;
+                               } else if (ClassImpl == typeof (DateTime)) {
+                                       /* default values for DateTime are encoded using a custom attribute */
+                                       DateTimeConstantAttribute[] attrs = (DateTimeConstantAttribute[])GetCustomAttributes (typeof (DateTimeConstantAttribute), false);
+                                       if (attrs.Length > 0)
+                                               return new DateTime (attrs [0].Ticks);
+                               }
+                               return DefaultValueImpl;
+                       }
                }
 
                public bool IsIn {
                        get {
-#if NET_2_0
                                return (Attributes & ParameterAttributes.In) != 0;
-#else
-                               return (AttrsImpl & ParameterAttributes.In) != 0;
-#endif
                        }
                }
 
                public bool IsLcid {
                        get {
-#if NET_2_0
                                return (Attributes & ParameterAttributes.Lcid) != 0;
-#else
-                               return (AttrsImpl & ParameterAttributes.Lcid) != 0;
-#endif
                        }
                }
 
                public bool IsOptional {
                        get {
-#if NET_2_0
                                return (Attributes & ParameterAttributes.Optional) != 0;
-#else
-                               return (AttrsImpl & ParameterAttributes.Optional) != 0;
-#endif
                        }
                }
 
                public bool IsOut {
                        get {
-#if NET_2_0
                                return (Attributes & ParameterAttributes.Out) != 0;
-#else
-                               return (AttrsImpl & ParameterAttributes.Out) != 0;
-#endif
                        }
                }
 
                public bool IsRetval {
                        get {
-#if NET_2_0
                                return (Attributes & ParameterAttributes.Retval) != 0;
-#else
-                               return (AttrsImpl & ParameterAttributes.Retval) != 0;
-#endif
                        }
                }
 
@@ -164,14 +181,23 @@ namespace System.Reflection
                        get {return PositionImpl;}
                }
 
-#if NET_2_0 || BOOTSTRAP_NET_2_0
-               public
-#else
-               internal
-#endif
-               extern int MetadataToken {
-                       [MethodImplAttribute (MethodImplOptions.InternalCall)]
-                       get;
+               [MethodImplAttribute (MethodImplOptions.InternalCall)]
+               extern int GetMetadataToken ();
+
+               public int MetadataToken {
+                       get {
+                               if (MemberImpl is PropertyInfo) {
+                                       PropertyInfo prop = (PropertyInfo)MemberImpl;
+                                       MethodInfo mi = prop.GetGetMethod (true);
+                                       if (mi == null)
+                                               mi = prop.GetSetMethod (true);
+                                       /*TODO expose and use a GetParametersNoCopy()*/
+                                       return mi.GetParameters () [PositionImpl].MetadataToken;
+                               } else if (MemberImpl is MethodBase) {
+                                       return GetMetadataToken ();
+                               }
+                               throw new ArgumentException ("Can't produce MetadataToken for member of type " + MemberImpl.GetType ());
+                       }
                }
 
                public virtual object[] GetCustomAttributes (bool inherit)
@@ -218,8 +244,6 @@ namespace System.Reflection
                        return attrs;
                }                       
 
-#if NET_2_0 || BOOTSTRAP_NET_2_0
-
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
                extern Type[] GetTypeModifiers (bool optional);
 
@@ -237,15 +261,19 @@ namespace System.Reflection
                        return types;
                }
 
-               [MonoTODO]
                public virtual object RawDefaultValue {
                        get {
-                               throw new NotImplementedException ();
+                               /*FIXME right now DefaultValue doesn't throw for reflection-only assemblies. Change this once the former is fixed.*/
+                               return DefaultValue;
                        }
                }
+
+#if NET_4_0
+               public virtual IList<CustomAttributeData> GetCustomAttributesData () {
+                       return CustomAttributeData.GetCustomAttributes (this);
+               }
 #endif
 
-#if NET_1_1
                void _ParameterInfo.GetIDsOfNames ([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
                {
                        throw new NotImplementedException ();
@@ -266,6 +294,5 @@ namespace System.Reflection
                {
                        throw new NotImplementedException ();
                }
-#endif
        }
 }