示例#1
0
文件: Property.cs 项目: denislevin/ql
 public Property(GenericContext gc, Type type, PropertyDefinitionHandle handle) : base(gc.Cx)
 {
     this.gc     = gc;
     this.handle = handle;
     pd          = Cx.MdReader.GetPropertyDefinition(handle);
     this.type   = type;
 }
示例#2
0
        public IProperty GetDefinition(PropertyDefinitionHandle handle)
        {
            if (handle.IsNil)
            {
                return(null);
            }
            if (propertyDefs == null)
            {
                return(new MetadataProperty(this, handle));
            }
            int row = MetadataTokens.GetRowNumber(handle);

            Debug.Assert(row != 0);
            if (row >= methodDefs.Length)
            {
                HandleOutOfRange(handle);
            }
            var property = LazyInit.VolatileRead(ref propertyDefs[row]);

            if (property != null)
            {
                return(property);
            }
            property = new MetadataProperty(this, handle);
            return(LazyInit.GetOrSet(ref propertyDefs[row], property));
        }
        internal override string Disassemble(IEntity entity)
        {
            PropertyDefinitionHandle handle = (PropertyDefinitionHandle)entity.MetadataToken;

            _reflectionDisassembler.DisassembleProperty(entity.ParentModule.PEFile, handle);
            return(_textOutput.ToString());
        }
示例#4
0
        internal MetadataProperty(MetadataModule module, PropertyDefinitionHandle handle)
        {
            Debug.Assert(module != null);
            Debug.Assert(!handle.IsNil);
            this.module         = module;
            this.propertyHandle = handle;

            var metadata  = module.metadata;
            var prop      = metadata.GetPropertyDefinition(handle);
            var accessors = prop.GetAccessors();

            getter = module.GetDefinition(accessors.Getter);
            setter = module.GetDefinition(accessors.Setter);
            name   = metadata.GetString(prop.Name);
            // Maybe we should defer the calculation of symbolKind?
            if (DetermineIsIndexer(name))
            {
                symbolKind = SymbolKind.Indexer;
            }
            else if (name.IndexOf('.') >= 0)
            {
                // explicit interface implementation
                var interfaceProp = this.ExplicitlyImplementedInterfaceMembers.FirstOrDefault() as IProperty;
                symbolKind = interfaceProp?.SymbolKind ?? SymbolKind.Property;
            }
            else
            {
                symbolKind = SymbolKind.Property;
            }
        }
示例#5
0
        internal static MrProperty TryGetProperty(
            MrType declaringType,
            PropertyDefinitionHandle propertyDefinitionHandle,
            bool publicishOnly)
        {
            var propertyDefinition = declaringType.Assembly.Reader.GetPropertyDefinition(propertyDefinitionHandle);

            var propertyAccessors = propertyDefinition.GetAccessors();
            var mrGetter          = TryGetEtter(
                declaringType,
                propertyAccessors.Getter,
                publicishOnly);

            var mrSetter = TryGetEtter(
                declaringType,
                propertyAccessors.Setter,
                publicishOnly);

            if (mrGetter != null || mrSetter != null)
            {
                return(new MrProperty(declaringType, propertyDefinitionHandle, propertyDefinition)
                {
                    Getter = mrGetter,
                    Setter = mrSetter
                });
            }

            return(null);
        }
示例#6
0
        internal static PEPropertySymbol Create(
            PEModuleSymbol moduleSymbol,
            PENamedTypeSymbol containingType,
            PropertyDefinitionHandle handle,
            PEMethodSymbol getMethod,
            PEMethodSymbol setMethod)
        {
            Debug.Assert((object)moduleSymbol != null);
            Debug.Assert((object)containingType != null);
            Debug.Assert(!handle.IsNil);

            var                     metadataDecoder = new MetadataDecoder(moduleSymbol, containingType);
            SignatureHeader         callingConvention;
            BadImageFormatException propEx;
            var                     propertyParams = metadataDecoder.GetSignatureForProperty(handle, out callingConvention, out propEx);

            Debug.Assert(propertyParams.Length > 0);

            var returnInfo = propertyParams[0];

            PEPropertySymbol result = returnInfo.CustomModifiers.IsDefaultOrEmpty && returnInfo.RefCustomModifiers.IsDefaultOrEmpty
                ? new PEPropertySymbol(moduleSymbol, containingType, handle, getMethod, setMethod, propertyParams, metadataDecoder)
                : new PEPropertySymbolWithCustomModifiers(moduleSymbol, containingType, handle, getMethod, setMethod, propertyParams, metadataDecoder);

            // A property should always have this modreq, and vice versa.
            var isBad = (result.RefKind == RefKind.In) != result.RefCustomModifiers.HasInAttributeModifier();

            if (propEx != null || isBad)
            {
                result._lazyUseSiteDiagnostic = new CSDiagnosticInfo(ErrorCode.ERR_BindToBogus, result);
            }

            return(result);
        }
示例#7
0
        internal PropertyDefinition(MetadataReader reader, PropertyDefinitionHandle handle)
        {
            Debug.Assert(reader != null);
            Debug.Assert(!handle.IsNil);

            _reader = reader;
            _rowId = handle.RowId;
        }
示例#8
0
 public PropertyDefEntry(PEFile module, PropertyDefinitionHandle handle)
 {
     this.metadataOffset = module.Reader.PEHeaders.MetadataStartOffset;
     this.module         = module;
     this.metadata       = module.Metadata;
     this.handle         = handle;
     this.propertyDef    = metadata.GetPropertyDefinition(handle);
 }
        internal PropertyDefinition(MetadataReader reader, PropertyDefinitionHandle handle)
        {
            Debug.Assert(reader != null);
            Debug.Assert(!handle.IsNil);

            _reader = reader;
            _rowId  = handle.RowId;
        }
 //
 // propertyHandle - the "tkPropertyDef" that identifies the property.
 // definingType   - the "tkTypeDef" that defined the field (this is where you get the metadata reader that created propertyHandle.)
 // contextType    - the type that supplies the type context (i.e. substitutions for generic parameters.) Though you
 //                  get your raw information from "definingType", you report "contextType" as your DeclaringType property.
 //
 //  For example:
 //
 //       typeof(Foo<>).GetTypeInfo().DeclaredMembers
 //
 //           The definingType and contextType are both Foo<>
 //
 //       typeof(Foo<int,String>).GetTypeInfo().DeclaredMembers
 //
 //          The definingType is "Foo<,>"
 //          The contextType is "Foo<int,String>"
 //
 //  We don't report any DeclaredMembers for arrays or generic parameters so those don't apply.
 //
 private EcmaFormatRuntimePropertyInfo(PropertyDefinitionHandle propertyHandle, EcmaFormatRuntimeNamedTypeInfo definingTypeInfo, RuntimeTypeInfo contextTypeInfo, RuntimeTypeInfo reflectedType) :
     base(contextTypeInfo, reflectedType)
 {
     _propertyHandle   = propertyHandle;
     _definingTypeInfo = definingTypeInfo;
     _reader           = definingTypeInfo.Reader;
     _property         = _reader.GetPropertyDefinition(propertyHandle);
 }
        public PropertyDefinitionMetadata ReservePropertyDefinition(PropertyInfo property,
                                                                    PropertyDefinitionHandle propertyHandle)
        {
            var metadata = new PropertyDefinitionMetadata(property, propertyHandle);

            _propertyHandles.Add(property, metadata);
            return(metadata);
        }
