• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Resolver.OverloadResolution类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ICSharpCode.NRefactory.CSharp.Resolver.OverloadResolution的典型用法代码示例。如果您正苦于以下问题:C# OverloadResolution类的具体用法?C# OverloadResolution怎么用?C# OverloadResolution使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



OverloadResolution类属于ICSharpCode.NRefactory.CSharp.Resolver命名空间,在下文中一共展示了OverloadResolution类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: LessArgumentsPassedToParamsIsBetter

 public void LessArgumentsPassedToParamsIsBetter()
 {
     OverloadResolution r = new OverloadResolution(context, MakeArgumentList(typeof(int), typeof(int), typeof(int)));
     Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(MakeParamsMethod(typeof(int[]))));
     Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(MakeParamsMethod(typeof(int), typeof(int[]))));
     Assert.IsFalse(r.IsAmbiguous);
     Assert.AreEqual(2, r.BestCandidate.Parameters.Count);
 }
开发者ID:richardschneider,项目名称:ILSpy,代码行数:8,代码来源:OverloadResolutionTests.cs


示例2: PreferIntOverUInt

		public void PreferIntOverUInt()
		{
			OverloadResolution r = new OverloadResolution(compilation, MakeArgumentList(typeof(ushort)));
			var c1 = MakeMethod(typeof(int));
			Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(c1));
			Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(MakeMethod(typeof(uint))));
			Assert.IsFalse(r.IsAmbiguous);
			Assert.AreSame(c1, r.BestCandidate);
		}
开发者ID:sphynx79,项目名称:dotfiles,代码行数:9,代码来源:OverloadResolutionTests.cs


示例3: NullableIntAndNullableUIntIsAmbiguous

        public void NullableIntAndNullableUIntIsAmbiguous()
        {
            OverloadResolution r = new OverloadResolution(context, MakeArgumentList(typeof(ushort?)));
            Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(MakeMethod(typeof(int?))));
            Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(MakeMethod(typeof(uint?))));
            Assert.AreEqual(OverloadResolutionErrors.AmbiguousMatch, r.BestCandidateErrors);

            // then adding a matching overload solves the ambiguity:
            Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(MakeMethod(typeof(ushort?))));
            Assert.AreEqual(OverloadResolutionErrors.None, r.BestCandidateErrors);
            Assert.IsNull(r.BestCandidateAmbiguousWith);
        }
开发者ID:richardschneider,项目名称:ILSpy,代码行数:12,代码来源:OverloadResolutionTests.cs


示例4: InvocationResolveResult

		public InvocationResolveResult(ResolveResult targetResult, OverloadResolution or, ITypeResolveContext context)
			: base(
				or.IsExtensionMethodInvocation ? null : targetResult,
				or.GetBestCandidateWithSubstitutedTypeArguments(),
				context)
		{
			this.OverloadResolutionErrors = or.BestCandidateErrors;
			this.argumentToParameterMap = or.GetArgumentToParameterMap();
			this.Arguments = or.GetArgumentsWithConversions();
			
			this.IsExtensionMethodInvocation = or.IsExtensionMethodInvocation;
			this.IsExpandedForm = or.BestCandidateIsExpandedForm;
			this.IsLiftedOperatorInvocation = or.BestCandidate is OverloadResolution.ILiftedOperator;
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:14,代码来源:InvocationResolveResult.cs


示例5: BetterConversionByLambdaReturnValue_ExpressionTree

        public void BetterConversionByLambdaReturnValue_ExpressionTree()
        {
            var m1 = MakeMethod(typeof(Func<long>));
            var m2 = MakeMethod(typeof(Expression<Func<int>>));

            // M(() => default(byte));
            ResolveResult[] args = {
                new MockLambda(compilation.FindType(KnownTypeCode.Byte))
            };

            OverloadResolution r = new OverloadResolution(compilation, args);
            Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(m1));
            Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(m2));
            Assert.AreSame(m2, r.BestCandidate);
            Assert.AreEqual(OverloadResolutionErrors.None, r.BestCandidateErrors);
        }
开发者ID:svermeulen,项目名称:NRefactory,代码行数:16,代码来源:OverloadResolutionTests.cs


