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


C# TypeSymbol.IsDelegateType方法代码示例

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


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

示例1: GetMethodGroupConversion

        public override Conversion GetMethodGroupConversion(BoundMethodGroup source, TypeSymbol destination, ref HashSet<DiagnosticInfo> useSiteDiagnostics)
        {
            // Must be a bona fide delegate type, not an expression tree type.
            if (!destination.IsDelegateType())
            {
                return Conversion.NoConversion;
            }

            var methodSymbol = GetDelegateInvokeMethodIfAvailable(destination);
            if ((object)methodSymbol == null)
            {
                return Conversion.NoConversion;
            }

            var resolution = ResolveDelegateMethodGroup(_binder, source, methodSymbol, ref useSiteDiagnostics);
            var conversion = (resolution.IsEmpty || resolution.HasAnyErrors) ?
                Conversion.NoConversion :
                ToConversion(resolution.OverloadResolutionResult, resolution.MethodGroup, (NamedTypeSymbol)destination);
            resolution.Free();
            return conversion;
        }
开发者ID:GuilhermeSa,项目名称:roslyn,代码行数:21,代码来源:Conversions.cs

示例2: DoSignaturesMatch

 private static bool DoSignaturesMatch(
     PEModuleSymbol moduleSymbol,
     TypeSymbol eventType,
     PEMethodSymbol addMethod,
     PEMethodSymbol removeMethod)
 {
     return
         (eventType.IsDelegateType() || eventType.IsErrorType()) &&
         DoesSignatureMatch(moduleSymbol, eventType, addMethod) &&
         DoesSignatureMatch(moduleSymbol, eventType, removeMethod) &&
         DoModifiersMatch(addMethod, removeMethod);
 }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:12,代码来源:PEEventSymbol.cs