示例#12
0
 private MrProperty(
     MrType declaringType,
     PropertyDefinitionHandle propertyDefinitionHandle,
     PropertyDefinition propertyDefinition)
 {
     DeclaringType    = declaringType;
     DefinitionHandle = propertyDefinitionHandle;
     Definition       = propertyDefinition;
 }
        /// <summary>
        /// Creates a instance of the method, if there is already not an instance.
        /// </summary>
        /// <param name="handle">The handle to the instance.</param>
        /// <param name="assemblyMetadata">The module that contains the instance.</param>
        /// <returns>The wrapper.</returns>
        public static PropertyWrapper?Create(PropertyDefinitionHandle handle, AssemblyMetadata assemblyMetadata)
        {
            if (handle.IsNil)
            {
                return(null);
            }

            return(new PropertyWrapper(handle, assemblyMetadata));
        }
示例#14
0
文件: Property.cs 项目: s0/ql
        public Property(GenericContext gc, Type type, PropertyDefinitionHandle handle) : base(gc.cx)
        {
            pd        = cx.mdReader.GetPropertyDefinition(handle);
            this.type = type;

            var id        = type.ShortId + gc.cx.Dot + cx.ShortName(pd.Name);
            var signature = pd.DecodeSignature(new SignatureDecoder(), gc);

            id     += "(" + CIL.Id.CommaSeparatedList(signature.ParameterTypes.Select(p => p.MakeId(gc))) + ")";
            ShortId = id;
        }
示例#15
0
        internal override bool TryGetPropertyHandle(Cci.IPropertyDefinition def, out PropertyDefinitionHandle handle)
        {
            if (mapToMetadata.MapDefinition(def) is PEPropertySymbol other)
            {
                handle = other.Handle;
                return(true);
            }

            handle = default;
            return(false);
        }
示例#16
0
        private void ImportProperty(PropertyDefinitionHandle srcHandle)
        {
            var src = _reader.GetPropertyDefinition(srcHandle);

            var accessors = src.GetAccessors();

            var getter = Import(accessors.Getter);
            var setter = Import(accessors.Setter);

            var others = accessors.Others
                         .Select(a => Tuple.Create(a, Import(a)))
                         .Where(a => !a.Item2.IsNil)
                         .ToList();

            if (getter.IsNil && setter.IsNil && !others.Any())
            {
                Trace?.Invoke($"Not imported property {_reader.ToString(src)}");
                return;
            }

            var dstHandle = _builder.AddProperty(src.Attributes, ImportValue(src.Name), ImportSignatureWithHeader(src.Signature));

            _propertyDefinitionCache.Add(srcHandle, dstHandle);

            Trace?.Invoke($"Imported property {_reader.ToString(src)} -> {RowId(dstHandle):X}");

            using var _ = WithLogPrefix($"[{_reader.ToString(src)}]");

            if (!getter.IsNil)
            {
                _builder.AddMethodSemantics(dstHandle, MethodSemanticsAttributes.Getter, getter);
                Trace?.Invoke($"Imported getter {_reader.ToString(accessors.Getter)} -> {RowId(getter):X}");
            }

            if (!setter.IsNil)
            {
                _builder.AddMethodSemantics(dstHandle, MethodSemanticsAttributes.Setter, setter);
                Trace?.Invoke($"Imported setter {_reader.ToString(accessors.Setter)} -> {RowId(setter):X}");
            }

            foreach (var(srcAccessor, dstAccessor) in others)
            {
                _builder.AddMethodSemantics(dstHandle, MethodSemanticsAttributes.Other, dstAccessor);
                Trace?.Invoke($"Imported other {_reader.ToString(srcAccessor)} -> {RowId(dstAccessor):X}");
            }

            var defaultValue = src.GetDefaultValue();

            if (!defaultValue.IsNil)
            {
                ImportDefaultValue(defaultValue, dstHandle);
            }
        }
示例#17
0
        internal EcmaProperty(RoInstantiationProviderType declaringType, PropertyDefinitionHandle handle, Type reflectedType)
            : base(declaringType, reflectedType)
        {
            Debug.Assert(!handle.IsNil);
            Debug.Assert(declaringType != null);
            Debug.Assert(reflectedType != null);
            Debug.Assert(declaringType.Module is EcmaModule);

            _handle = handle;
            _module = (EcmaModule)(declaringType.Module);
            _neverAccessThisExceptThroughPropertyDefinitionProperty = handle.GetPropertyDefinition(Reader);
        }
示例#18
0
        public PropertyDefinitionHandle CreatePropertiesForType(PropertyInfo[] properties)
        {
            if (properties.Length == 0)
            {
                return(default(PropertyDefinitionHandle));
            }

            var handles = new PropertyDefinitionHandle[properties.Length];

            for (var i = 0; i < properties.Length; i++)
            {
                var property = properties[i];

                if (_propertyHandles.TryGetValue(property, out var propertyDef))
                {
                    handles[i] = propertyDef;
                    continue;
                }

                propertyDef = _metadataBuilder.AddProperty(
                    property.Attributes,
                    GetString(property.Name),
                    GetPropertySignature(property));

                _propertyHandles.Add(property, propertyDef);

                handles[i] = propertyDef;

                var getMethod = property.GetGetMethod(true);
                if (getMethod != null)
                {
                    _metadataBuilder.AddMethodSemantics(
                        propertyDef,
                        MethodSemanticsAttributes.Getter,
                        GetOrCreateMethod(getMethod));
                }

                var setMethod = property.GetSetMethod(true);
                if (setMethod != null)
                {
                    _metadataBuilder.AddMethodSemantics(
                        propertyDef,
                        MethodSemanticsAttributes.Setter,
                        GetOrCreateMethod(setMethod));
                }
            }

            return(handles.First());
        }
示例#19
0
        internal override bool TryGetPropertyHandle(Cci.IPropertyDefinition def, out PropertyDefinitionHandle handle)
        {
            var other = this.mapToMetadata.MapDefinition(def) as PEPropertySymbol;

            if ((object)other != null)
            {
                handle = other.Handle;
                return(true);
            }
            else
            {
                handle = default(PropertyDefinitionHandle);
                return(false);
            }
        }