示例6: Lambda_DelegateAndExpressionTreeOverloadsAreAmbiguous

		public void Lambda_DelegateAndExpressionTreeOverloadsAreAmbiguous()
		{
			var m1 = MakeMethod(typeof(Func<int>));
			var m2 = MakeMethod(typeof(Expression<Func<int>>));
			
			// M(() => default(int));
			ResolveResult[] args = {
				new MockLambda(compilation.FindType(KnownTypeCode.Int32))
			};
			
			OverloadResolution r = new OverloadResolution(compilation, args);
			Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(m1));
			Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(m2));
			Assert.AreEqual(OverloadResolutionErrors.AmbiguousMatch, r.BestCandidateErrors);
		}
开发者ID:sphynx79,项目名称:dotfiles,代码行数:15,代码来源:OverloadResolutionTests.cs


示例7: SkeetEvilOverloadResolution

		public void SkeetEvilOverloadResolution()
		{
			// http://msmvps.com/blogs/jon_skeet/archive/2010/11/02/evil-code-overload-resolution-workaround.aspx
			
			// static void Foo<T>(T? ignored = default(T?)) where T : struct
			var m1 = MakeUnresolvedMethod();
			m1.TypeParameters.Add(new DefaultUnresolvedTypeParameter(SymbolKind.Method, 0, "T") { HasValueTypeConstraint = true });
			m1.Parameters.Add(MakeOptionalParameter(
				NullableType.Create(new TypeParameterReference(SymbolKind.Method, 0)),
				"ignored"
			));
			
			// class ClassConstraint<T> where T : class {}
			var classConstraint = new DefaultUnresolvedTypeDefinition(string.Empty, "ClassConstraint");
			classConstraint.TypeParameters.Add(new DefaultUnresolvedTypeParameter(SymbolKind.TypeDefinition, 0, "T") { HasReferenceTypeConstraint = true });
			
			// static void Foo<T>(ClassConstraint<T> ignored = default(ClassConstraint<T>))
			// where T : class
			var m2 = MakeUnresolvedMethod();
			m2.TypeParameters.Add(new DefaultUnresolvedTypeParameter(SymbolKind.Method, 0, "T") { HasReferenceTypeConstraint = true });
			m2.Parameters.Add(MakeOptionalParameter(
				new ParameterizedTypeReference(classConstraint, new[] { new TypeParameterReference(SymbolKind.Method, 0) }),
				"ignored"
			));
			
			// static void Foo<T>()
			var m3 = MakeUnresolvedMethod();
			m3.TypeParameters.Add(new DefaultUnresolvedTypeParameter(SymbolKind.Method, 0, "T"));
			
			ICompilation compilation = TypeSystemHelper.CreateCompilation(classConstraint);
			var context = new SimpleTypeResolveContext(compilation.MainAssembly);
			IMethod resolvedM1 = (IMethod)m1.CreateResolved(context);
			IMethod resolvedM2 = (IMethod)m2.CreateResolved(context);
			IMethod resolvedM3 = (IMethod)m3.CreateResolved(context);
			
			// Call: Foo<int>();
			OverloadResolution o;
			o = new OverloadResolution(compilation, new ResolveResult[0], typeArguments: new[] { compilation.FindType(typeof(int)) });
			Assert.AreEqual(OverloadResolutionErrors.None, o.AddCandidate(resolvedM1));
			Assert.AreEqual(OverloadResolutionErrors.ConstructedTypeDoesNotSatisfyConstraint, o.AddCandidate(resolvedM2));
			Assert.AreSame(resolvedM1, o.BestCandidate);
			
			// Call: Foo<string>();
			o = new OverloadResolution(compilation, new ResolveResult[0], typeArguments: new[] { compilation.FindType(typeof(string)) });
			Assert.AreEqual(OverloadResolutionErrors.ConstructedTypeDoesNotSatisfyConstraint, o.AddCandidate(resolvedM1));
			Assert.AreEqual(OverloadResolutionErrors.None, o.AddCandidate(resolvedM2));
			Assert.AreSame(resolvedM2, o.BestCandidate);
			
			// Call: Foo<int?>();
			o = new OverloadResolution(compilation, new ResolveResult[0], typeArguments: new[] { compilation.FindType(typeof(int?)) });
			Assert.AreEqual(OverloadResolutionErrors.ConstructedTypeDoesNotSatisfyConstraint, o.AddCandidate(resolvedM1));
			Assert.AreEqual(OverloadResolutionErrors.ConstructedTypeDoesNotSatisfyConstraint, o.AddCandidate(resolvedM2));
			Assert.AreEqual(OverloadResolutionErrors.None, o.AddCandidate(resolvedM3));
			Assert.AreSame(resolvedM3, o.BestCandidate);
		}
