本文整理汇总了C#中System.Delegate.GetMethodInfo方法的典型用法代码示例。如果您正苦于以下问题:C# Delegate.GetMethodInfo方法的具体用法?C# Delegate.GetMethodInfo怎么用?C# Delegate.GetMethodInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Delegate
的用法示例。
在下文中一共展示了Delegate.GetMethodInfo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public static AsyncInvocationRegion Create(Delegate @delegate)
{
#if PORTABLE
return Create(@delegate.GetMethodInfo());
#else
return Create(@delegate.Method);
#endif
}
示例2: IsAsyncOperation
public static bool IsAsyncOperation(Delegate @delegate)
{
#if PORTABLE
return IsAsyncOperation(@delegate.GetMethodInfo());
#else
return IsAsyncOperation(@delegate.Method);
#endif
}
示例3: ClearCore
void IActionInvoker.ClearIfMatched(Delegate action, object recipient) {
object target = Target;
if(recipient != target)
return;
#if !NETFX_CORE
if(action != null && action.Method.Name != MethodName)
#else
if(action != null && action.GetMethodInfo().Name != MethodName)
#endif
return;
targetReference = null;
ClearCore();
}
示例4: IsMatch
/// <summary>
/// Returns a value indicating whether the current weak delegate is a match (equivalent) for the specified strong delegate.
/// </summary>
/// <param name="strongDelegate">The <see cref="Delegate">delegate</see> to evaluate.</param>
/// <returns>True if the current weak delegate is a match for the specified strong delegate; otherwise, false.</returns>
public virtual bool IsMatch( Delegate strongDelegate )
{
if ( strongDelegate == null )
return false;
if ( !object.Equals( strongDelegate.Target, Target ) )
return false;
if ( !strongDelegate.GetMethodInfo().Equals( method ) )
return false;
return true;
}
示例5: ScriptUserdataDelegate
public ScriptUserdataDelegate(Script script, Delegate value) : base(script) {
this.m_Delegate = value;
this.m_Value = value;
this.m_ValueType = value.GetType();
var method = m_Delegate.GetMethodInfo();
var infos = method.GetParameters();
var dynamicDelegate = method.Name.Equals(Script.DynamicDelegateName);
int length = dynamicDelegate ? infos.Length - 1 : infos.Length;
m_Objects = new object[length];
for (int i = 0; i < length; ++i) {
var p = infos[dynamicDelegate ? i + 1 : i];
m_Parameters.Add(new FunctionParameter(p.ParameterType, p.DefaultValue));
}
}
示例6: RegisterFunction
public void RegisterFunction(string functionName, Delegate function, bool isOverWritable)
{
if (string.IsNullOrEmpty(functionName))
throw new ArgumentNullException("functionName");
if (function == null)
throw new ArgumentNullException("function");
Type funcType = function.GetType();
if (!funcType.FullName.StartsWith("System.Func"))
throw new ArgumentException("Only System.Func delegates are permitted.", "function");
#if NETFX_CORE
foreach (Type genericArgument in funcType.GenericTypeArguments)
#else
foreach (Type genericArgument in funcType.GetGenericArguments())
#endif
if (genericArgument != typeof(double))
throw new ArgumentException("Only doubles are supported as function arguments", "function");
functionName = ConvertFunctionName(functionName);
if (functions.ContainsKey(functionName) && !functions[functionName].IsOverWritable)
{
string message = string.Format("The function \"{0}\" cannot be overwriten.", functionName);
throw new Exception(message);
}
#if NETFX_CORE
int numberOfParameters = function.GetMethodInfo().GetParameters().Length;
#else
int numberOfParameters = function.Method.GetParameters().Length;
#endif
if (functions.ContainsKey(functionName) && functions[functionName].NumberOfParameters != numberOfParameters)
{
string message = string.Format("The number of parameters cannot be changed when overwriting a method.");
throw new Exception(message);
}
FunctionInfo functionInfo = new FunctionInfo(functionName, numberOfParameters, isOverWritable, function);
if (functions.ContainsKey(functionName))
functions[functionName] = functionInfo;
else
functions.Add(functionName, functionInfo);
}
示例7: DelegateReference
/// <summary>
/// Initializes a new instance of <see cref="DelegateReference"/>.
/// </summary>
/// <param name="delegate">The original <see cref="Delegate"/> to create a reference for.</param>
/// <param name="keepReferenceAlive">If <see langword="false" /> the class will create a weak reference to the delegate, allowing it to be garbage collected. Otherwise it will keep a strong reference to the target.</param>
/// <exception cref="ArgumentNullException">If the passed <paramref name="delegate"/> is not assignable to <see cref="Delegate"/>.</exception>
public DelegateReference(Delegate @delegate, bool keepReferenceAlive)
{
if (@delegate == null)
throw new ArgumentNullException("delegate");
if (keepReferenceAlive)
{
this._delegate = @delegate;
}
else
{
_weakReference = new WeakReference(@delegate.Target);
_method = @delegate.GetMethodInfo();
_delegateType = @delegate.GetType();
}
}
示例8: SubscriberReference
public SubscriberReference(Delegate action)
{
if (action == null)
throw new ArgumentNullException("action");
// If the delegates target is null, we can't hold a reference to it.
// This happens when the callback method is static or a it has been
// created as a lambda/anonymous delegate that doesn't capture any
// instance variables. (Causes the compiler to generate a static method.)
if (action.Target == null)
throw new InvalidOperationException("Subscription with a static delegate method is not supported");
_weakReference = new WeakReference(action.Target);
_delegateType = action.GetType();
_delegateMethod = action.GetMethodInfo();
}
示例9: GetArguments
private object[] GetArguments(Delegate valueFactory) {
object[] arguments = new object[valueFactory.GetMethodInfo().GetParameters().Length];
IEnumerable<ImportDefinition> ctorImportDefinitions = ImportDefinitions.Where(ReflectionModelServices.IsImportingParameter);
foreach (ImportDefinition ctorImportDefinition in ctorImportDefinitions) {
ParameterInfo parameterInfo = ReflectionModelServices.GetImportingParameter(ctorImportDefinition).Value;
IEnumerable<Export> value;
if (_imports.TryGetValue(ctorImportDefinition, out value)) {
arguments[parameterInfo.Position] = value.Single().Value;
_imports.Remove(ctorImportDefinition);
} else {
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "There is no export for parameter of type {0}",
parameterInfo.ParameterType));
}
}
return arguments;
}
开发者ID:AlexanderSher,项目名称:RTVS-Old,代码行数:18,代码来源:CompositionBatchExtensions.FactoryReflectionComposablePart.cs
示例10: InternalWeakDelegate
//--------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the <see cref="InternalWeakDelegate"/> class.
/// </summary>
/// <param name="delegate">
/// The original <see cref="System.Delegate"/> to create a weak reference for.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="delegate"/> is <see langword="null"/>.
/// </exception>
public InternalWeakDelegate(Delegate @delegate)
{
if (@delegate == null)
throw new ArgumentNullException("delegate");
object target = @delegate.Target;
TargetReference = (target != null) ? new WeakReference(target) : null;
#if !NETFX_CORE && !NET45
MethodInfo = @delegate.Method;
#else
MethodInfo = @delegate.GetMethodInfo();
#endif
DelegateType = @delegate.GetType();
Debug.Assert(
(TargetReference != null && !MethodInfo.IsStatic)
|| (TargetReference == null && MethodInfo.IsStatic),
"Sanity check.");
CheckForClosure(MethodInfo);
CheckForNonPublicEventHandler(target, MethodInfo);
}
示例11: GetMethod
private static MethodInfo GetMethod(Delegate x)
{
return x.GetMethodInfo();
}
示例12: appendEventHandler
private void appendEventHandler(StringBuilder sb, String name, Delegate eh)
{
if (eh != null)
sb.AppendFormat("{0}={1};", name, eh.GetMethodInfo().Name);
else
sb.AppendFormat("{0}=null;", name);
}
示例13: WeakDelegate
/// <summary>
/// Initializes a new instance of <see cref="WeakDelegate"/>
/// </summary>
/// <param name="delegate"></param>
public WeakDelegate(Delegate @delegate)
{
_target = new WeakReference(@delegate.Target);
_method = @delegate.GetMethodInfo();
}
示例14: FromDelegate
/// <summary>
/// Creates a CallbackFunction from a delegate.
/// </summary>
/// <param name="script">The script.</param>
/// <param name="del">The delegate.</param>
/// <param name="accessMode">The access mode.</param>
/// <returns></returns>
public static CallbackFunction FromDelegate(Script script, Delegate del, InteropAccessMode accessMode = InteropAccessMode.Default)
{
if (accessMode == InteropAccessMode.Default)
accessMode = m_DefaultAccessMode;
#if NETFX_CORE
MethodMemberDescriptor descr = new MethodMemberDescriptor(del.GetMethodInfo(), accessMode);
#else
MethodMemberDescriptor descr = new MethodMemberDescriptor(del.Method, accessMode);
#endif
return descr.GetCallbackFunction(script, del.Target);
}
示例15: CallDelegate
/*!*/
internal static MSA.Expression CallDelegate(Delegate/*!*/ method, MSA.Expression[]/*!*/ arguments)
{
MethodInfo methodInfo = method.GetMethodInfo();
// We prefer to peek inside the delegate and call the target method directly. However, we need to
// exclude DynamicMethods since Delegate.Method returns a dummy MethodInfo, and we cannot emit a call to it.
if (methodInfo.DeclaringType == null || !methodInfo.DeclaringType.IsPublic() || !methodInfo.IsPublic) {
// do not inline:
return Ast.Call(AstUtils.Constant(method), method.GetType().GetMethod("Invoke"), arguments);
}
if (method.Target != null) {
// inline a closed static delegate:
if (methodInfo.IsStatic) {
return Ast.Call(null, method.GetMethodInfo(), ArrayUtils.Insert(AstUtils.Constant(method.Target), arguments));
}
// inline a closed instance delegate:
return Ast.Call(AstUtils.Constant(method.Target), methodInfo, arguments);
}
// inline an open static delegate:
if (methodInfo.IsStatic) {
return Ast.Call(null, methodInfo, arguments);
}
// inline an open instance delegate:
return Ast.Call(arguments[0], methodInfo, ArrayUtils.RemoveFirst(arguments));
}