示例#20
0
            public PEPropertySymbolWithCustomModifiers(
                PEModuleSymbol moduleSymbol,
                PENamedTypeSymbol containingType,
                PropertyDefinitionHandle handle,
                PEMethodSymbol getMethod,
                PEMethodSymbol setMethod,
                ParamInfo <TypeSymbol>[] propertyParams,
                MetadataDecoder metadataDecoder)
                : base(moduleSymbol, containingType, handle, getMethod, setMethod,
                       propertyParams,
                       metadataDecoder)
            {
                var returnInfo = propertyParams[0];

                _refCustomModifiers = CSharpCustomModifier.Convert(returnInfo.RefCustomModifiers);
            }
示例#21
0
        /// <summary>
        /// Get the information for a property.
        /// </summary>
        /// <param name="reader">The metadata reader.</param>
        /// <param name="handle">The property definition to read.</param>
        /// <returns>The property's information.</returns>
        public static PropertyInfo GetPropertyInfo(this MetadataReader reader, PropertyDefinitionHandle handle)
        {
            var propertyDefinition = reader.GetPropertyDefinition(handle);
            var accessors          = propertyDefinition.GetAccessors();
            var signature          = propertyDefinition.DecodeSignature(new SignatureTypeProvider(reader), null);

            return(new PropertyInfo
            {
                Name = reader.GetString(propertyDefinition.Name),

                Type = signature.ReturnType,

                HasGetter = !accessors.Getter.IsNil,
                HasSetter = !accessors.Setter.IsNil,

                Attributes = propertyDefinition.Attributes,
            });
        }
示例#22
0
        private static void ProcessPropertyDef(PropertyDefinitionHandle propertyDefHandle, MetadataReader dllReader, MetadataReader pdbReader, HashSet <DocumentHandle> docList)
        {
            var propertyDef = dllReader.GetPropertyDefinition(propertyDefHandle);
            var accessors   = propertyDef.GetAccessors();

            if (!accessors.Getter.IsNil)
            {
                ProcessMethodDef(accessors.Getter, dllReader, pdbReader, docList, processDeclaringType: true);
            }

            if (!accessors.Setter.IsNil)
            {
                ProcessMethodDef(accessors.Setter, dllReader, pdbReader, docList, processDeclaringType: true);
            }

            foreach (var other in accessors.Others)
            {
                ProcessMethodDef(other, dllReader, pdbReader, docList, processDeclaringType: true);
            }
        }
示例#23
0
        private void WalkProperty(MetadataReader mdReader, PropertyDefinitionHandle handle, MutableSymbol parent)
        {
            PropertyDefinition prop = mdReader.GetPropertyDefinition(handle);

            MutableSymbol result = new MutableSymbol(mdReader.GetString(prop.Name), SymbolType.Property);

            // Use the accessibility and location of the getter [or setter, if write only property]
            // Not identical to Roslyn PEPropertyDeclaration but much simpler
            MethodDefinitionHandle getterOrSetterHandle = prop.GetAccessors().Getter;

            if (getterOrSetterHandle.IsNil)
            {
                getterOrSetterHandle = prop.GetAccessors().Setter;
            }

            // If we couldn't retrieve a getter or setter, exclude this property
            if (getterOrSetterHandle.IsNil)
            {
                return;
            }

            MethodDefinition getterOrSetter = mdReader.GetMethodDefinition(getterOrSetterHandle);

            AddModifiers(getterOrSetter.Attributes, result);
            AddLocation(getterOrSetterHandle, result);
            AddParameters(mdReader, getterOrSetter, result);

            // If this is an Indexer, rename it and retype it
            // Roslyn PEPropertySymbol.IsIndexer is also just based on the name.
            if (result.Name == "Item")
            {
                result.Name = "this[]";
                result.Type = SymbolType.Indexer;
            }

            if (IsExcluded(result))
            {
                return;
            }
            parent.AddChild(result);
        }
        private PropertyWrapper(PropertyDefinitionHandle handle, AssemblyMetadata assemblyMetadata)
        {
            PropertyDefinitionHandle = handle;
            AssemblyMetadata         = assemblyMetadata;
            Handle     = handle;
            Definition = Resolve();

            _name       = new Lazy <string>(() => Definition.Name.GetName(assemblyMetadata), LazyThreadSafetyMode.PublicationOnly);
            _attributes = new Lazy <IReadOnlyList <AttributeWrapper> >(() => AttributeWrapper.CreateChecked(Definition.GetCustomAttributes(), assemblyMetadata), LazyThreadSafetyMode.PublicationOnly);

            _getterMethod = new Lazy <MethodWrapper?>(() => MethodWrapper.Create(Definition.GetAccessors().Getter, assemblyMetadata), LazyThreadSafetyMode.PublicationOnly);
            _setterMethod = new Lazy <MethodWrapper?>(() => MethodWrapper.Create(Definition.GetAccessors().Setter, assemblyMetadata), LazyThreadSafetyMode.PublicationOnly);

            _anyAccessor = new Lazy <MethodWrapper>(GetAnyAccessor, LazyThreadSafetyMode.PublicationOnly);

            _declaringType = new Lazy <TypeWrapper>(() => AnyAccessor.DeclaringType, LazyThreadSafetyMode.PublicationOnly);

            _accessibility = new Lazy <EntityAccessibility>(GetAccessibility, LazyThreadSafetyMode.PublicationOnly);

            _signature = new Lazy <MethodSignature <IHandleTypeNamedWrapper> >(() => Definition.DecodeSignature(assemblyMetadata.TypeProvider, new GenericContext(this)), LazyThreadSafetyMode.PublicationOnly);
        }
        public PropertyInformation(AssemblyInformation assembly, TypeDefinition tdef,
                                   PropertyDefinitionHandle handle)
        {
            var def = assembly.Reader.GetPropertyDefinition(handle);

            Name = assembly.Reader.GetString(def.Name);

            MethodInformation build(MethodDefinitionHandle mh)
            => mh.IsNil ? default(MethodInformation) : new MethodInformation(assembly, mh);

            var accessors = def.GetAccessors();

            var getter = build(accessors.Getter);
            var setter = build(accessors.Setter);

            HasPublicSetter = setter?.IsPublic ?? false;
            HasPublicGetter = getter?.IsPublic ?? false;

            TypeFullName = getter?.ReturnTypeFullName ?? setter?.Parameters[0].TypeFullName;
            IsStatic     = getter?.IsStatic ?? setter?.IsStatic ?? false;
        }