开发者ID:sphynx79,项目名称:dotfiles,代码行数:55,代码来源:OverloadResolutionTests.cs


示例8: PreferMethodWithoutOptionalParameters

		public void PreferMethodWithoutOptionalParameters()
		{
			var m1 = MakeMethod();
			var m2 = MakeMethod(1);
			
			OverloadResolution r = new OverloadResolution(compilation, MakeArgumentList());
			Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(m1));
			Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(m2));
			Assert.IsFalse(r.IsAmbiguous);
			Assert.AreSame(m1, r.BestCandidate);
		}
开发者ID:sphynx79,项目名称:dotfiles,代码行数:11,代码来源:OverloadResolutionTests.cs


示例9: ResolveIndexer

        /// <summary>
        /// Resolves an indexer access.
        /// </summary>
        /// <param name="target">Target expression.</param>
        /// <param name="arguments">
        /// Arguments passed to the indexer.
        /// The resolver may mutate this array to wrap elements in <see cref="ConversionResolveResult"/>s!
        /// </param>
        /// <param name="argumentNames">
        /// The argument names. Pass the null string for positional arguments.
        /// </param>
        /// <returns>ArrayAccessResolveResult, InvocationResolveResult, or ErrorResolveResult</returns>
        public ResolveResult ResolveIndexer(ResolveResult target, ResolveResult[] arguments, string[] argumentNames = null)
        {
            switch (target.Type.Kind) {
                case TypeKind.Dynamic:
                    for (int i = 0; i < arguments.Length; i++) {
                        arguments[i] = Convert(arguments[i], SpecialType.Dynamic);
                    }
                    return new ArrayAccessResolveResult(SpecialType.Dynamic, target, arguments);

                case TypeKind.Array:
                case TypeKind.Pointer:
                    // §7.6.6.1 Array access / §18.5.3 Pointer element access
                    AdjustArrayAccessArguments(arguments);
                    return new ArrayAccessResolveResult(((TypeWithElementType)target.Type).ElementType, target, arguments);
            }

            // §7.6.6.2 Indexer access
            OverloadResolution or = new OverloadResolution(compilation, arguments, argumentNames, conversions: conversions);
            MemberLookup lookup = CreateMemberLookup();
            var indexers = lookup.LookupIndexers(target.Type);
            or.AddMethodLists(indexers);
            if (or.BestCandidate != null) {
                return or.CreateResolveResult(target);
            } else {
                return ErrorResult;
            }
        }
开发者ID:holmak,项目名称:NRefactory,代码行数:39,代码来源:CSharpResolver.cs


示例10: CreateResolveResultForUserDefinedOperator

 ResolveResult CreateResolveResultForUserDefinedOperator(OverloadResolution r)
 {
     return r.CreateResolveResult(null);
 }
开发者ID:holmak,项目名称:NRefactory,代码行数:4,代码来源:CSharpResolver.cs


示例11: ResolveObjectCreation

 /// <summary>
 /// Resolves an object creation.
 /// </summary>
 /// <param name="type">Type of the object to create.</param>
 /// <param name="arguments">
 /// Arguments passed to the constructor.
 /// The resolver may mutate this array to wrap elements in <see cref="ConversionResolveResult"/>s!
 /// </param>
 /// <param name="argumentNames">
 /// The argument names. Pass the null string for positional arguments.
 /// </param>
 /// <param name="allowProtectedAccess">
 /// Whether to allow calling protected constructors.
 /// This should be false except when resolving constructor initializers.
 /// </param>
 /// <returns>InvocationResolveResult or ErrorResolveResult</returns>
 public ResolveResult ResolveObjectCreation(IType type, ResolveResult[] arguments, string[] argumentNames = null, bool allowProtectedAccess = false)
 {
     if (type.Kind == TypeKind.Delegate && arguments.Length == 1) {
         return Convert(arguments[0], type);
     }
     OverloadResolution or = new OverloadResolution(compilation, arguments, argumentNames, conversions: conversions);
     MemberLookup lookup = CreateMemberLookup();
     foreach (IMethod ctor in type.GetConstructors()) {
         if (lookup.IsAccessible(ctor, allowProtectedAccess))
             or.AddCandidate(ctor);
         else
             or.AddCandidate(ctor, OverloadResolutionErrors.Inaccessible);
     }
     if (or.BestCandidate != null) {
         return or.CreateResolveResult(null);
     } else {
         return new ErrorResolveResult(type);
     }
 }
开发者ID:holmak,项目名称:NRefactory,代码行数:35,代码来源:CSharpResolver.cs


