Esempio n. 1
0
        private void EnsureTypeParametersAreLoaded()
        {
            if (_lazyTypeParameters.IsDefault)
            {
                ImmutableArray <TypeParameterSymbol> typeParams;

                try
                {
                    var moduleSymbol = _containingType.ContainingPEModule;
                    var gpHandles    = moduleSymbol.Module.GetGenericParametersForMethodOrThrow(_handle);

                    if (gpHandles.Count == 0)
                    {
                        typeParams = ImmutableArray <TypeParameterSymbol> .Empty;
                    }
                    else
                    {
                        TypeParameterSymbol[] ownedParams = new PETypeParameterSymbol[gpHandles.Count];

                        for (int i = 0; i < ownedParams.Length; i++)
                        {
                            ownedParams[i] = new PETypeParameterSymbol(moduleSymbol, this, (ushort)i, gpHandles[i]);
                        }

                        typeParams = ImmutableArray.Create <TypeParameterSymbol>(ownedParams);
                    }
                }
                catch (BadImageFormatException)
                {
                    var old = Interlocked.CompareExchange(ref _lazyUseSiteDiagnostic, new CSDiagnosticInfo(ErrorCode.ERR_BindToBogus, this), CSDiagnosticInfo.EmptyErrorInfo);
                    Debug.Assert((object)old == (object)CSDiagnosticInfo.EmptyErrorInfo ||
                                 ((object)old != null && old.Code == (int)ErrorCode.ERR_BindToBogus && old.Arguments.Length == 1 && old.Arguments[0] == (object)this));

                    typeParams = ImmutableArray <TypeParameterSymbol> .Empty;
                }

                ImmutableInterlocked.InterlockedCompareExchange(ref _lazyTypeParameters, typeParams, default(ImmutableArray <TypeParameterSymbol>));
            }
        }
        private void EnsureTypeParametersAreLoaded()
        {
            if (lazyTypeParameters.IsDefault)
            {
                ImmutableArray<TypeParameterSymbol> typeParams;

                try
                {
                    var moduleSymbol = this.containingType.ContainingPEModule;
                    var gpHandles = moduleSymbol.Module.GetGenericParametersForMethodOrThrow(this.handle);

                    if (gpHandles.Count == 0)
                    {
                        typeParams = ImmutableArray<TypeParameterSymbol>.Empty;
                    }
                    else
                    {
                        TypeParameterSymbol[] ownedParams = new PETypeParameterSymbol[gpHandles.Count];

                        for (int i = 0; i < ownedParams.Length; i++)
                        {
                            ownedParams[i] = new PETypeParameterSymbol(moduleSymbol, this, (ushort)i, gpHandles[i]);
                        }

                        typeParams = ImmutableArray.Create<TypeParameterSymbol>(ownedParams);
                    }
                }
                catch (BadImageFormatException)
                {
                    var old = Interlocked.CompareExchange(ref lazyUseSiteDiagnostic, new CSDiagnosticInfo(ErrorCode.ERR_BindToBogus, this), CSDiagnosticInfo.EmptyErrorInfo);
                    Debug.Assert((object)old == (object)CSDiagnosticInfo.EmptyErrorInfo ||
                                    ((object)old != null && old.Code == (int)ErrorCode.ERR_BindToBogus && old.Arguments.Length == 1 && old.Arguments[0] == (object)this));

                    typeParams = ImmutableArray<TypeParameterSymbol>.Empty;
                }

                ImmutableInterlocked.InterlockedCompareExchange(ref lazyTypeParameters, typeParams, default(ImmutableArray<TypeParameterSymbol>));
            }
        }