当前位置: 首页>>代码示例>>C#>>正文


C# Binder.BindType方法代码示例

本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Binder.BindType方法的典型用法代码示例。如果您正苦于以下问题:C# Binder.BindType方法的具体用法?C# Binder.BindType怎么用?C# Binder.BindType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.CodeAnalysis.CSharp.Binder的用法示例。


在下文中一共展示了Binder.BindType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetSpeculativelyBoundExpression

        /// <summary>
        /// Bind the given expression speculatively at the given position, and return back
        /// the resulting bound node. May return null in some error cases.
        /// </summary>
        /// <remarks>
        /// Keep in sync with Binder.BindCrefParameterOrReturnType.
        /// </remarks>
        private BoundExpression GetSpeculativelyBoundExpression(int position, ExpressionSyntax expression, SpeculativeBindingOption bindingOption, out Binder binder, out ImmutableArray<Symbol> crefSymbols)
        {
            if (expression == null)
            {
                throw new ArgumentNullException(nameof(expression));
            }

            crefSymbols = default(ImmutableArray<Symbol>);

            expression = SyntaxFactory.GetStandaloneExpression(expression);

            binder = this.GetSpeculativeBinder(position, expression, bindingOption);
            if (binder == null)
            {
                return null;
            }

            if (binder.Flags.Includes(BinderFlags.CrefParameterOrReturnType))
            {
                var unusedDiagnostics = DiagnosticBag.GetInstance();
                crefSymbols = ImmutableArray.Create<Symbol>(binder.BindType(expression, unusedDiagnostics));
                unusedDiagnostics.Free();
                return null;
            }
            else if (binder.InCref)
            {
                if (expression.IsKind(SyntaxKind.QualifiedName))
                {
                    var qualified = (QualifiedNameSyntax)expression;
                    var crefWrapper = SyntaxFactory.QualifiedCref(qualified.Left, SyntaxFactory.NameMemberCref(qualified.Right));
                    crefSymbols = BindCref(crefWrapper, binder);
                }
                else
                {
                    var typeSyntax = expression as TypeSyntax;
                    if (typeSyntax != null)
                    {
                        var crefWrapper = typeSyntax is PredefinedTypeSyntax ?
                            (CrefSyntax)SyntaxFactory.TypeCref(typeSyntax) :
                            SyntaxFactory.NameMemberCref(typeSyntax);
                        crefSymbols = BindCref(crefWrapper, binder);
                    }
                }
                return null;
            }

            var diagnostics = DiagnosticBag.GetInstance();
            var boundNode = GetSpeculativelyBoundExpressionHelper(binder, expression, bindingOption, diagnostics);
            diagnostics.Free();
            return boundNode;
        }
开发者ID:,项目名称:,代码行数:58,代码来源:

示例2: GetSpeculativelyBoundAttribute

        /// <summary>
        /// Bind the given attribute speculatively at the given position, and return back
        /// the resulting bound node. May return null in some error cases.
        /// </summary>
        private BoundAttribute GetSpeculativelyBoundAttribute(int position, AttributeSyntax attribute, out Binder binder)
        {
            if (attribute == null)
            {
                throw new ArgumentNullException(nameof(attribute));
            }

            binder = this.GetSpeculativeBinderForAttribute(position);
            if (binder == null)
            {
                return null;
            }

            var diagnostics = DiagnosticBag.GetInstance();
            AliasSymbol aliasOpt; // not needed.
            NamedTypeSymbol attributeType = (NamedTypeSymbol)binder.BindType(attribute.Name, diagnostics, out aliasOpt);
            var boundNode = new ExecutableCodeBinder(attribute, binder.ContainingMemberOrLambda, binder).BindAttribute(attribute, attributeType, diagnostics);
            diagnostics.Free();

            return boundNode;
        }
开发者ID:,项目名称:,代码行数:25,代码来源:

