Example #1
0
        // The only purpose of this method is to get type name of the method and declaring type token (opaque for SymWriter), everything else is ignored by the SymWriter.
        // "mb" is the token passed to OpenMethod. The token is remembered until the corresponding CloseMethod, which passes it to GetMethodProps.
        // It's opaque for SymWriter.
        public override int GetMethodProps(
            int methodDef,
            [Out] int *declaringTypeDef,
            [Out] char *name,
            int nameBufferLength,
            [Out] int *nameLength,
            [Out] MethodAttributes *attributes,
            [Out] byte **signature,
            [Out] int *signatureLength,
            [Out] int *relativeVirtualAddress,
            [Out] MethodImplAttributes *implAttributes)
        {
            Debug.Assert(attributes == null);
            Debug.Assert(signature == null);
            Debug.Assert(signatureLength == null);
            Debug.Assert(relativeVirtualAddress == null);
            Debug.Assert(implAttributes == null);

            if (!_metadataProvider.TryGetMethodInfo(methodDef, out var nameStr, out var declaringTypeToken))
            {
                return(HResult.E_INVALIDARG);
            }

            if (name != null || nameLength != null)
            {
                // if the buffer is too small to fit the name, truncate the name.
                // -1 to account for a NUL terminator.
                int adjustedLength = Math.Min(nameStr.Length, nameBufferLength - 1);

                if (nameLength != null)
                {
                    // return the length of the possibly truncated name not including NUL
                    *nameLength = adjustedLength;
                }

                if (name != null && nameBufferLength > 0)
                {
                    char *dst = name;

                    for (int i = 0; i < adjustedLength; i++)
                    {
                        *dst = nameStr[i];
                        dst++;
                    }

                    *dst = '\0';
                }
            }

            if (declaringTypeDef != null)
            {
                *declaringTypeDef = declaringTypeToken;
            }

            return(HResult.S_OK);
        }
Example #2
0
 public virtual int GetMethodProps(
     int methodDef,
     [Out] int *declaringTypeDef,
     [Out] char *name,
     int nameBufferLength,
     [Out] int *nameLength,
     [Out] MethodAttributes *attributes,
     [Out] byte **signature,
     [Out] int *signatureLength,
     [Out] int *relativeVirtualAddress,
     [Out] MethodImplAttributes *implAttributes)
 => throw new NotImplementedException();
Example #3
0
        // The only purpose of this method is to get type name of the method and declaring type token (opaque for SymWriter), everything else is ignored by the SymWriter.
        // "mb" is the token passed to OpenMethod. The token is remembered until the corresponding CloseMethod, which passes it to GetMethodProps.
        // It's opaque for SymWriter.
        int IMetadataImport.GetMethodProps(
            int methodDef,
            [Out] int *declaringTypeDef,
            [Out] char *name,
            int nameBufferLength,
            [Out] int *nameLength,
            [Out] MethodAttributes *attributes,
            [Out] byte **signature,
            [Out] int *signatureLength,
            [Out] int *relativeVirtualAddress,
            [Out] MethodImplAttributes *implAttributes)
        {
            MetadataRequired();

            Debug.Assert(attributes == null);
            Debug.Assert(signature == null);
            Debug.Assert(signatureLength == null);
            Debug.Assert(relativeVirtualAddress == null);
            Debug.Assert(implAttributes == null);

            var handle           = (MethodDefinitionHandle)MetadataTokens.Handle(methodDef);
            var methodDefinition = _metadataReaderOpt.GetMethodDefinition(handle);

            if (name != null || nameLength != null)
            {
                string nameStr = _metadataReaderOpt.GetString(methodDefinition.Name);

                // if the buffer is too small to fit the name, truncate the name.
                // -1 to account for a NUL terminator.
                int adjustedLength = Math.Min(nameStr.Length, nameBufferLength - 1);

                // return the length of the name not including NUL
                if (nameLength != null)
                {
                    *nameLength = adjustedLength;
                }

                if (name != null)
                {
                    InteropUtilities.StringCopy(name, nameStr, adjustedLength);
                }
            }

            if (declaringTypeDef != null)
            {
                *declaringTypeDef = MetadataTokens.GetToken(methodDefinition.GetDeclaringType());
            }

            return(HResult.S_OK);
        }