示例#26
0
            public PEPropertySymbolWithCustomModifiers(
                PEModuleSymbol moduleSymbol,
                PENamedTypeSymbol containingType,
                PropertyDefinitionHandle handle,
                PEMethodSymbol getMethod,
                PEMethodSymbol setMethod,
                ParamInfo <TypeSymbol>[] propertyParams,
                MetadataDecoder metadataDecoder,
                out bool isBad)
                : base(moduleSymbol, containingType, handle, getMethod, setMethod,
                       propertyParams[0].CustomModifiers.NullToEmpty().Length + propertyParams[0].RefCustomModifiers.NullToEmpty().Length,
                       propertyParams, metadataDecoder)
            {
                var returnInfo = propertyParams[0];

                _typeCustomModifiers = CSharpCustomModifier.Convert(returnInfo.CustomModifiers);
                _refCustomModifiers  = CSharpCustomModifier.Convert(returnInfo.RefCustomModifiers);

                // The modreq is only accepted on RefReadOnly symbols
                isBad = this.RefKind != RefKind.RefReadOnly && _refCustomModifiers.Any(modifier => !modifier.IsOptional && modifier.Modifier.IsWellKnownTypeInAttribute());
            }
示例#27
0
        internal static PEPropertySymbol Create(
            PEModuleSymbol moduleSymbol,
            PENamedTypeSymbol containingType,
            PropertyDefinitionHandle handle,
            PEMethodSymbol getMethod,
            PEMethodSymbol setMethod)
        {
            Debug.Assert((object)moduleSymbol != null);
            Debug.Assert((object)containingType != null);
            Debug.Assert(!handle.IsNil);

            var metadataDecoder = new MetadataDecoder(moduleSymbol, containingType);
            SignatureHeader callingConvention;
            BadImageFormatException propEx;
            var propertyParams = metadataDecoder.GetSignatureForProperty(handle, out callingConvention, out propEx);
            Debug.Assert(propertyParams.Length > 0);

            var returnInfo = propertyParams[0];
            PEPropertySymbol result;

            if (returnInfo.CustomModifiers.IsDefaultOrEmpty && returnInfo.RefCustomModifiers.IsDefaultOrEmpty)
            {
                result = new PEPropertySymbol(moduleSymbol, containingType, handle, getMethod, setMethod, 0, propertyParams, metadataDecoder);
            }
            else
            {
                result = new PEPropertySymbolWithCustomModifiers(moduleSymbol, containingType, handle, getMethod, setMethod, propertyParams, metadataDecoder);
            }

            if (propEx != null)
            {
                result._lazyUseSiteDiagnostic = new CSDiagnosticInfo(ErrorCode.ERR_BindToBogus, result);
            }

            return result;
        }
        public PropertyInformation(AssemblyInformation assembly, TypeDefinition tdef,
                                   PropertyDefinitionHandle handle)
        {
            var def = assembly.Reader.GetPropertyDefinition(handle);

            Name = assembly.Reader.GetString(def.Name);

            var accessors = def.GetAccessors();
            MethodInformation accessor;

            if (!accessors.Setter.IsNil)
            {
                accessor        = new MethodInformation(assembly, accessors.Setter);
                HasPublicSetter = accessor.IsPublic;

                TypeFullName = accessor.Parameters[0].TypeFullName;
            }
            else
            {
                accessor     = new MethodInformation(assembly, accessors.Getter);
                TypeFullName = accessor.ReturnTypeFullName;
            }
            IsStatic = accessor.IsStatic;
        }
示例#29
0
 public PropertyDefinition GetPropertyDefinition(PropertyDefinitionHandle handle)
 {
     return new PropertyDefinition(this, handle);
 }
示例#30
0
        private PEPropertySymbol(
            PEModuleSymbol moduleSymbol,
            PENamedTypeSymbol containingType,
            PropertyDefinitionHandle handle,
            PEMethodSymbol getMethod,
            PEMethodSymbol setMethod,
            ParamInfo <TypeSymbol>[] propertyParams,
            MetadataDecoder metadataDecoder)
        {
            _containingType = containingType;
            var module = moduleSymbol.Module;
            PropertyAttributes      mdFlags = 0;
            BadImageFormatException mrEx    = null;

            try
            {
                module.GetPropertyDefPropsOrThrow(handle, out _name, out mdFlags);
            }
            catch (BadImageFormatException e)
            {
                mrEx = e;

                if ((object)_name == null)
                {
                    _name = string.Empty;
                }
            }

            _getMethod = getMethod;
            _setMethod = setMethod;
            _handle    = handle;

            SignatureHeader         unusedCallingConvention;
            BadImageFormatException getEx = null;
            var getMethodParams           = (object)getMethod == null ? null : metadataDecoder.GetSignatureForMethod(getMethod.Handle, out unusedCallingConvention, out getEx);
            BadImageFormatException setEx = null;
            var setMethodParams           = (object)setMethod == null ? null : metadataDecoder.GetSignatureForMethod(setMethod.Handle, out unusedCallingConvention, out setEx);

            // NOTE: property parameter names are not recorded in metadata, so we have to
            // use the parameter names from one of the indexers
            // NB: prefer setter names to getter names if both are present.
            bool isBad;

            _parameters = setMethodParams is null
                ? GetParameters(moduleSymbol, this, propertyParams, getMethodParams, getMethod.IsMetadataVirtual(), out isBad)
                : GetParameters(moduleSymbol, this, propertyParams, setMethodParams, setMethod.IsMetadataVirtual(), out isBad);

            if (getEx != null || setEx != null || mrEx != null || isBad)
            {
                _lazyUseSiteDiagnostic = new CSDiagnosticInfo(ErrorCode.ERR_BindToBogus, this);
            }

            var returnInfo          = propertyParams[0];
            var typeCustomModifiers = CSharpCustomModifier.Convert(returnInfo.CustomModifiers);

            if (returnInfo.IsByRef)
            {
                if (moduleSymbol.Module.HasIsReadOnlyAttribute(handle))
                {
                    _refKind = RefKind.RefReadOnly;
                }
                else
                {
                    _refKind = RefKind.Ref;
                }
            }
            else
            {
                _refKind = RefKind.None;
            }

            // CONSIDER: Can we make parameter type computation lazy?
            TypeSymbol originalPropertyType = returnInfo.Type;

            originalPropertyType = DynamicTypeDecoder.TransformType(originalPropertyType, typeCustomModifiers.Length, handle, moduleSymbol, _refKind);
            originalPropertyType = NativeIntegerTypeDecoder.TransformType(originalPropertyType, handle, moduleSymbol);

            // Dynamify object type if necessary
            originalPropertyType = originalPropertyType.AsDynamicIfNoPia(_containingType);

            // We start without annotation (they will be decoded below)
            var propertyTypeWithAnnotations = TypeWithAnnotations.Create(originalPropertyType, customModifiers: typeCustomModifiers);

            // Decode nullable before tuple types to avoid converting between
            // NamedTypeSymbol and TupleTypeSymbol unnecessarily.

            // The containing type is passed to NullableTypeDecoder.TransformType to determine access
            // because the property does not have explicit accessibility in metadata.
            propertyTypeWithAnnotations = NullableTypeDecoder.TransformType(propertyTypeWithAnnotations, handle, moduleSymbol, accessSymbol: _containingType, nullableContext: _containingType);
            propertyTypeWithAnnotations = TupleTypeDecoder.DecodeTupleTypesIfApplicable(propertyTypeWithAnnotations, handle, moduleSymbol);

            _propertyTypeWithAnnotations = propertyTypeWithAnnotations;

            // A property is bogus and must be accessed by calling its accessors directly if the
            // accessor signatures do not agree, both with each other and with the property,
            // or if it has parameters and is not an indexer or indexed property.
            bool callMethodsDirectly = !DoSignaturesMatch(module, metadataDecoder, propertyParams, _getMethod, getMethodParams, _setMethod, setMethodParams) ||
                                       MustCallMethodsDirectlyCore();

            if (!callMethodsDirectly)
            {
                if ((object)_getMethod != null)
                {
                    _getMethod.SetAssociatedProperty(this, MethodKind.PropertyGet);
                }

                if ((object)_setMethod != null)
                {
                    _setMethod.SetAssociatedProperty(this, MethodKind.PropertySet);
                }
            }

            if (callMethodsDirectly)
            {
                _flags |= Flags.CallMethodsDirectly;
            }

            if ((mdFlags & PropertyAttributes.SpecialName) != 0)
            {
                _flags |= Flags.IsSpecialName;
            }

            if ((mdFlags & PropertyAttributes.RTSpecialName) != 0)
            {
                _flags |= Flags.IsRuntimeSpecialName;
            }
        }
