Convert() приватный статический Метод

private static Convert ( ModifierInfo customModifier ) : Microsoft.CodeAnalysis.CustomModifier
customModifier ModifierInfo
Результат Microsoft.CodeAnalysis.CustomModifier
Пример #1
0
        ///// <summary>
        ///// Mark this field as the backing field of a field-like event.
        ///// The caller will also ensure that it is excluded from the member list of
        ///// the containing type (as it would be in source).
        ///// </summary>
        //internal void SetAssociatedEvent(PEEventSymbol eventSymbol)
        //{
        //    Debug.Assert((object)eventSymbol != null);
        //    Debug.Assert(eventSymbol.ContainingType == _containingType);

        //    // This should always be true in valid metadata - there should only
        //    // be one event with a given name in a given type.
        //    if ((object)_associatedEventOpt == null)
        //    {
        //        // No locking required since this method will only be called by the thread that created
        //        // the field symbol (and will be called before the field symbol is added to the containing
        //        // type members and available to other threads).
        //        _associatedEventOpt = eventSymbol;
        //    }
        //}

        private void EnsureSignatureIsLoaded()
        {
            if ((object)_lazyType == null)
            {
                var  moduleSymbol = _containingType.ContainingPEModule;
                bool isVolatile;
                ImmutableArray <ModifierInfo <TypeSymbol> > customModifiers;
                TypeSymbol type = (new MetadataDecoder(moduleSymbol, _containingType)).DecodeFieldSignature(_handle, out isVolatile, out customModifiers);
                ImmutableArray <CustomModifier> customModifiersArray = CSharpCustomModifier.Convert(customModifiers);
                //type = DynamicTypeDecoder.TransformType(type, customModifiersArray.Length, _handle, moduleSymbol);
                _lazyIsVolatile = isVolatile;

                TypeSymbol fixedElementType;
                int        fixedSize;
                if (customModifiersArray.IsEmpty && IsFixedBuffer(out fixedSize, out fixedElementType))
                {
                    _lazyFixedSize = fixedSize;
                    _lazyFixedImplementationType = type as NamedTypeSymbol;
                    //type = new PointerTypeSymbol(fixedElementType);
                    throw new NotImplementedException();
                }

                ImmutableInterlocked.InterlockedCompareExchange(ref _lazyCustomModifiers, customModifiersArray, default(ImmutableArray <CustomModifier>));
                Interlocked.CompareExchange(ref _lazyType, type, null);
            }
        }
Пример #2
0
        internal override TypeSymbol MakePointerTypeSymbol(PEModuleSymbol moduleSymbol, TypeSymbol type, ImmutableArray <ModifierInfo <TypeSymbol> > customModifiers)
        {
            if (type is UnsupportedMetadataTypeSymbol)
            {
                return(type);
            }

            return(new PointerTypeSymbol(type, CSharpCustomModifier.Convert(customModifiers)));
        }
Пример #3
0
            public PEParameterSymbolWithCustomModifiers(
                PEModuleSymbol moduleSymbol,
                Symbol containingSymbol,
                int ordinal,
                bool isByRef,
                TypeSymbol type,
                ParameterHandle handle,
                ImmutableArray <ModifierInfo <TypeSymbol> > customModifiers,
                out bool isBad) :
                base(moduleSymbol, containingSymbol, ordinal, isByRef, type, handle, out isBad)
            {
                _customModifiers = CSharpCustomModifier.Convert(customModifiers);

                // TODO: RefCustomModifiers
            }
Пример #4
0
            public PEParameterSymbolWithCustomModifiers(
                PEModuleSymbol moduleSymbol,
                Symbol containingSymbol,
                int ordinal,
                bool isByRef,
                ushort countOfCustomModifiersPrecedingByRef,
                TypeSymbol type,
                ParameterHandle handle,
                ImmutableArray <ModifierInfo <TypeSymbol> > customModifiers,
                out bool isBad) :
                base(moduleSymbol, containingSymbol, ordinal, isByRef, type, handle, customModifiers.Length, out isBad)
            {
                _customModifiers = CSharpCustomModifier.Convert(customModifiers);
                _countOfCustomModifiersPrecedingByRef = countOfCustomModifiersPrecedingByRef;

                Debug.Assert(_countOfCustomModifiersPrecedingByRef == 0 || isByRef);
                Debug.Assert(_countOfCustomModifiersPrecedingByRef <= _customModifiers.Length);
            }
