@@ -42,6 +42,12 @@ module CoreClrUtilities
4242 cl.Split( ' ' )
4343#endif
4444
45+ let commit ( results : _ []) =
46+ match resultswith
47+ | [||] -> null
48+ | [| m|] -> m
49+ | _ -> raise( AmbiguousMatchException())
50+
4551[<Flags>]
4652type BindingFlags =
4753| DeclaredOnly= 2
@@ -76,17 +82,45 @@ module CoreClrUtilities
7682| :? System.Reflection.TypeInfoas c-> if c.IsNestedthen MemberType.NestedTypeelse MemberType.TypeInfo
7783|_ -> MemberType.None
7884 mapIsMethodOrConstructor||| mapIsEvent||| mapIsField||| mapIsProperty||| mapIsTypeInfoOrNested
85+
7986
87+ let inline hasFlag ( flag : BindingFlags ) f = ( f&&& flag) = flag
88+ let isDeclaredFlag f = hasFlag BindingFlags.DeclaredOnly f
89+ let isPublicFlag f = hasFlag BindingFlags.Public f
90+ let isStaticFlag f = hasFlag BindingFlags.Static f
91+ let isInstanceFlag f = hasFlag BindingFlags.Instance f
92+ let isNonPublicFlag f = hasFlag BindingFlags.NonPublic f
93+
94+ let isAcceptable bindingFlags isStatic isPublic =
95+ // 1. check if member kind (static\instance) was specified in flags
96+ (( isStaticFlag bindingFlags&& isStatic) || ( isInstanceFlag bindingFlags&& not isStatic)) &&
97+ // 2. check if member accessibility was specified in flags
98+ (( isPublicFlag bindingFlags&& isPublic) || ( isNonPublicFlag bindingFlags&& not isPublic))
99+
100+ let publicFlags = BindingFlags.Public||| BindingFlags.Instance||| BindingFlags.Static
101+
102+
80103type System.Reflection.MemberInfo with
104+ member this.GetCustomAttributes ( inherits : bool ) : obj [] = downcast box( CustomAttributeExtensions.GetCustomAttributes( this, inherits) |> Seq.toArray)
105+ member this.GetCustomAttributes ( attrTy : Type ) : obj [] = downcast box( CustomAttributeExtensions.GetCustomAttributes( this, attrTy) |> Seq.toArray)
106+ member this.GetCustomAttributes ( attrTy , inherits ) : obj [] = downcast box( CustomAttributeExtensions.GetCustomAttributes( this, attrTy, inherits) |> Seq.toArray)
81107member this.MemberType = mapMemberType this
82108
83109type System.Reflection.MethodInfo with
110+ member this.GetCustomAttributes ( inherits : bool ) : obj [] = downcast box( CustomAttributeExtensions.GetCustomAttributes( this, inherits) |> Seq.toArray)
111+ member this.GetCustomAttributes ( attrTy : Type ) : obj [] = downcast box( CustomAttributeExtensions.GetCustomAttributes( this, attrTy) |> Seq.toArray)
112+ member this.GetCustomAttributes ( attrTy , inherits ) : obj [] = downcast box( CustomAttributeExtensions.GetCustomAttributes( this, attrTy, inherits) |> Seq.toArray)
84113member this.MemberType = mapMemberType this
85114
86115type System.Reflection.PropertyInfo with
116+ member this.GetCustomAttributes ( inherits : bool ) : obj [] = downcast box( CustomAttributeExtensions.GetCustomAttributes( this, inherits) |> Seq.toArray)
117+ member this.GetCustomAttributes ( attrTy : Type ) : obj [] = downcast box( CustomAttributeExtensions.GetCustomAttributes( this, attrTy) |> Seq.toArray)
118+ member this.GetCustomAttributes ( attrTy , inherits ) : obj [] = downcast box( CustomAttributeExtensions.GetCustomAttributes( this, attrTy, inherits) |> Seq.toArray)
87119member this.MemberType = mapMemberType this
88120
89121type System.Reflection.Assembly with
122+ member this.GetCustomAttributes () : obj [] = downcast box( CustomAttributeExtensions.GetCustomAttributes( this) |> Seq.toArray)
123+ member this.GetCustomAttributes ( attrTy , _inherits ) : obj [] = downcast box( CustomAttributeExtensions.GetCustomAttributes( this, attrTy) |> Seq.toArray)
90124member this.GetTypes () =
91125 this.DefinedTypes
92126|> Seq.map( fun ti -> ti.AsType())
@@ -97,3 +131,50 @@ module CoreClrUtilities
97131with get() = System.Globalization.CultureInfo.CurrentCulture
98132and set culture = System.Globalization.CultureInfo.CurrentCulture<- culture
99133
134+ type System.Type with
135+
136+ member this.Assembly = this.GetTypeInfo() .Assembly
137+ // use different sources based on Declared flag
138+ member this.GetConstructor ( _bindingFlags , _binder , argsT : Type [], _parameterModifiers ) = this.GetConstructor( argsT)
139+ member this.GetConstructor ( parameterTypes : Type []) =
140+ this.GetTypeInfo() .DeclaredConstructors
141+ |> Seq.filter( fun ci ->
142+ not ci.IsStatic&& //exclude type initializer
143+ (
144+ let parameters = ci.GetParameters()
145+ ( parameters.Length= parameterTypes.Length) &&
146+ ( parameterTypes, parameters) ||> Array.forall2( fun ty pi -> pi.ParameterType.Equals ty)
147+ )
148+ )
149+ |> Seq.toArray
150+ |> commit
151+ member this.GetCustomAttributes ( attrTy , inherits ) : obj [] = downcast box( CustomAttributeExtensions.GetCustomAttributes( this.GetTypeInfo(), attrTy, inherits) |> Seq.toArray)
152+ member this.GetGenericParameterConstraints () = this.GetTypeInfo() .GetGenericParameterConstraints()
153+ member this.GetMethods ( bindingFlags ) =
154+ ( if isDeclaredFlag bindingFlagsthen this.GetTypeInfo() .DeclaredMethodselse this.GetRuntimeMethods())
155+ |> Seq.filter( fun m -> isAcceptable bindingFlags m.IsStatic m.IsPublic)
156+ |> Seq.toArray
157+ member this.GetMethods () = this.GetMethods( publicFlags)
158+ member this.GetMethod ( name , ? bindingFlags ) =
159+ let bindingFlags = defaultArg bindingFlags publicFlags
160+ this.GetMethods( bindingFlags)
161+ |> Array.filter( fun m -> m.Name= name)
162+ |> commit
163+ member this.GetMethod ( name , _bindingFlags , _binder , argsT : Type [], _parameterModifiers ) =
164+ this.GetMethod( name, argsT)
165+ member this.GetProperties (? bindingFlags ) =
166+ let bindingFlags = defaultArg bindingFlags publicFlags
167+ ( if isDeclaredFlag bindingFlagsthen this.GetTypeInfo() .DeclaredPropertieselse this.GetRuntimeProperties())
168+ |> Seq.filter( fun pi ->
169+ let mi = match pi.GetMethodwith | null -> pi.SetMethod| _ -> pi.GetMethod
170+ if mi= null then false
171+ else isAcceptable bindingFlags mi.IsStatic mi.IsPublic
172+ )
173+ |> Seq.toArray
174+ member this.GetProperty ( name , ? bindingFlags ) =
175+ let bindingFlags = defaultArg bindingFlags publicFlags
176+ this.GetProperties( bindingFlags)
177+ |> Array.filter( fun pi -> pi.Name= name)
178+ |> commit
179+ member this.IsGenericType = this.GetTypeInfo() .IsGenericType
180+ member this.IsValueType = this.GetTypeInfo() .IsValueType