void WriteMethod(string name, DmdMethodSignature sig, IList <DmdType> genericArguments, bool isMethod) { var flags = GetTypeFlags(true) | TypeFlags.FnPtrIsIntPtr; FormatTypeName(sig.ReturnType, flags); writer.Append(' '); writer.Append(name); if (genericArguments != null) { WriteMethodGenericArguments(genericArguments, flags); } if (isMethod || sig.GetParameterTypes().Count != 0 || sig.GetVarArgsParameterTypes().Count != 0) { if (!isMethod) { writer.Append(' '); } writer.Append(isMethod ? '(' : '['); WriteParameters(sig.GetParameterTypes(), flags); if ((sig.Flags & DmdSignatureCallingConvention.Mask) == DmdSignatureCallingConvention.VarArg) { if (sig.GetParameterTypes().Count > 0) { writer.Append(", "); } writer.Append("..."); } writer.Append(isMethod ? ')' : ']'); } }
/// <summary> /// Gets the hash code of a method signature /// </summary> /// <param name="a">Method signature</param> /// <returns></returns> public int GetHashCode(DmdMethodSignature a) { if ((object)a == null) { return(0); } int hc = (int)a.Flags; hc ^= a.GenericParameterCount; if (!DontCompareReturnType) { hc ^= GetHashCode(a.ReturnType); } hc ^= GetHashCode(a.GetParameterTypes()); hc ^= GetHashCode(a.GetVarArgsParameterTypes()); return(hc); }
/// <summary> /// Compares two method signatures /// </summary> /// <param name="a">First method signature</param> /// <param name="b">Second method signature</param> /// <returns></returns> public bool Equals(DmdMethodSignature a, DmdMethodSignature b) { if ((object)a == b) { return(true); } if ((object)a == null || (object)b == null) { return(false); } return(a.Flags == b.Flags && a.GenericParameterCount == b.GenericParameterCount && (DontCompareReturnType || Equals(a.ReturnType, b.ReturnType)) && Equals(a.GetParameterTypes(), b.GetParameterTypes()) && Equals(a.GetVarArgsParameterTypes(), b.GetVarArgsParameterTypes())); }
void Write(DmdMethodSignature methodSignature) => WriteMethod(null, methodSignature, genericArguments: null, isMethod: true);
string FormatCore(DmdMethodSignature methodSignature) { Write(methodSignature); return(writer.ToString()); }
public static string Format(DmdMethodSignature methodSignature, bool serializable = false) { using (var formatter = new DmdMemberFormatter(serializable ? GlobalFlags.Serializable : GlobalFlags.None)) return(formatter.FormatCore(methodSignature)); }
/// <summary> /// Makes a function pointer type /// </summary> /// <param name="methodSignature">Method signature</param> /// <param name="customModifiers">Custom modifiers or null</param> /// <param name="options">Options</param> /// <returns></returns> public abstract DmdType MakeFunctionPointerType(DmdMethodSignature methodSignature, IList <DmdCustomModifier> customModifiers, DmdMakeTypeOptions options = DmdMakeTypeOptions.None);