示例#31
0
 internal abstract bool TryGetPropertyHandle(Cci.IPropertyDefinition def, out PropertyDefinitionHandle handle);
 private Mapping<PropertyDefinitionHandle> MapPropertyDefinitionImpl(PropertyDefinitionHandle handle)
 {
     throw new NotImplementedException();
 }
 public Mapping<PropertyDefinitionHandle> MapPropertyDefinition(PropertyDefinitionHandle handle)
 {
     return _propertyDefinitions.GetOrAdd(handle, MapPropertyDefinitionImpl);
 }
示例#34
0
 internal BlobHandle GetSignature(PropertyDefinitionHandle handle)
 {
     int rowOffset = (handle.RowId - 1) * this.RowSize;
     return BlobHandle.FromOffset(this.Block.PeekHeapReference(rowOffset + _SignatureOffset, _IsBlobHeapRefSizeSmall));
 }
示例#35
0
 internal static uint ConvertPropertyHandleToTag(PropertyDefinitionHandle propertyDef)
 {
     return (uint)propertyDef.RowId << NumberOfBits | Property;
 }
示例#36
0
        private MemberInfo GetOrAddPropertyInfo(PropertyDefinitionHandle handle)
        {
            if (this.properties == null)
            {
                properties = new Dictionary<PropertyDefinitionHandle, MemberInfo>();
            }

            MemberInfo result = null;
            if (!properties.TryGetValue(handle, out result))
            {
                var property = metadataReader.GetPropertyDefinition(handle);
                var propertyMethodDefinitionHandles = property.GetAccessors();
                TypeDefinitionHandle declaringTypeDefinitionHandle;
                MethodDefinitionHandle accessorMethod = propertyMethodDefinitionHandles.Getter;
                if (accessorMethod.IsNil)
                {
                    accessorMethod = propertyMethodDefinitionHandles.Setter;
                }

                declaringTypeDefinitionHandle = metadataReader.GetMethodDefinition(accessorMethod).GetDeclaringType();
                result = new MemberInfo(MemberKind.Property);
                result.Token = this.metadataReader.GetToken(handle);
                result.DeclaringTypeDefinitionHandle = declaringTypeDefinitionHandle;
                result.Handle = handle;
                properties.Add(handle, result);
            }

            return result;
        }
示例#37
0
        internal PEPropertySymbol(
            PEModuleSymbol moduleSymbol,
            PENamedTypeSymbol containingType,
            PropertyDefinitionHandle handle,
            PEMethodSymbol getMethod,
            PEMethodSymbol setMethod)
        {
            Debug.Assert((object)moduleSymbol != null);
            Debug.Assert((object)containingType != null);
            Debug.Assert(!handle.IsNil);

            _containingType = containingType;
            var module = moduleSymbol.Module;
            PropertyAttributes      mdFlags = 0;
            BadImageFormatException mrEx    = null;

            try
            {
                module.GetPropertyDefPropsOrThrow(handle, out _name, out mdFlags);
            }
            catch (BadImageFormatException e)
            {
                mrEx = e;

                if ((object)_name == null)
                {
                    _name = string.Empty;
                }
            }

            _getMethod = getMethod;
            _setMethod = setMethod;
            _handle    = handle;

            var                     metadataDecoder = new MetadataDecoder(moduleSymbol, containingType);
            SignatureHeader         callingConvention;
            BadImageFormatException propEx;
            var                     propertyParams = metadataDecoder.GetSignatureForProperty(handle, out callingConvention, out propEx, allowByRefReturn: true);

            Debug.Assert(propertyParams.Length > 0);

            SignatureHeader         unusedCallingConvention;
            BadImageFormatException getEx = null;
            var getMethodParams           = (object)getMethod == null ? null : metadataDecoder.GetSignatureForMethod(getMethod.Handle, out unusedCallingConvention, out getEx, allowByRefReturn: true);
            BadImageFormatException setEx = null;
            var setMethodParams           = (object)setMethod == null ? null : metadataDecoder.GetSignatureForMethod(setMethod.Handle, out unusedCallingConvention, out setEx, allowByRefReturn: false);

            // NOTE: property parameter names are not recorded in metadata, so we have to
            // use the parameter names from one of the indexers
            // NB: prefer setter names to getter names if both are present.
            bool isBad;

            _parameters = GetParameters(moduleSymbol, this, propertyParams, setMethodParams ?? getMethodParams, out isBad);

            if (propEx != null || getEx != null || setEx != null || mrEx != null || isBad)
            {
                _lazyUseSiteDiagnostic = new CSDiagnosticInfo(ErrorCode.ERR_BindToBogus, this);
            }

            _typeCustomModifiers = CSharpCustomModifier.Convert(propertyParams[0].CustomModifiers);

            _refKind = propertyParams[0].IsByRef ? RefKind.Ref : RefKind.None;

            // CONSIDER: Can we make parameter type computation lazy?
            TypeSymbol originalPropertyType = propertyParams[0].Type;

            _propertyType = DynamicTypeDecoder.TransformType(originalPropertyType, _typeCustomModifiers.Length, handle, moduleSymbol);

            // Dynamify object type if necessary
            _propertyType = _propertyType.AsDynamicIfNoPia(_containingType);

            _propertyType = TupleTypeDecoder.DecodeTupleTypesIfApplicable(_propertyType, handle, moduleSymbol);

            // A property is bogus and must be accessed by calling its accessors directly if the
            // accessor signatures do not agree, both with each other and with the property,
            // or if it has parameters and is not an indexer or indexed property.
            bool callMethodsDirectly = !DoSignaturesMatch(module, metadataDecoder, propertyParams, _getMethod, getMethodParams, _setMethod, setMethodParams) ||
                                       MustCallMethodsDirectlyCore();

            if (!callMethodsDirectly)
            {
                if ((object)_getMethod != null)
                {
                    _getMethod.SetAssociatedProperty(this, MethodKind.PropertyGet);
                }

                if ((object)_setMethod != null)
                {
                    _setMethod.SetAssociatedProperty(this, MethodKind.PropertySet);
                }
            }

            if (callMethodsDirectly)
            {
                _flags |= Flags.CallMethodsDirectly;
            }

            if ((mdFlags & PropertyAttributes.SpecialName) != 0)
            {
                _flags |= Flags.IsSpecialName;
            }

            if ((mdFlags & PropertyAttributes.RTSpecialName) != 0)
            {
                _flags |= Flags.IsRuntimeSpecialName;
            }
        }