示例12: SkeetEvilOverloadResolution

        public void SkeetEvilOverloadResolution()
        {
            // http://msmvps.com/blogs/jon_skeet/archive/2010/11/02/evil-code-overload-resolution-workaround.aspx

            // static void Foo<T>(T? ignored = default(T?)) where T : struct
            var m1 = MakeMethod();
            m1.TypeParameters.Add(new DefaultTypeParameter(m1, 0, "T") { HasValueTypeConstraint = true });
            m1.Parameters.Add(MakeOptionalParameter(
                NullableType.Create(m1.TypeParameters[0], context),
                "ignored"
            ));

            // class ClassConstraint<T> where T : class {}
            DefaultTypeDefinition classConstraint = new DefaultTypeDefinition(dummyClass, "ClassConstraint");
            classConstraint.TypeParameters.Add(new DefaultTypeParameter(classConstraint, 0, "T") { HasReferenceTypeConstraint = true });

            // static void Foo<T>(ClassConstraint<T> ignored = default(ClassConstraint<T>))
            // where T : class
            var m2 = MakeMethod();
            m2.TypeParameters.Add(new DefaultTypeParameter(m2, 0, "T") { HasReferenceTypeConstraint = true });
            m2.Parameters.Add(MakeOptionalParameter(
                new ParameterizedType(classConstraint, new[] { m2.TypeParameters[0] }),
                "ignored"
            ));

            // static void Foo<T>()
            var m3 = MakeMethod();
            m3.TypeParameters.Add(new DefaultTypeParameter(m3, 0, "T"));

            // Call: Foo<int>();
            OverloadResolution o;
            o = new OverloadResolution(context, new ResolveResult[0], typeArguments: new[] { typeof(int).ToTypeReference().Resolve(context) });
            Assert.AreEqual(OverloadResolutionErrors.None, o.AddCandidate(m1));
            Assert.AreEqual(OverloadResolutionErrors.ConstructedTypeDoesNotSatisfyConstraint, o.AddCandidate(m2));
            Assert.AreSame(m1, o.BestCandidate);

            // Call: Foo<string>();
            o = new OverloadResolution(context, new ResolveResult[0], typeArguments: new[] { typeof(string).ToTypeReference().Resolve(context) });
            Assert.AreEqual(OverloadResolutionErrors.ConstructedTypeDoesNotSatisfyConstraint, o.AddCandidate(m1));
            Assert.AreEqual(OverloadResolutionErrors.None, o.AddCandidate(m2));
            Assert.AreSame(m2, o.BestCandidate);

            // Call: Foo<int?>();
            o = new OverloadResolution(context, new ResolveResult[0], typeArguments: new[] { typeof(int?).ToTypeReference().Resolve(context) });
            Assert.AreEqual(OverloadResolutionErrors.ConstructedTypeDoesNotSatisfyConstraint, o.AddCandidate(m1));
            Assert.AreEqual(OverloadResolutionErrors.ConstructedTypeDoesNotSatisfyConstraint, o.AddCandidate(m2));
            Assert.AreEqual(OverloadResolutionErrors.None, o.AddCandidate(m3));
            Assert.AreSame(m3, o.BestCandidate);
        }
开发者ID:richardschneider,项目名称:ILSpy,代码行数:49,代码来源:OverloadResolutionTests.cs


示例13: CreateResolveResultForUserDefinedOperator

		ResolveResult CreateResolveResultForUserDefinedOperator(OverloadResolution r, System.Linq.Expressions.ExpressionType operatorType)
		{
			if (r.BestCandidateErrors != OverloadResolutionErrors.None)
				return r.CreateResolveResult(null);
			IMethod method = (IMethod)r.BestCandidate;
			return new OperatorResolveResult(method.ReturnType, operatorType, method,
			                                 isLiftedOperator: method is OverloadResolution.ILiftedOperator,
			                                 operands: r.GetArgumentsWithConversions());
		}
开发者ID:nieve,项目名称:NRefactory,代码行数:9,代码来源:CSharpResolver.cs


示例14: BetterConversionByLambdaReturnValue

		public void BetterConversionByLambdaReturnValue()
		{
			var m1 = MakeMethod(typeof(Func<long>));
			var m2 = MakeMethod(typeof(Func<int>));
			
			// M(() => default(byte));
			ResolveResult[] args = {
				new MockLambda(KnownTypeReference.Byte.Resolve(context))
			};
			
			OverloadResolution r = new OverloadResolution(context, args);
			Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(m1));
			Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(m2));
			Assert.AreSame(m2, r.BestCandidate);
			Assert.AreEqual(OverloadResolutionErrors.None, r.BestCandidateErrors);
		}
