/// <summary> /// Gets the hash code of a method or constructor /// </summary> /// <param name="a">Method or constructor</param> /// <returns></returns> public int GetHashCode(DmdMethodBase a) { if ((object)a == null) { return(0); } int hc = MemberNameGetHashCode(a.Name); hc ^= GetHashCode(a.GetMethodSignature()); if (CompareDeclaringType) { hc ^= GetHashCode(a.DeclaringType); } return(hc); }
static IList <DmdType> GetGenericArguments(DmdMethodBase method) { if (method.GetMethodSignature().GenericParameterCount == 0) { return(Array.Empty <DmdType>()); } if (!method.IsMetadataReference) { return(method.GetGenericArguments()); } var resolvedMethod = method.ResolveMethodBaseNoThrow(); if ((object)resolvedMethod != null) { return(resolvedMethod.GetGenericArguments()); } return(Array.Empty <DmdType>()); }
void Write(DmdMethodBase method) => WriteMethod(method.Name, method.GetMethodSignature(), GetGenericArguments(method), isMethod: true);
string FormatCore(DmdMethodBase method) { Write(method); return(writer.ToString()); }
public static string Format(DmdMethodBase method, bool serializable = false) { using (var formatter = new DmdMemberFormatter(serializable ? GlobalFlags.Serializable : GlobalFlags.None)) return(formatter.FormatCore(method)); }
/// <summary> /// Executes a method /// </summary> /// <param name="context">Evaluation context</param> /// <param name="method">Method to call</param> /// <param name="obj">Instance object or null if it's a static method</param> /// <param name="parameters">Parameters passed to the method</param> /// <returns></returns> public abstract object Invoke(object context, DmdMethodBase method, object obj, object[] parameters);
/// <summary> /// Makes a generic method parameter /// </summary> /// <param name="position">Position</param> /// <param name="declaringMethod">Declaring method</param> /// <param name="name">Name</param> /// <param name="attributes">Attributes</param> /// <param name="customModifiers">Custom modifiers or null</param> /// <param name="options">Options</param> /// <returns></returns> public abstract DmdType MakeGenericMethodParameter(int position, DmdMethodBase declaringMethod, string name, DmdGenericParameterAttributes attributes, IList <DmdCustomModifier> customModifiers, DmdMakeTypeOptions options = DmdMakeTypeOptions.None);
/// <summary> /// Makes a generic method parameter /// </summary> /// <param name="position">Position</param> /// <param name="declaringMethod">Declaring method</param> /// <returns></returns> public DmdType MakeGenericMethodParameter(int position, DmdMethodBase declaringMethod) => MakeGenericMethodParameter(position, declaringMethod, string.Empty, 0, null);
/// <summary> /// Executes a method /// </summary> /// <param name="context">Evaluation context</param> /// <param name="method">Method to call</param> /// <param name="obj">Instance object or null if it's a constructor or a static method</param> /// <param name="parameters">Parameters passed to the method</param> /// <param name="callback">Notified when the method is complete</param> public abstract void Invoke(object context, DmdMethodBase method, object obj, object[] parameters, Action <object> callback);
/// <summary> /// Executes a method /// </summary> /// <param name="context">Evaluation context</param> /// <param name="method">Method to call</param> /// <param name="obj">Instance object or null if it's a static method</param> /// <param name="parameters">Parameters passed to the method</param> /// <returns></returns> public abstract object?Invoke(object?context, DmdMethodBase method, object?obj, object?[]?parameters);
/// <summary> /// Constructor /// </summary> /// <param name="method">Method that couldn't be resolved</param> public MethodResolveException(DmdMethodBase method) : base("Couldn't resolve method: " + method.ToString() + ", type: " + method.DeclaringType !.ToString()) => Method = method;