示例#38
0
 public PEPropertySymbolWithCustomModifiers(
     PEModuleSymbol moduleSymbol,
     PENamedTypeSymbol containingType,
     PropertyDefinitionHandle handle,
     PEMethodSymbol getMethod,
     PEMethodSymbol setMethod,
     ParamInfo<TypeSymbol>[] propertyParams,
     MetadataDecoder metadataDecoder)
     : base (moduleSymbol, containingType, handle, getMethod, setMethod,
             propertyParams[0].CustomModifiers.NullToEmpty().Length + propertyParams[0].RefCustomModifiers.NullToEmpty().Length,
             propertyParams, metadataDecoder)
 {
     var returnInfo = propertyParams[0];
     _typeCustomModifiers = CSharpCustomModifier.Convert(returnInfo.CustomModifiers);
     _refCustomModifiers = CSharpCustomModifier.Convert(returnInfo.RefCustomModifiers);
 }
示例#39
0
 internal static uint ConvertPropertyHandleToTag(PropertyDefinitionHandle propertyDef)
 {
     return((uint)propertyDef.RowId << NumberOfBits | Property);
 }
示例#40
0
 public void AddPropertyMap(TypeDefinitionHandle declaringType, PropertyDefinitionHandle propertyList)
 {
     _propertyMapTable.Add(new PropertyMapRow
     {
         Parent = (uint)MetadataTokens.GetRowNumber(declaringType),
         PropertyList = (uint)MetadataTokens.GetRowNumber(propertyList)
     });
 }
示例#41
0
        private PEPropertySymbol(
            PEModuleSymbol moduleSymbol,
            PENamedTypeSymbol containingType,
            PropertyDefinitionHandle handle,
            PEMethodSymbol getMethod,
            PEMethodSymbol setMethod,
            int countOfCustomModifiers,
            ParamInfo<TypeSymbol>[] propertyParams,
            MetadataDecoder metadataDecoder)
        {
            _containingType = containingType;
            var module = moduleSymbol.Module;
            PropertyAttributes mdFlags = 0;
            BadImageFormatException mrEx = null;

            try
            {
                module.GetPropertyDefPropsOrThrow(handle, out _name, out mdFlags);
            }
            catch (BadImageFormatException e)
            {
                mrEx = e;

                if ((object)_name == null)
                {
                    _name = string.Empty;
                }
            }

            _getMethod = getMethod;
            _setMethod = setMethod;
            _handle = handle;

            SignatureHeader unusedCallingConvention;
            BadImageFormatException getEx = null;
            var getMethodParams = (object)getMethod == null ? null : metadataDecoder.GetSignatureForMethod(getMethod.Handle, out unusedCallingConvention, out getEx);
            BadImageFormatException setEx = null;
            var setMethodParams = (object)setMethod == null ? null : metadataDecoder.GetSignatureForMethod(setMethod.Handle, out unusedCallingConvention, out setEx);

            // NOTE: property parameter names are not recorded in metadata, so we have to
            // use the parameter names from one of the indexers
            // NB: prefer setter names to getter names if both are present.
            bool isBad;
            _parameters = GetParameters(moduleSymbol, this, propertyParams, setMethodParams ?? getMethodParams, out isBad);

            if (getEx != null || setEx != null || mrEx != null || isBad)
            {
                _lazyUseSiteDiagnostic = new CSDiagnosticInfo(ErrorCode.ERR_BindToBogus, this);
            }

            var returnInfo = propertyParams[0];
            _refKind = returnInfo.IsByRef ? RefKind.Ref : RefKind.None;

            // CONSIDER: Can we make parameter type computation lazy?
            TypeSymbol originalPropertyType = returnInfo.Type;
            _propertyType = DynamicTypeDecoder.TransformType(originalPropertyType, countOfCustomModifiers, handle, moduleSymbol, _refKind);

            // Dynamify object type if necessary
            _propertyType = _propertyType.AsDynamicIfNoPia(_containingType);

            _propertyType = TupleTypeDecoder.DecodeTupleTypesIfApplicable(_propertyType, handle, moduleSymbol);

            // A property is bogus and must be accessed by calling its accessors directly if the
            // accessor signatures do not agree, both with each other and with the property,
            // or if it has parameters and is not an indexer or indexed property.
            bool callMethodsDirectly = !DoSignaturesMatch(module, metadataDecoder, propertyParams, _getMethod, getMethodParams, _setMethod, setMethodParams) ||
                MustCallMethodsDirectlyCore();

            if (!callMethodsDirectly)
            {
                if ((object)_getMethod != null)
                {
                    _getMethod.SetAssociatedProperty(this, MethodKind.PropertyGet);
                }

                if ((object)_setMethod != null)
                {
                    _setMethod.SetAssociatedProperty(this, MethodKind.PropertySet);
                }
            }

            if (callMethodsDirectly)
            {
                _flags |= Flags.CallMethodsDirectly;
            }

            if ((mdFlags & PropertyAttributes.SpecialName) != 0)
            {
                _flags |= Flags.IsSpecialName;
            }

            if ((mdFlags & PropertyAttributes.RTSpecialName) != 0)
            {
                _flags |= Flags.IsRuntimeSpecialName;
            }
        }