示例3: IsAnonymousFunctionCompatibleWithType

        public static LambdaConversionResult IsAnonymousFunctionCompatibleWithType(UnboundLambda anonymousFunction, TypeSymbol type)
        {
            Debug.Assert((object)anonymousFunction != null);
            Debug.Assert((object)type != null);

            if (type.IsDelegateType())
            {
                return IsAnonymousFunctionCompatibleWithDelegate(anonymousFunction, type);
            }
            else if (type.IsExpressionTree())
            {
                return IsAnonymousFunctionCompatibleWithExpressionTree(anonymousFunction, (NamedTypeSymbol)type);
            }

            return LambdaConversionResult.BadTargetType;
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:16,代码来源:Conversions.cs

示例4: IsVarianceCast

        // Although III.1.8.1.3 seems to imply that verifier understands variance casts.
        // It appears that verifier/JIT gets easily confused. 
        // So to not rely on whether that should work or not we will flag potentially 
        // "complicated" casts and make them static casts to ensure we are all on 
        // the same page with what type should be tracked.
        private static bool IsVarianceCast(TypeSymbol to, TypeSymbol from)
        {
            if (to == from)
            {
                return false;
            }

            if ((object)from == null)
            {
                // from unknown type - this could be a variance conversion.
                return true;
            }

            // while technically variance casts, array conversions do not seem to be a problem
            // unless the element types are converted via variance.
            if (to.IsArray())
            {
                return IsVarianceCast(((ArrayTypeSymbol)to).ElementType, ((ArrayTypeSymbol)from).ElementType);
            }

            return (to.IsDelegateType() && to != from) ||
                   (to.IsInterfaceType() && from.IsInterfaceType() && !from.InterfacesAndTheirBaseInterfacesNoUseSiteDiagnostics.Contains((NamedTypeSymbol)to));
        }
开发者ID:tvsonar,项目名称:roslyn,代码行数:28,代码来源:EmitExpression.cs

示例5: GenerateImplicitConversionError

        protected void GenerateImplicitConversionError(DiagnosticBag diagnostics, CSharpSyntaxNode syntax,
            Conversion conversion, BoundExpression expression, TypeSymbol targetType)
        {
            Debug.Assert(expression != null);
            Debug.Assert((object)targetType != null);

            if (targetType.TypeKind == TypeKind.Error)
            {
                return;
            }

            if (expression.Kind == BoundKind.BadExpression)
            {
                return;
            }

            if (expression.Kind == BoundKind.UnboundLambda)
            {
                GenerateAnonymousFunctionConversionError(diagnostics, syntax, (UnboundLambda)expression, targetType);
                return;
            }

            var sourceType = expression.Type;
            if ((object)sourceType != null)
            {
                GenerateImplicitConversionError(diagnostics, this.Compilation, syntax, conversion, sourceType, targetType, expression.ConstantValue);
                return;
            }

            if (expression.IsLiteralNull())
            {
                if (targetType.TypeKind == TypeKind.TypeParameter)
                {
                    Error(diagnostics, ErrorCode.ERR_TypeVarCantBeNull, syntax, targetType);
                    return;
                }
                if (targetType.IsValueType)
                {
                    Error(diagnostics, ErrorCode.ERR_ValueCantBeNull, syntax, targetType);
                    return;
                }
            }

            if (expression.Kind == BoundKind.MethodGroup)
            {
                var methodGroup = (BoundMethodGroup)expression;
                if (!Conversions.ReportDelegateMethodGroupDiagnostics(this, methodGroup, targetType, diagnostics))
                {
                    var nodeForSquiggle = syntax;
                    while (nodeForSquiggle.Kind() == SyntaxKind.ParenthesizedExpression)
                    {
                        nodeForSquiggle = ((ParenthesizedExpressionSyntax)nodeForSquiggle).Expression;
                    }

                    if (nodeForSquiggle.Kind() == SyntaxKind.SimpleMemberAccessExpression || nodeForSquiggle.Kind() == SyntaxKind.PointerMemberAccessExpression)
                    {
                        nodeForSquiggle = ((MemberAccessExpressionSyntax)nodeForSquiggle).Name;
                    }

                    var location = nodeForSquiggle.Location;

                    if (ReportDelegateInvokeUseSiteDiagnostic(diagnostics, targetType, location))
                    {
                        return;
                    }

                    Error(diagnostics,
                        targetType.IsDelegateType() ? ErrorCode.ERR_MethDelegateMismatch : ErrorCode.ERR_MethGrpToNonDel,
                        location, methodGroup.Name, targetType);
                }

                return;
            }

            Debug.Assert(expression.HasAnyErrors && expression.Kind != BoundKind.UnboundLambda, "Missing a case in implicit conversion error reporting");
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:76,代码来源:Binder_Statements.cs

示例6: GenerateImplicitConversionError

        protected void GenerateImplicitConversionError(
            DiagnosticBag diagnostics, 
            CSharpSyntaxNode syntax,
            Conversion conversion, 
            BoundExpression operand, 
            TypeSymbol targetType)
        {
            Debug.Assert(operand != null);
            Debug.Assert((object)targetType != null);

            if (targetType.TypeKind == TypeKind.Error)
            {
                return;
            }

            if (operand.Kind == BoundKind.BadExpression)
            {
                return;
            }

            if (operand.Kind == BoundKind.UnboundLambda)
            {
                GenerateAnonymousFunctionConversionError(diagnostics, syntax, (UnboundLambda)operand, targetType);
                return;
            }

            if (operand.Kind == BoundKind.TupleLiteral)
            {
                var tuple = (BoundTupleLiteral)operand;
                var targetElementTypes = default(ImmutableArray<TypeSymbol>);

                // If target is a tuple or compatible type with the same number of elements,
                // report errors for tuple arguments that failed to convert, which would be more useful.
                if (targetType.TryGetElementTypesIfTupleOrCompatible(out targetElementTypes) && 
                    targetElementTypes.Length == tuple.Arguments.Length)
                {
                    GenerateImplicitConversionErrorsForTupleLiteralArguments(diagnostics, tuple.Arguments, targetElementTypes);
                    return;
                }

                // target is not compatible with source and source does not have a type
                if ((object)tuple.Type == null)
                {
                    Error(diagnostics, ErrorCode.ERR_ConversionNotTupleCompatible, syntax, tuple.Arguments.Length, targetType);
                    return;
                }

                // Otherwise it is just a regular conversion failure from T1 to T2.
            }

            var sourceType = operand.Type;
            if ((object)sourceType != null)
            {
                GenerateImplicitConversionError(diagnostics, this.Compilation, syntax, conversion, sourceType, targetType, operand.ConstantValue);
                return;
            }
            
            if (operand.IsLiteralNull())
            {
                if (targetType.TypeKind == TypeKind.TypeParameter)
                {
                    Error(diagnostics, ErrorCode.ERR_TypeVarCantBeNull, syntax, targetType);
                    return;
                }
                if (targetType.IsValueType)
                {
                    Error(diagnostics, ErrorCode.ERR_ValueCantBeNull, syntax, targetType);
                    return;
                }
            }

            if (operand.Kind == BoundKind.MethodGroup)
            {
                var methodGroup = (BoundMethodGroup)operand;
                if (!Conversions.ReportDelegateMethodGroupDiagnostics(this, methodGroup, targetType, diagnostics))
                {
                    var nodeForSquiggle = syntax;
                    while (nodeForSquiggle.Kind() == SyntaxKind.ParenthesizedExpression)
                    {
                        nodeForSquiggle = ((ParenthesizedExpressionSyntax)nodeForSquiggle).Expression;
                    }

                    if (nodeForSquiggle.Kind() == SyntaxKind.SimpleMemberAccessExpression || nodeForSquiggle.Kind() == SyntaxKind.PointerMemberAccessExpression)
                    {
                        nodeForSquiggle = ((MemberAccessExpressionSyntax)nodeForSquiggle).Name;
                    }

                    var location = nodeForSquiggle.Location;

                    if (ReportDelegateInvokeUseSiteDiagnostic(diagnostics, targetType, location))
                    {
                        return;
                    }

                    Error(diagnostics,
                        targetType.IsDelegateType() ? ErrorCode.ERR_MethDelegateMismatch : ErrorCode.ERR_MethGrpToNonDel,
                        location, methodGroup.Name, targetType);
                }

                return;
//.........这里部分代码省略.........
开发者ID:abock,项目名称:roslyn,代码行数:101,代码来源:Binder_Statements.cs

示例7: TestBinaryIntrinsicSymbol


//.........这里部分代码省略.........
                Assert.NotEqual(symbol1.Parameters[0], symbol5.Parameters[1]);
            }

            switch (op)
            {
                case BinaryOperatorKind.LogicalAnd:
                case BinaryOperatorKind.LogicalOr:
                    Assert.Null(symbol1);
                    Assert.Null(symbol2);
                    Assert.Null(symbol3);
                    Assert.Null(symbol4);
                    return;
            }


            BinaryOperatorKind result = OverloadResolution.BinopEasyOut.OpKind(op, leftType, rightType);
            BinaryOperatorSignature signature;
            bool isDynamic = (leftType.IsDynamic() || rightType.IsDynamic());

            if (result == BinaryOperatorKind.Error)
            {
                if (leftType.IsDynamic() && !rightType.IsPointerType() && !rightType.IsRestrictedType())
                {
                    signature = new BinaryOperatorSignature(op | BinaryOperatorKind.Dynamic, leftType, rightType, leftType);
                }
                else if (rightType.IsDynamic() && !leftType.IsPointerType() && !leftType.IsRestrictedType())
                {
                    signature = new BinaryOperatorSignature(op | BinaryOperatorKind.Dynamic, leftType, rightType, rightType);
                }
                else if ((op == BinaryOperatorKind.Equal || op == BinaryOperatorKind.NotEqual) &&
                    leftType.IsReferenceType && rightType.IsReferenceType &&
                    (leftType == rightType || compilation.Conversions.ClassifyConversion(leftType, rightType, ref useSiteDiagnostics).IsReference))
                {
                    if (leftType.IsDelegateType() && rightType.IsDelegateType())
                    {
                        Assert.Equal(leftType, rightType);
                        signature = new BinaryOperatorSignature(op | BinaryOperatorKind.Delegate,
                            leftType, // TODO: this feels like a spec violation
                            leftType, // TODO: this feels like a spec violation
                            compilation.GetSpecialType(SpecialType.System_Boolean));
                    }
                    else if (leftType.SpecialType == SpecialType.System_Delegate && rightType.SpecialType == SpecialType.System_Delegate)
                    {
                        signature = new BinaryOperatorSignature(op | BinaryOperatorKind.Delegate,
                            compilation.GetSpecialType(SpecialType.System_Delegate), compilation.GetSpecialType(SpecialType.System_Delegate),
                            compilation.GetSpecialType(SpecialType.System_Boolean));
                    }
                    else
                    {
                        signature = new BinaryOperatorSignature(op | BinaryOperatorKind.Object, compilation.ObjectType, compilation.ObjectType,
                            compilation.GetSpecialType(SpecialType.System_Boolean));
                    }
                }
                else if (op == BinaryOperatorKind.Addition &&
                    ((leftType.IsStringType() && !rightType.IsPointerType()) || (!leftType.IsPointerType() && rightType.IsStringType())))
                {
                    Assert.False(leftType.IsStringType() && rightType.IsStringType());

                    if (leftType.IsStringType())
                    {
                        signature = new BinaryOperatorSignature(op | BinaryOperatorKind.String, leftType, compilation.ObjectType, leftType);
                    }
                    else
                    {
                        Assert.True(rightType.IsStringType());
                        signature = new BinaryOperatorSignature(op | BinaryOperatorKind.String, compilation.ObjectType, rightType, rightType);
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:67,代码来源:OperatorTests.cs


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