public static EmbeddedSignatureData[] EncodeAsEmbeddedSignatureData(this UnmanagedCallingConventions callingConventions, TypeSystemContext context)
        {
            UnmanagedCallingConventions convention = (callingConventions & UnmanagedCallingConventions.CallingConventionMask);
            UnmanagedCallingConventions modifiers  = (callingConventions & UnmanagedCallingConventions.ModifiersMask);

            UnmanagedCallingConventions platformDefault = GetPlatformDefaultUnmanagedCallingConvention(context);

            int count = ((convention != platformDefault) ? 1 : 0) + BitOperations.PopCount((uint)modifiers);

            if (count == 0)
            {
                return(null);
            }

            EmbeddedSignatureData[] ret = new EmbeddedSignatureData[count];

            int index = 0;

            if (convention != platformDefault)
            {
                ret[index++] = CreateCallConvEmbeddedSignatureData(context, convention switch
                {
                    UnmanagedCallingConventions.Cdecl => "CallConvCdecl",
                    UnmanagedCallingConventions.Stdcall => "CallConvStdcall",
                    UnmanagedCallingConventions.Fastcall => "CallConvFastcall",
                    UnmanagedCallingConventions.Thiscall => "CallConvThiscall",
                    _ => throw new InvalidProgramException()
                });
Ejemplo n.º 2
0
        private bool Equals(MethodSignature otherSignature, bool allowCovariantReturn)
        {
            if (this._flags != otherSignature._flags)
            {
                return(false);
            }

            if (this._genericParameterCount != otherSignature._genericParameterCount)
            {
                return(false);
            }

            if (this._returnType != otherSignature._returnType)
            {
                if (!allowCovariantReturn)
                {
                    return(false);
                }

                if (!otherSignature._returnType.IsCompatibleWith(this._returnType))
                {
                    return(false);
                }
            }

            if (this._parameters.Length != otherSignature._parameters.Length)
            {
                return(false);
            }

            for (int i = 0; i < this._parameters.Length; i++)
            {
                if (this._parameters[i] != otherSignature._parameters[i])
                {
                    return(false);
                }
            }

            if (this._embeddedSignatureData == null && otherSignature._embeddedSignatureData == null)
            {
                return(true);
            }

            // Array methods do not need to have matching details for the array parameters they support
            if (this.EmbeddedSignatureMismatchPermitted ||
                otherSignature.EmbeddedSignatureMismatchPermitted)
            {
                return(true);
            }

            if (this._embeddedSignatureData != null && otherSignature._embeddedSignatureData != null)
            {
                if (this._embeddedSignatureData.Length != otherSignature._embeddedSignatureData.Length)
                {
                    return(false);
                }

                for (int i = 0; i < this._embeddedSignatureData.Length; i++)
                {
                    ref EmbeddedSignatureData thisData  = ref this._embeddedSignatureData[i];
                    ref EmbeddedSignatureData otherData = ref otherSignature._embeddedSignatureData[i];

                    if (thisData.index != otherData.index ||
                        thisData.kind != otherData.kind ||
                        thisData.type != otherData.type)
                    {
                        return(false);
                    }
                }