示例#42
0
 internal StringHandle GetName(PropertyDefinitionHandle handle)
 {
     int rowOffset = (handle.RowId - 1) * this.RowSize;
     return StringHandle.FromOffset(this.Block.PeekHeapReference(rowOffset + _NameOffset, _IsStringHeapRefSizeSmall));
 }
示例#43
0
        public void IsNil()
        {
            Assert.False(ModuleDefinitionHandle.FromRowId(1).IsNil);
            Assert.False(AssemblyDefinitionHandle.FromRowId(1).IsNil);
            Assert.False(InterfaceImplementationHandle.FromRowId(1).IsNil);
            Assert.False(MethodDefinitionHandle.FromRowId(1).IsNil);
            Assert.False(MethodSpecificationHandle.FromRowId(1).IsNil);
            Assert.False(TypeDefinitionHandle.FromRowId(1).IsNil);
            Assert.False(ExportedTypeHandle.FromRowId(1).IsNil);
            Assert.False(TypeReferenceHandle.FromRowId(1).IsNil);
            Assert.False(TypeSpecificationHandle.FromRowId(1).IsNil);
            Assert.False(MemberReferenceHandle.FromRowId(1).IsNil);
            Assert.False(FieldDefinitionHandle.FromRowId(1).IsNil);
            Assert.False(EventDefinitionHandle.FromRowId(1).IsNil);
            Assert.False(PropertyDefinitionHandle.FromRowId(1).IsNil);
            Assert.False(StandaloneSignatureHandle.FromRowId(1).IsNil);
            Assert.False(MemberReferenceHandle.FromRowId(1).IsNil);
            Assert.False(FieldDefinitionHandle.FromRowId(1).IsNil);
            Assert.False(EventDefinitionHandle.FromRowId(1).IsNil);
            Assert.False(PropertyDefinitionHandle.FromRowId(1).IsNil);
            Assert.False(ParameterHandle.FromRowId(1).IsNil);
            Assert.False(GenericParameterHandle.FromRowId(1).IsNil);
            Assert.False(GenericParameterConstraintHandle.FromRowId(1).IsNil);
            Assert.False(ModuleReferenceHandle.FromRowId(1).IsNil);
            Assert.False(CustomAttributeHandle.FromRowId(1).IsNil);
            Assert.False(DeclarativeSecurityAttributeHandle.FromRowId(1).IsNil);
            Assert.False(ManifestResourceHandle.FromRowId(1).IsNil);
            Assert.False(ConstantHandle.FromRowId(1).IsNil);
            Assert.False(ManifestResourceHandle.FromRowId(1).IsNil);
            Assert.False(AssemblyFileHandle.FromRowId(1).IsNil);
            Assert.False(MethodImplementationHandle.FromRowId(1).IsNil);
            Assert.False(AssemblyReferenceHandle.FromRowId(1).IsNil);

            Assert.False(((EntityHandle)ModuleDefinitionHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)AssemblyDefinitionHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)InterfaceImplementationHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)MethodDefinitionHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)MethodSpecificationHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)TypeDefinitionHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)ExportedTypeHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)TypeReferenceHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)TypeSpecificationHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)MemberReferenceHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)FieldDefinitionHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)EventDefinitionHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)PropertyDefinitionHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)StandaloneSignatureHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)MemberReferenceHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)FieldDefinitionHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)EventDefinitionHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)PropertyDefinitionHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)ParameterHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)GenericParameterHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)GenericParameterConstraintHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)ModuleReferenceHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)CustomAttributeHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)DeclarativeSecurityAttributeHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)ManifestResourceHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)ConstantHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)ManifestResourceHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)AssemblyFileHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)MethodImplementationHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)AssemblyReferenceHandle.FromRowId(1)).IsNil);

            Assert.False(StringHandle.FromOffset(1).IsNil);
            Assert.False(BlobHandle.FromOffset(1).IsNil);
            Assert.False(UserStringHandle.FromOffset(1).IsNil);
            Assert.False(GuidHandle.FromIndex(1).IsNil);

            Assert.False(((Handle)StringHandle.FromOffset(1)).IsNil);
            Assert.False(((Handle)BlobHandle.FromOffset(1)).IsNil);
            Assert.False(((Handle)UserStringHandle.FromOffset(1)).IsNil);
            Assert.False(((Handle)GuidHandle.FromIndex(1)).IsNil);

            Assert.True(ModuleDefinitionHandle.FromRowId(0).IsNil);
            Assert.True(AssemblyDefinitionHandle.FromRowId(0).IsNil);
            Assert.True(InterfaceImplementationHandle.FromRowId(0).IsNil);
            Assert.True(MethodDefinitionHandle.FromRowId(0).IsNil);
            Assert.True(MethodSpecificationHandle.FromRowId(0).IsNil);
            Assert.True(TypeDefinitionHandle.FromRowId(0).IsNil);
            Assert.True(ExportedTypeHandle.FromRowId(0).IsNil);
            Assert.True(TypeReferenceHandle.FromRowId(0).IsNil);
            Assert.True(TypeSpecificationHandle.FromRowId(0).IsNil);
            Assert.True(MemberReferenceHandle.FromRowId(0).IsNil);
            Assert.True(FieldDefinitionHandle.FromRowId(0).IsNil);
            Assert.True(EventDefinitionHandle.FromRowId(0).IsNil);
            Assert.True(PropertyDefinitionHandle.FromRowId(0).IsNil);
            Assert.True(StandaloneSignatureHandle.FromRowId(0).IsNil);
            Assert.True(MemberReferenceHandle.FromRowId(0).IsNil);
            Assert.True(FieldDefinitionHandle.FromRowId(0).IsNil);
            Assert.True(EventDefinitionHandle.FromRowId(0).IsNil);
            Assert.True(PropertyDefinitionHandle.FromRowId(0).IsNil);
            Assert.True(ParameterHandle.FromRowId(0).IsNil);
            Assert.True(GenericParameterHandle.FromRowId(0).IsNil);
            Assert.True(GenericParameterConstraintHandle.FromRowId(0).IsNil);
            Assert.True(ModuleReferenceHandle.FromRowId(0).IsNil);
            Assert.True(CustomAttributeHandle.FromRowId(0).IsNil);
            Assert.True(DeclarativeSecurityAttributeHandle.FromRowId(0).IsNil);
            Assert.True(ManifestResourceHandle.FromRowId(0).IsNil);
            Assert.True(ConstantHandle.FromRowId(0).IsNil);
            Assert.True(ManifestResourceHandle.FromRowId(0).IsNil);
            Assert.True(AssemblyFileHandle.FromRowId(0).IsNil);
            Assert.True(MethodImplementationHandle.FromRowId(0).IsNil);
            Assert.True(AssemblyReferenceHandle.FromRowId(0).IsNil);

            Assert.True(((EntityHandle)ModuleDefinitionHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)AssemblyDefinitionHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)InterfaceImplementationHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)MethodDefinitionHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)MethodSpecificationHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)TypeDefinitionHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)ExportedTypeHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)TypeReferenceHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)TypeSpecificationHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)MemberReferenceHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)FieldDefinitionHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)EventDefinitionHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)PropertyDefinitionHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)StandaloneSignatureHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)MemberReferenceHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)FieldDefinitionHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)EventDefinitionHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)PropertyDefinitionHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)ParameterHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)GenericParameterHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)GenericParameterConstraintHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)ModuleReferenceHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)CustomAttributeHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)DeclarativeSecurityAttributeHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)ManifestResourceHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)ConstantHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)ManifestResourceHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)AssemblyFileHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)MethodImplementationHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)AssemblyReferenceHandle.FromRowId(0)).IsNil);

            // heaps:
            Assert.True(StringHandle.FromOffset(0).IsNil);
            Assert.True(BlobHandle.FromOffset(0).IsNil);
            Assert.True(UserStringHandle.FromOffset(0).IsNil);
            Assert.True(GuidHandle.FromIndex(0).IsNil);

            Assert.True(((Handle)StringHandle.FromOffset(0)).IsNil);
            Assert.True(((Handle)BlobHandle.FromOffset(0)).IsNil);
            Assert.True(((Handle)UserStringHandle.FromOffset(0)).IsNil);
            Assert.True(((Handle)GuidHandle.FromIndex(0)).IsNil);

            // virtual:
            Assert.False(AssemblyReferenceHandle.FromVirtualIndex(0).IsNil);
            Assert.False(StringHandle.FromVirtualIndex(0).IsNil);
            Assert.False(BlobHandle.FromVirtualIndex(0, 0).IsNil);

            Assert.False(((Handle)AssemblyReferenceHandle.FromVirtualIndex(0)).IsNil);
            Assert.False(((Handle)StringHandle.FromVirtualIndex(0)).IsNil);
            Assert.False(((Handle)BlobHandle.FromVirtualIndex(0, 0)).IsNil);
        }
