1 // -----------------------------------------------------------------------
\r
2 // Copyright (c) Microsoft Corporation. All rights reserved.
\r
3 // -----------------------------------------------------------------------
\r
5 using System.ComponentModel.Composition.Hosting;
\r
6 using System.Reflection;
\r
7 using Microsoft.Internal;
\r
8 using System.Threading;
\r
9 using System.ComponentModel.Composition.Primitives;
\r
11 namespace System.ComponentModel.Composition.ReflectionModel
\r
13 internal partial class ReflectionMethod : ReflectionMember
\r
15 private readonly MethodInfo _method;
\r
17 public ReflectionMethod(MethodInfo method)
\r
19 Assumes.NotNull(method);
\r
21 this._method = method;
\r
24 public MethodInfo UnderlyingMethod
\r
26 get { return this._method; }
\r
29 public override MemberInfo UnderlyingMember
\r
31 get { return this.UnderlyingMethod; }
\r
34 public override bool CanRead
\r
36 get { return true; }
\r
39 public override bool RequiresInstance
\r
41 get { return !this.UnderlyingMethod.IsStatic; }
\r
44 public override Type ReturnType
\r
46 get { return this.UnderlyingMethod.ReturnType; }
\r
49 public override ReflectionItemType ItemType
\r
51 get { return ReflectionItemType.Method; }
\r
54 public override object GetValue(object instance)
\r
56 return SafeCreateExportedDelegate(instance, _method);
\r
59 [System.Security.SecuritySafeCritical]
\r
61 private static ExportedDelegate SafeCreateExportedDelegate(object instance, MethodInfo method)
\r
63 // We demand member access in place of the [SecurityCritical]
\r
64 // attribute on ExportDelegate constructor
\r
65 ReflectionInvoke.DemandMemberAccessIfNeeded(method);
\r
67 return new ExportedDelegate(instance, method);
\r