开发者ID:jiguixin,项目名称:ILSpy,代码行数:16,代码来源:OverloadResolutionTests.cs


示例15: CreateOverloadResolution

 OverloadResolution CreateOverloadResolution(ResolveResult[] arguments, string[] argumentNames = null, IType[] typeArguments = null)
 {
     var or = new OverloadResolution(compilation, arguments, argumentNames, typeArguments, conversions);
     or.CheckForOverflow = checkForOverflow;
     return or;
 }
开发者ID:CSRedRat,项目名称:NRefactory,代码行数:6,代码来源:CSharpResolver.cs


示例16: ConstraintValidatingSubstitution

 public ConstraintValidatingSubstitution(IType[] typeArguments, OverloadResolution overloadResolution)
     : base(typeArguments)
 {
     this.overloadResolution = overloadResolution;
 }
开发者ID:richardschneider,项目名称:ILSpy,代码行数:5,代码来源:OverloadResolution.cs


示例17: PreferUIntOverLong_FromIntLiteral

		public void PreferUIntOverLong_FromIntLiteral()
		{
			ResolveResult[] args = { new ConstantResolveResult(compilation.FindType(KnownTypeCode.Int32), 1) };
			OverloadResolution r = new OverloadResolution(compilation, args);
			var c1 = MakeMethod(typeof(uint));
			Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(c1));
			Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(MakeMethod(typeof(long))));
			Assert.IsFalse(r.IsAmbiguous);
			Assert.AreSame(c1, r.BestCandidate);
		}
开发者ID:sphynx79,项目名称:dotfiles,代码行数:10,代码来源:OverloadResolutionTests.cs


示例18: ParamsMethodMatchesOneArgumentInExpandedForm

 public void ParamsMethodMatchesOneArgumentInExpandedForm()
 {
     OverloadResolution r = new OverloadResolution(context, MakeArgumentList(typeof(int)));
     Assert.AreEqual(OverloadResolutionErrors.None, r.AddCandidate(MakeParamsMethod(typeof(int[]))));
     Assert.IsTrue(r.BestCandidateIsExpandedForm);
 }
开发者ID:richardschneider,项目名称:ILSpy,代码行数:6,代码来源:OverloadResolutionTests.cs


