コード例 #1
0
        protected sealed override Guid?ComputeGuidFromCustomAttributes()
        {
            //
            // Look for a [Guid] attribute. If found, return that.
            //
            foreach (CustomAttributeHandle cah in _typeDefinition.CustomAttributes)
            {
                // We can't reference the GuidAttribute class directly as we don't have an official dependency on System.Runtime.InteropServices.
                // Following age-old CLR tradition, we search for the custom attribute using a name-based search. Since this makes it harder
                // to be sure we won't run into custom attribute constructors that comply with the GuidAttribute(String) signature,
                // we'll check that it does and silently skip the CA if it doesn't match the expected pattern.
                if (cah.IsCustomAttributeOfType(_reader, "System.Runtime.InteropServices", "GuidAttribute"))
                {
                    CustomAttribute             ca            = cah.GetCustomAttribute(_reader);
                    HandleCollection.Enumerator fahEnumerator = ca.FixedArguments.GetEnumerator();
                    if (!fahEnumerator.MoveNext())
                    {
                        continue;
                    }
                    Handle guidStringArgumentHandle = fahEnumerator.Current;
                    if (fahEnumerator.MoveNext())
                    {
                        continue;
                    }
                    if (!(guidStringArgumentHandle.ParseConstantValue(_reader) is string guidString))
                    {
                        continue;
                    }
                    return(new Guid(guidString));
                }
            }

            return(null);
        }
コード例 #2
0
        public IntPtrConstructorMethodInvoker(MetadataReader reader, MethodHandle methodHandle)
        {
            // Since we control the definition of System.IntPtr, we only do enough analysis of the signature to disambiguate the constructors we support.
            _id = IntPtrConstructorId.None;
            Method           method = methodHandle.GetMethod(reader);
            HandleCollection parameterTypeSignatureHandles = method.Signature.GetMethodSignature(reader).Parameters;

            if (parameterTypeSignatureHandles.Count == 1)
            {
                HandleCollection.Enumerator enumerator = parameterTypeSignatureHandles.GetEnumerator();
                enumerator.MoveNext();
                Handle parameterTypeHandle = enumerator.Current;

                // If any parameter is a pointer type, bail as we don't support Invokes on pointers.
                if (parameterTypeHandle.HandleType != HandleType.TypeDefinition)
                {
                    throw new PlatformNotSupportedException(SR.PlatformNotSupported_PointerArguments);
                }

                TypeDefinition typeDefinition = parameterTypeHandle.ToTypeDefinitionHandle(reader).GetTypeDefinition(reader);
                String         name           = typeDefinition.Name.GetString(reader);
                switch (name)
                {
                case "Int32":
                    _id = IntPtrConstructorId.Int32;
                    break;

                case "Int64":
                    _id = IntPtrConstructorId.Int64;
                    break;

                case "UInt32":
                    _id = IntPtrConstructorId.UInt32;
                    break;

                case "UInt64":
                    _id = IntPtrConstructorId.UInt64;
                    break;

                default:
                    break;
                }
            }
        }