Пример #5
0
        internal override TypeSymbol SubstituteTypeParameters(
            PEModuleSymbol moduleSymbol,
            TypeSymbol genericTypeDef,
            ImmutableArray <KeyValuePair <TypeSymbol, ImmutableArray <ModifierInfo <TypeSymbol> > > > arguments,
            ImmutableArray <bool> refersToNoPiaLocalType)
        {
            if (genericTypeDef is UnsupportedMetadataTypeSymbol)
            {
                return(genericTypeDef);
            }

            // Let's return unsupported metadata type if any argument is unsupported metadata type
            foreach (var arg in arguments)
            {
                if (arg.Key.Kind == SymbolKind.ErrorType &&
                    arg.Key is UnsupportedMetadataTypeSymbol)
                {
                    return(new UnsupportedMetadataTypeSymbol());
                }
            }

            NamedTypeSymbol genericType = (NamedTypeSymbol)genericTypeDef;

            //// See if it is or its enclosing type is a non-interface closed over NoPia local types.
            //ImmutableArray<AssemblySymbol> linkedAssemblies = moduleSymbol.ContainingAssembly.GetLinkedReferencedAssemblies();

            //bool noPiaIllegalGenericInstantiation = false;

            //if (!linkedAssemblies.IsDefaultOrEmpty || moduleSymbol.Module.ContainsNoPiaLocalTypes())
            //{
            //    NamedTypeSymbol typeToCheck = genericType;
            //    int argumentIndex = refersToNoPiaLocalType.Length - 1;

            //    do
            //    {
            //        if (!typeToCheck.IsInterface)
            //        {
            //            break;
            //        }
            //        else
            //        {
            //            argumentIndex -= typeToCheck.Arity;
            //        }

            //        typeToCheck = typeToCheck.ContainingType;
            //    }
            //    while ((object)typeToCheck != null);

            //    for (int i = argumentIndex; i >= 0; i--)
            //    {
            //        if (refersToNoPiaLocalType[i] ||
            //            (!linkedAssemblies.IsDefaultOrEmpty &&
            //            MetadataDecoder.IsOrClosedOverATypeFromAssemblies(arguments[i].Key, linkedAssemblies)))
            //        {
            //            noPiaIllegalGenericInstantiation = true;
            //            break;
            //        }
            //    }
            //}

            // Collect generic parameters for the type and its containers in the order
            // that matches passed in arguments, i.e. sorted by the nesting.
            ImmutableArray <TypeParameterSymbol> typeParameters = genericType.GetAllTypeParameters();

            Debug.Assert(typeParameters.Length > 0);

            if (typeParameters.Length != arguments.Length)
            {
                return(new UnsupportedMetadataTypeSymbol());
            }

            TypeMap substitution = new TypeMap(typeParameters, arguments.SelectAsArray(arg => new TypeWithModifiers(arg.Key, CSharpCustomModifier.Convert(arg.Value))));

            NamedTypeSymbol constructedType = substitution.SubstituteNamedType(genericType);

            //if (noPiaIllegalGenericInstantiation)
            //{
            //    constructedType = new NoPiaIllegalGenericInstantiationSymbol(moduleSymbol, constructedType);
            //}

            return(constructedType);
        }
Пример #6
0
        internal override TypeSymbol GetSZArrayTypeSymbol(PEModuleSymbol moduleSymbol, TypeSymbol elementType, ImmutableArray <ModifierInfo <TypeSymbol> > customModifiers)
        {
            if (elementType is UnsupportedMetadataTypeSymbol)
            {
                return(elementType);
            }

            return(ArrayTypeSymbol.CreateSZArray(moduleSymbol.ContainingAssembly, elementType, CSharpCustomModifier.Convert(customModifiers)));
        }
Пример #7
0
        internal override TypeSymbol GetMDArrayTypeSymbol(PEModuleSymbol moduleSymbol, int rank, TypeSymbol elementType, ImmutableArray <ModifierInfo <TypeSymbol> > customModifiers,
                                                          ImmutableArray <int> sizes, ImmutableArray <int> lowerBounds)
        {
            if (elementType is UnsupportedMetadataTypeSymbol)
            {
                return(elementType);
            }

            return(ArrayTypeSymbol.CreateMDArray(moduleSymbol.ContainingAssembly, elementType, rank, sizes, lowerBounds, CSharpCustomModifier.Convert(customModifiers)));
        }
Пример #8
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;
            }
        }