示例19: ResolveUnaryOperator

        public ResolveResult ResolveUnaryOperator(UnaryOperatorType op, ResolveResult expression)
        {
            if (SpecialType.Dynamic.Equals(expression.Type))
                return UnaryOperatorResolveResult(SpecialType.Dynamic, op, expression);

            // C# 4.0 spec: §7.3.3 Unary operator overload resolution
            string overloadableOperatorName = GetOverloadableOperatorName(op);
            if (overloadableOperatorName == null) {
                switch (op) {
                    case UnaryOperatorType.Dereference:
                        PointerType p = expression.Type as PointerType;
                        if (p != null)
                            return UnaryOperatorResolveResult(p.ElementType, op, expression);
                        else
                            return ErrorResult;
                    case UnaryOperatorType.AddressOf:
                        return UnaryOperatorResolveResult(new PointerType(expression.Type), op, expression);
                    case UnaryOperatorType.Await:
                        ResolveResult getAwaiterMethodGroup = ResolveMemberAccess(expression, "GetAwaiter", EmptyList<IType>.Instance, true);
                        ResolveResult getAwaiterInvocation = ResolveInvocation(getAwaiterMethodGroup, new ResolveResult[0]);
                        var getResultMethodGroup = CreateMemberLookup().Lookup(getAwaiterInvocation, "GetResult", EmptyList<IType>.Instance, true) as MethodGroupResolveResult;
                        if (getResultMethodGroup != null) {
                            var or = getResultMethodGroup.PerformOverloadResolution(compilation, new ResolveResult[0], allowExtensionMethods: false, conversions: conversions);
                            IType awaitResultType = or.GetBestCandidateWithSubstitutedTypeArguments().ReturnType;
                            return UnaryOperatorResolveResult(awaitResultType, UnaryOperatorType.Await, expression);
                        } else {
                            return UnaryOperatorResolveResult(SpecialType.UnknownType, UnaryOperatorType.Await, expression);
                        }
                    default:
                        throw new ArgumentException("Invalid value for UnaryOperatorType", "op");
                }
            }
            // If the type is nullable, get the underlying type:
            IType type = NullableType.GetUnderlyingType(expression.Type);
            bool isNullable = NullableType.IsNullable(expression.Type);

            // the operator is overloadable:
            OverloadResolution userDefinedOperatorOR = new OverloadResolution(compilation, new[] { expression }, conversions: conversions);
            foreach (var candidate in GetUserDefinedOperatorCandidates(type, overloadableOperatorName)) {
                userDefinedOperatorOR.AddCandidate(candidate);
            }
            if (userDefinedOperatorOR.FoundApplicableCandidate) {
                return CreateResolveResultForUserDefinedOperator(userDefinedOperatorOR);
            }

            expression = UnaryNumericPromotion(op, ref type, isNullable, expression);
            CSharpOperators.OperatorMethod[] methodGroup;
            CSharpOperators operators = CSharpOperators.Get(compilation);
            switch (op) {
                case UnaryOperatorType.Increment:
                case UnaryOperatorType.Decrement:
                case UnaryOperatorType.PostIncrement:
                case UnaryOperatorType.PostDecrement:
                    // C# 4.0 spec: §7.6.9 Postfix increment and decrement operators
                    // C# 4.0 spec: §7.7.5 Prefix increment and decrement operators
                    TypeCode code = ReflectionHelper.GetTypeCode(type);
                    if ((code >= TypeCode.SByte && code <= TypeCode.Decimal) || type.Kind == TypeKind.Enum || type.Kind == TypeKind.Pointer)
                        return UnaryOperatorResolveResult(expression.Type, op, expression);
                    else
                        return new ErrorResolveResult(expression.Type);
                case UnaryOperatorType.Plus:
                    methodGroup = operators.UnaryPlusOperators;
                    break;
                case UnaryOperatorType.Minus:
                    methodGroup = CheckForOverflow ? operators.CheckedUnaryMinusOperators : operators.UncheckedUnaryMinusOperators;
                    break;
                case UnaryOperatorType.Not:
                    methodGroup = operators.LogicalNegationOperators;
                    break;
                case UnaryOperatorType.BitNot:
                    if (type.Kind == TypeKind.Enum) {
                        if (expression.IsCompileTimeConstant && !isNullable) {
                            // evaluate as (E)(~(U)x);
                            var U = compilation.FindType(expression.ConstantValue.GetType());
                            var unpackedEnum = new ConstantResolveResult(U, expression.ConstantValue);
                            return CheckErrorAndResolveCast(expression.Type, ResolveUnaryOperator(op, unpackedEnum));
                        } else {
                            return UnaryOperatorResolveResult(expression.Type, op, expression);
                        }
                    } else {
                        methodGroup = operators.BitwiseComplementOperators;
                        break;
                    }
                default:
                    throw new InvalidOperationException();
            }
            OverloadResolution builtinOperatorOR = new OverloadResolution(compilation, new[] { expression }, conversions: conversions);
            foreach (var candidate in methodGroup) {
                builtinOperatorOR.AddCandidate(candidate);
            }
            CSharpOperators.UnaryOperatorMethod m = (CSharpOperators.UnaryOperatorMethod)builtinOperatorOR.BestCandidate;
            IType resultType = m.ReturnType;
            if (builtinOperatorOR.BestCandidateErrors != OverloadResolutionErrors.None) {
                // If there are any user-defined operators, prefer those over the built-in operators.
                // It'll be a more informative error.
                if (userDefinedOperatorOR.BestCandidate != null)
                    return CreateResolveResultForUserDefinedOperator(userDefinedOperatorOR);
                else
                    return new ErrorResolveResult(resultType);
            } else if (expression.IsCompileTimeConstant && m.CanEvaluateAtCompileTime) {
//.........这里部分代码省略.........
开发者ID:holmak,项目名称:NRefactory,代码行数:101,代码来源:CSharpResolver.cs


示例20: ConstraintValidatingSubstitution

			public ConstraintValidatingSubstitution(IList<IType> classTypeArguments, IList<IType> methodTypeArguments, OverloadResolution overloadResolution)
				: base(classTypeArguments, methodTypeArguments)
			{
				this.conversions = overloadResolution.conversions;
			}
开发者ID:Netring,项目名称:ILSpy,代码行数:5,代码来源:OverloadResolution.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Resolver.TypeInference类代码示例发布时间:2022-05-26
下一篇:
C# Resolver.MemberLookup类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap