本文整理汇总了C#中System.Reflection.MethodInfo.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# MethodInfo.Equals方法的具体用法?C# MethodInfo.Equals怎么用?C# MethodInfo.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MethodInfo
的用法示例。
在下文中一共展示了MethodInfo.Equals方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AreMethodEquals
/// <summary>
/// The are method equals.
/// </summary>
/// <param name="left">
/// The left.
/// </param>
/// <param name="right">
/// The right.
/// </param>
/// <returns>
/// The are method equals.
/// </returns>
private static bool AreMethodEquals(MethodInfo left, MethodInfo right)
{
if (left.Equals(right))
return true;
// GetHashCode calls to RuntimeMethodHandle.StripMethodInstantiation()
// which is needed to fix issues with method equality from generic types.
if (left.GetHashCode() != right.GetHashCode())
return false;
if (left.DeclaringType != right.DeclaringType)
return false;
ParameterInfo[] leftParams = left.GetParameters();
ParameterInfo[] rightParams = right.GetParameters();
if (leftParams.Length != rightParams.Length)
return false;
for (int i = 0; i < leftParams.Length; i++)
{
if (leftParams[i].ParameterType != rightParams[i].ParameterType)
return false;
}
if (left.ReturnType != right.ReturnType)
return false;
return true;
}
示例2: Invoke
/// <summary>
/// Invokes the method if this is something that the LazyInitializer can handle
/// without the underlying proxied object being instantiated.
/// </summary>
/// <param name="method">The name of the method/property to Invoke.</param>
/// <param name="args">The arguments to pass the method/property.</param>
/// <param name="proxy">The proxy object that the method is being invoked on.</param>
/// <returns>
/// The result of the Invoke if the underlying proxied object is not needed. If the
/// underlying proxied object is needed then it returns the result <see cref="AbstractLazyInitializer.InvokeImplementation"/>
/// which indicates that the Proxy will need to forward to the real implementation.
/// </returns>
public virtual object Invoke(MethodInfo method, object[] args, object proxy)
{
string methodName = method.Name;
int paramCount = method.GetParameters().Length;
if (paramCount == 0)
{
if (!overridesEquals && methodName == "GetHashCode")
{
return IdentityEqualityComparer.GetHashCode(proxy);
}
else if (IsUninitialized && IsEqualToIdentifierMethod(method))
{
return Identifier;
}
else if (methodName == "Dispose")
{
return null;
}
else if ("get_HibernateLazyInitializer".Equals(methodName))
{
return this;
}
}
else if (paramCount == 1)
{
if (!overridesEquals && methodName == "Equals")
{
return IdentityEqualityComparer.Equals(args[0], proxy);
}
else if (setIdentifierMethod!=null&&method.Equals(setIdentifierMethod))
{
Initialize();
Identifier = args[0];
return InvokeImplementation;
}
}
else if (paramCount == 2)
{
// if the Proxy Engine delegates the call of GetObjectData to the Initializer
// then we need to handle it. Castle.DynamicProxy takes care of serializing
// proxies for us, but other providers might not.
if (methodName == "GetObjectData")
{
SerializationInfo info = (SerializationInfo)args[0];
StreamingContext context = (StreamingContext)args[1]; // not used !?!
if (Target == null & Session != null)
{
EntityKey key = Session.GenerateEntityKey(Identifier, Session.Factory.GetEntityPersister(EntityName));
object entity = Session.PersistenceContext.GetEntity(key);
if (entity != null)
SetImplementation(entity);
}
// let the specific ILazyInitializer write its requirements for deserialization
// into the stream.
AddSerializationInfo(info, context);
// don't need a return value for proxy.
return null;
}
}
//if it is a property of an embedded component, invoke on the "identifier"
if (componentIdType != null && componentIdType.IsMethodOf(method))
{
return method.Invoke(Identifier, args);
}
return InvokeImplementation;
}
示例3: CheckMethod
private static bool CheckMethod(MethodInfo method, MethodInfo propertyMethod)
{
if (method.Equals(propertyMethod))
{
return true;
}
// If the type is an interface then the handle for the method got by the compiler will not be the
// same as that returned by reflection.
// Check for this condition and try and get the method from reflection.
Type type = method.DeclaringType;
if (type.IsInterface && method.Name == propertyMethod.Name && type.GetMethod(method.Name) == propertyMethod)
{
return true;
}
return false;
}
示例4: IsMethodOverride
public static bool IsMethodOverride(MethodInfo method)
{
var type = method.DeclaringType;
var baseMethod = method.GetBaseDefinition();
return (baseMethod != null) && (!method.Equals(baseMethod));
}
示例5: IsImplementationOfInterfaceMethod
static bool IsImplementationOfInterfaceMethod(MethodInfo method, Type interfaceType, string methodName)
{
if (!interfaceType.IsAssignableFrom(method.DeclaringType)) {
return false;
}
var interfaceMap = method.DeclaringType.GetInterfaceMap(interfaceType);
return
interfaceMap.InterfaceMethods.Where((t, i) => t.Name == methodName && method.Equals(interfaceMap.TargetMethods[i]))
.Any();
}
示例6: Invoke
public virtual object Invoke(object proxy, MethodInfo method, object[] args)
{
if (method.Equals(this.completeMethod))
{
int result = Complete((string)args[0], System.Convert.ToInt32(((int)args[1])), (IList<string>)args[2]);
return Sharpen.Extensions.ValueOf(result);
}
throw new MissingMethodException(method.ToString());
}