コード例 #1
0
        public void TestTake()
        {
            var zero = IndexedTypeParameterSymbol.TakeSymbols(0);

            Assert.Equal(0, zero.Length);

            var five = IndexedTypeParameterSymbol.TakeSymbols(5);

            Assert.Equal(5, five.Length);
            Assert.Equal(five[0], IndexedTypeParameterSymbol.GetTypeParameter(0));
            Assert.Equal(five[1], IndexedTypeParameterSymbol.GetTypeParameter(1));
            Assert.Equal(five[2], IndexedTypeParameterSymbol.GetTypeParameter(2));
            Assert.Equal(five[3], IndexedTypeParameterSymbol.GetTypeParameter(3));
            Assert.Equal(five[4], IndexedTypeParameterSymbol.GetTypeParameter(4));

            var fifty = IndexedTypeParameterSymbol.TakeSymbols(50);

            Assert.Equal(50, fifty.Length);

            // prove they are all unique
            var set = new HashSet <TypeParameterSymbol>(fifty);

            Assert.Equal(50, set.Count);

            var fiveHundred = IndexedTypeParameterSymbol.TakeSymbols(500);

            Assert.Equal(500, fiveHundred.Length);
        }
コード例 #2
0
 /// <summary>
 /// We know that we'll never have a method context because that's what we're
 /// trying to find.  Instead, just return an indexed type parameter that will
 /// make comparison easier.
 /// </summary>
 /// <param name="position"></param>
 /// <returns></returns>
 protected override TypeSymbol GetGenericMethodTypeParamSymbol(int position)
 {
     // Note: technically this is a source symbol, but we only care about the position
     return(IndexedTypeParameterSymbol.GetTypeParameter(position));
 }
コード例 #3
0
        private MethodMemberBuilder(NamedTypeSymbol container, Binder enclosing, MemberDeclarationSyntax syntax, DiagnosticBag diagnostics)
            : base(enclosing.Location(syntax) as SourceLocation, container, enclosing)
        {
            Debug.Assert(syntax != null);
            this.syntax = syntax;

            // Make a binder context in which each type parameter binds to a corresponding numbered type parameter
            Binder parametersContext = Enclosing;

            if (syntax.Kind == SyntaxKind.MethodDeclaration)
            {
                var methodSyntax = syntax as MethodDeclarationSyntax;
                int arity        = methodSyntax.Arity;
                if (arity != 0)
                {
                    var typeParamMap = new MultiDictionary <string, TypeParameterSymbol>();
                    var typeParams   = methodSyntax.TypeParameterListOpt.Parameters;

                    for (int iParam = 0; iParam < typeParams.Count; iParam++)
                    {
                        var arg    = typeParams[iParam];
                        var symbol = IndexedTypeParameterSymbol.GetTypeParameter(iParam);
                        typeParamMap.Add(arg.Identifier.ValueText, symbol);
                    }

                    parametersContext = new WithDummyTypeParametersBinder(typeParamMap, Enclosing);
                }

                if (methodSyntax.ExplicitInterfaceSpecifierOpt != null)
                {
                    this.explicitInterfaceType = enclosing.BindType(methodSyntax.ExplicitInterfaceSpecifierOpt.Name, diagnostics);
                }
            }

            // TODOngafter 1: recast this code using ReadOnlyArray.
            IEnumerable <ParameterSyntax> parameters = SyntaxParameters.HasValue ? SyntaxParameters.Value : SpecializedCollections.EmptyEnumerable <ParameterSyntax>();

            declaredParameterTypes = parameters.Select(p =>
            {
                if (p.TypeOpt == null)
                {
                    return(new CSErrorTypeSymbol(enclosing.Compilation.GlobalNamespace, "ErrorType", 0, diagnostics.Add(ErrorCode.ERR_NotYetImplementedInRoslyn, new SourceLocation(Tree, p))));
                }
                return(parametersContext.BindType(p.TypeOpt, diagnostics));
            }).ToList();

            var parameterRefs = parameters.Select(p => p.Modifiers.GetRefKind()).ToList();

            switch (syntax.Kind)
            {
            case SyntaxKind.ConstructorDeclaration:
                Binder original = parametersContext;     // TODOngafter 1: worry about diagnostic reporting and suppression here.
                declaredReturnType = Enclosing.GetSpecialType(SpecialType.System_Void, diagnostics, syntax);
                break;

            default:
                declaredReturnType = parametersContext.BindType(SyntaxReturnType, diagnostics);
                break;
            }

            TypeSymbol explType   = null;
            var        explSyntax = ExplicitInterface;

            if (explSyntax != null)
            {
                explType = parametersContext.BindType(explSyntax, diagnostics);
            }

            // TODOngafter 3: map dynamic->object for the signature
            this.signature = new MethodSignature(Name, SyntaxArity, declaredParameterTypes, parameterRefs, explType);
        }