示例#44
0
        internal PEPropertySymbol(
            PEModuleSymbol moduleSymbol,
            PENamedTypeSymbol containingType,
            PropertyDefinitionHandle handle,
            PEMethodSymbol getMethod,
            PEMethodSymbol setMethod)
        {
            Debug.Assert((object)moduleSymbol != null);
            Debug.Assert((object)containingType != null);
            Debug.Assert(!handle.IsNil);

            _containingType = containingType;
            var module = moduleSymbol.Module;
            PropertyAttributes mdFlags = 0;
            BadImageFormatException mrEx = null;

            try
            {
                module.GetPropertyDefPropsOrThrow(handle, out _name, out mdFlags);
            }
            catch (BadImageFormatException e)
            {
                mrEx = e;

                if ((object)_name == null)
                {
                    _name = string.Empty;
                }
            }

            _getMethod = getMethod;
            _setMethod = setMethod;
            _handle = handle;

            var metadataDecoder = new MetadataDecoder(moduleSymbol, containingType);
            SignatureHeader callingConvention;
            BadImageFormatException propEx;
            var propertyParams = metadataDecoder.GetSignatureForProperty(handle, out callingConvention, out propEx);
            Debug.Assert(propertyParams.Length > 0);

            SignatureHeader unusedCallingConvention;
            BadImageFormatException getEx = null;
            var getMethodParams = (object)getMethod == null ? null : metadataDecoder.GetSignatureForMethod(getMethod.Handle, out unusedCallingConvention, out getEx);
            BadImageFormatException setEx = null;
            var setMethodParams = (object)setMethod == null ? null : metadataDecoder.GetSignatureForMethod(setMethod.Handle, out unusedCallingConvention, out setEx);

            // NOTE: property parameter names are not recorded in metadata, so we have to
            // use the parameter names from one of the indexers.
            // NB: prefer setter names to getter names if both are present.
            bool isBad;
            _parameters = GetParameters(moduleSymbol, this, propertyParams, setMethodParams ?? getMethodParams, out isBad);

            //if (propEx != null || getEx != null || setEx != null || mrEx != null || isBad)
            //{
            //    _lazyUseSiteDiagnostic = new CSDiagnosticInfo(ErrorCode.ERR_BindToBogus, this);
            //}

            _typeCustomModifiers = CSharpCustomModifier.Convert(propertyParams[0].CustomModifiers);

            // CONSIDER: Can we make parameter type computation lazy?
            TypeSymbol originalPropertyType = propertyParams[0].Type;
            _propertyType = originalPropertyType; // DynamicTypeDecoder.TransformType(originalPropertyType, _typeCustomModifiers.Length, handle, moduleSymbol);

            //// Dynamify object type if necessary
            //_propertyType = _propertyType.AsDynamicIfNoPia(_containingType);

            // A property is bogus and must be accessed by calling its accessors directly if the
            // accessor signatures do not agree, both with each other and with the property,
            // or if it has parameters and is not an indexer or indexed property.
            bool callMethodsDirectly = !DoSignaturesMatch(module, metadataDecoder, propertyParams, _getMethod, getMethodParams, _setMethod, setMethodParams) ||
                MustCallMethodsDirectlyCore();

            if (!callMethodsDirectly)
            {
                //if ((object)_getMethod != null)
                //{
                //    _getMethod.SetAssociatedProperty(this, MethodKind.PropertyGet);
                //}

                //if ((object)_setMethod != null)
                //{
                //    _setMethod.SetAssociatedProperty(this, MethodKind.PropertySet);
                //}
            }

            if (callMethodsDirectly)
            {
                _flags |= Flags.CallMethodsDirectly;
            }

            if ((mdFlags & PropertyAttributes.SpecialName) != 0)
            {
                _flags |= Flags.IsSpecialName;
            }

            if ((mdFlags & PropertyAttributes.RTSpecialName) != 0)
            {
                _flags |= Flags.IsRuntimeSpecialName;
            }
        }
示例#45
0
 internal PropertyAttributes GetFlags(PropertyDefinitionHandle handle)
 {
     int rowOffset = (handle.RowId - 1) * this.RowSize;
     return (PropertyAttributes)this.Block.PeekUInt16(rowOffset + _FlagsOffset);
 }
示例#46
0
 internal int FindSemanticMethodsForProperty(PropertyDefinitionHandle propertyDef, out ushort methodCount)
 {
     methodCount = 0;
     uint searchCodedTag = HasSemanticsTag.ConvertPropertyHandleToTag(propertyDef);
     return this.BinarySearchTag(searchCodedTag, ref methodCount);
 }