Ejemplo n.º 1
0
        private void DecodeSignature()
        {
            var   propertyDef    = module.metadata.GetPropertyDefinition(propertyHandle);
            var   genericContext = new GenericContext(DeclaringType.TypeParameters);
            IType returnType;

            IParameter[] parameters;
            try
            {
                var signature   = propertyDef.DecodeSignature(module.TypeProvider, genericContext);
                var accessors   = propertyDef.GetAccessors();
                var declTypeDef = this.DeclaringTypeDefinition;
                ParameterHandleCollection?parameterHandles;
                Nullability nullableContext;
                if (!accessors.Getter.IsNil)
                {
                    var getter = module.metadata.GetMethodDefinition(accessors.Getter);
                    parameterHandles = getter.GetParameters();
                    nullableContext  = getter.GetCustomAttributes().GetNullableContext(module.metadata)
                                       ?? declTypeDef?.NullableContext ?? Nullability.Oblivious;
                }
                else if (!accessors.Setter.IsNil)
                {
                    var setter = module.metadata.GetMethodDefinition(accessors.Setter);
                    parameterHandles = setter.GetParameters();
                    nullableContext  = setter.GetCustomAttributes().GetNullableContext(module.metadata)
                                       ?? declTypeDef?.NullableContext ?? Nullability.Oblivious;
                }
                else
                {
                    parameterHandles = null;
                    nullableContext  = declTypeDef?.NullableContext ?? Nullability.Oblivious;
                }
                // We call OptionsForEntity() for the declaring type, not the property itself,
                // because the property's accessibilty isn't stored in metadata but computed.
                // Otherwise we'd get infinite recursion, because computing the accessibility
                // requires decoding the signature for the GetBaseMembers() call.
                // Roslyn uses the same workaround (see the NullableTypeDecoder.TransformType
                // call in PEPropertySymbol).
                var typeOptions = module.OptionsForEntity(declTypeDef);
                (returnType, parameters, _) = MetadataMethod.DecodeSignature(
                    module, this, signature,
                    parameterHandles, nullableContext, typeOptions,
                    returnTypeAttributes: propertyDef.GetCustomAttributes());
            }
            catch (BadImageFormatException)
            {
                returnType = SpecialType.UnknownType;
                parameters = Empty <IParameter> .Array;
            }
            LazyInit.GetOrSet(ref this.returnType, returnType);
            LazyInit.GetOrSet(ref this.parameters, parameters);
        }
Ejemplo n.º 2
0
        private void DecodeSignature()
        {
            var   methodDef      = module.metadata.GetMethodDefinition(handle);
            var   genericContext = new GenericContext(DeclaringType.TypeParameters, this.TypeParameters);
            IType returnType;

            IParameter[] parameters;
            ModifiedType mod;

            try {
                var nullableContext = methodDef.GetCustomAttributes().GetNullableContext(module.metadata) ?? DeclaringTypeDefinition.NullableContext;
                var signature       = methodDef.DecodeSignature(module.TypeProvider, genericContext);
                (returnType, parameters, mod) = DecodeSignature(module, this, signature, methodDef.GetParameters(), nullableContext, module.OptionsForEntity(this));
            } catch (BadImageFormatException) {
                returnType = SpecialType.UnknownType;
                parameters = Empty <IParameter> .Array;
                mod        = null;
            }
            this.isInitOnly = mod is { Modifier : { Name : "IsExternalInit", Namespace : "System.Runtime.CompilerServices" } };
            LazyInit.GetOrSet(ref this.returnType, returnType);
            LazyInit.GetOrSet(ref this.parameters, parameters);
        }
Ejemplo n.º 3
0
        private IType DecodeTypeAndVolatileFlag()
        {
            var   metadata = module.metadata;
            var   fieldDef = metadata.GetFieldDefinition(handle);
            IType ty;

            try
            {
                ty = fieldDef.DecodeSignature(module.TypeProvider, new GenericContext(DeclaringType?.TypeParameters));
                if (ty is ModifiedType mod && mod.Modifier.Name == "IsVolatile" && mod.Modifier.Namespace == "System.Runtime.CompilerServices")
                {
                    Volatile.Write(ref this.isVolatile, true);
                    ty = mod.ElementType;
                }
                ty = ApplyAttributeTypeVisitor.ApplyAttributesToType(ty, Compilation,
                                                                     fieldDef.GetCustomAttributes(), metadata, module.OptionsForEntity(this),
                                                                     DeclaringTypeDefinition?.NullableContext ?? Nullability.Oblivious);
            }
            catch (BadImageFormatException)
            {
                ty = SpecialType.UnknownType;
            }
            return(LazyInit.GetOrSet(ref this.type, ty));
        }
Ejemplo n.º 4
0
        private void DecodeSignature()
        {
            var   methodDef      = module.metadata.GetMethodDefinition(handle);
            var   genericContext = new GenericContext(DeclaringType.TypeParameters, this.TypeParameters);
            IType returnType;

            IParameter[] parameters;
            try {
                var nullableContext = methodDef.GetCustomAttributes().GetNullableContext(module.metadata) ?? DeclaringTypeDefinition.NullableContext;
                var signature       = methodDef.DecodeSignature(module.TypeProvider, genericContext);
                (returnType, parameters) = DecodeSignature(module, this, signature, methodDef.GetParameters(), nullableContext, module.OptionsForEntity(this));
            } catch (BadImageFormatException) {
                returnType = SpecialType.UnknownType;
                parameters = Empty <IParameter> .Array;
            }
            LazyInit.GetOrSet(ref this.returnType, returnType);
            LazyInit.GetOrSet(ref this.parameters, parameters);
        }