示例3: CanBeValidAttributeArgument

        /// <remarks>
        /// Since this method is expected to be called on every nested expression of the argument, it doesn't
        /// need to recurse (directly).
        /// </remarks>
        internal static bool CanBeValidAttributeArgument(ExpressionSyntax node, Binder typeBinder)
        {
            Debug.Assert(node != null);
            switch (node.Kind)
            {
                // ObjectCreationExpression for primitive types, such as "new int()", are treated as constants and allowed in attribute arguments.
                case SyntaxKind.ObjectCreationExpression:
                    {
                        var objectCreation = (ObjectCreationExpressionSyntax)node;
                        if (objectCreation.Initializer == null)
                        {
                            var unusedDiagnostics = DiagnosticBag.GetInstance();
                            var type = typeBinder.BindType(objectCreation.Type, unusedDiagnostics);
                            unusedDiagnostics.Free();

                            var kind = TypedConstant.GetTypedConstantKind(type, typeBinder.Compilation);
                            switch (kind)
                            {
                                case TypedConstantKind.Primitive:
                                case TypedConstantKind.Enum:
                                    switch (type.TypeKind)
                                    {
                                        case TypeKind.Struct:
                                        case TypeKind.Class:
                                        case TypeKind.Enum:
                                            return true;
                                        default:
                                            return false;
                                    }
                            }
                        }

                        return false;
                    }

                // sizeof(int)
                case SyntaxKind.SizeOfExpression:

                // typeof(int)
                case SyntaxKind.TypeOfExpression:

                // constant expressions

                // SPEC:    Section 7.19: Only the following constructs are permitted in constant expressions:

                //  Literals (including the null literal).
                case SyntaxKind.NumericLiteralExpression:
                case SyntaxKind.StringLiteralExpression:
                case SyntaxKind.CharacterLiteralExpression:
                case SyntaxKind.TrueLiteralExpression:
                case SyntaxKind.FalseLiteralExpression:
                case SyntaxKind.NullLiteralExpression:

                //  References to const members of class and struct types.
                //  References to members of enumeration types.
                case SyntaxKind.IdentifierName:
                case SyntaxKind.GenericName:
                case SyntaxKind.AliasQualifiedName:
                case SyntaxKind.QualifiedName:
                case SyntaxKind.PredefinedType:
                case SyntaxKind.SimpleMemberAccessExpression:

                //  References to const parameters or local variables. Not valid for attribute arguments, so skipped here.

                //  Parenthesized sub-expressions, which are themselves constant expressions.
                case SyntaxKind.ParenthesizedExpression:

                //  Cast expressions, provided the target type is one of the types listed above.
                case SyntaxKind.CastExpression:

                //  checked and unchecked expressions
                case SyntaxKind.UncheckedExpression:
                case SyntaxKind.CheckedExpression:

                //  Default value expressions
                case SyntaxKind.DefaultExpression:

                //  The predefined +, –, !, and ~ unary operators.
                case SyntaxKind.UnaryPlusExpression:
                case SyntaxKind.UnaryMinusExpression:
                case SyntaxKind.LogicalNotExpression:
                case SyntaxKind.BitwiseNotExpression:

                //  The predefined +, –, *, /, %, <<, >>, &, |, ^, &&, ||, ==, !=, <, >, <=, and >= binary operators, provided each operand is of a type listed above.
                case SyntaxKind.AddExpression:
                case SyntaxKind.MultiplyExpression:
                case SyntaxKind.SubtractExpression:
                case SyntaxKind.DivideExpression:
                case SyntaxKind.ModuloExpression:
                case SyntaxKind.LeftShiftExpression:
                case SyntaxKind.RightShiftExpression:
                case SyntaxKind.BitwiseAndExpression:
                case SyntaxKind.BitwiseOrExpression:
                case SyntaxKind.ExclusiveOrExpression:
                case SyntaxKind.LogicalAndExpression:
                case SyntaxKind.LogicalOrExpression:
//.........这里部分代码省略.........
开发者ID:EkardNT,项目名称:Roslyn,代码行数:101,代码来源:EarlyWellKnownAttributeBinder.cs


注:本文中的Microsoft.CodeAnalysis.CSharp.Binder.BindType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。