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


C# IsExpression类代码示例

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


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

示例1: E

        /// <summary>
        /// http://dlang.org/expression.html#IsExpression
        /// </summary>
        public ISemantic E(IsExpression isExpression)
        {
            if(!eval)
                return new PrimitiveType(DTokens.Bool);

            bool retTrue = false;

            if (isExpression.TestedType != null)
            {
                var typeToCheck = DResolver.StripMemberSymbols(TypeDeclarationResolver.ResolveSingle(isExpression.TestedType, ctxt));

                if (typeToCheck != null)
                {
                    // case 1, 4
                    if (isExpression.TypeSpecialization == null && isExpression.TypeSpecializationToken == 0)
                        retTrue = true;

                    // The probably most frequented usage of this expression
                    else if (isExpression.TypeAliasIdentifierHash == 0)
                        retTrue = evalIsExpression_NoAlias(isExpression, typeToCheck);
                    else
                        retTrue = evalIsExpression_WithAliases(isExpression, typeToCheck);
                }
            }

            return new PrimitiveValue(DTokens.Bool, retTrue?1:0, isExpression);
        }
开发者ID:DinrusGroup,项目名称:DRC,代码行数:30,代码来源:Evaluation.IsExpression.cs

示例2: VisitIsExpression

			public override void VisitIsExpression (IsExpression isExpression)
			{
				base.VisitIsExpression (isExpression);

//				var conversions = CSharpConversions.Get(ctx.Compilation);
				var exprType = ctx.Resolve (isExpression.Expression).Type;
				var providedType = ctx.ResolveType (isExpression.Type);

				if (exprType.Kind == TypeKind.Unknown || providedType.Kind == TypeKind.Unknown)
					return;
				if (IsValidReferenceOrBoxingConversion(exprType, providedType))
					return;
				
				var exprTP = exprType as ITypeParameter;
				var providedTP = providedType as ITypeParameter;
				if (exprTP != null) {
					if (IsValidReferenceOrBoxingConversion(exprTP.EffectiveBaseClass, providedType)
					    && exprTP.EffectiveInterfaceSet.All(i => IsValidReferenceOrBoxingConversion(i, providedType)))
						return;
				}
				if (providedTP != null) {
					if (IsValidReferenceOrBoxingConversion(exprType, providedTP.EffectiveBaseClass))
						return;
				}
				
				AddIssue (isExpression, ctx.TranslateString ("Given expression is never of the provided type"));
			}
开发者ID:RainsSoft,项目名称:playscript-monodevelop,代码行数:27,代码来源:ExpressionIsNeverOfProvidedTypeIssue.cs

示例3: VisitIsExpression

			public override void VisitIsExpression (IsExpression isExpression)
			{
				base.VisitIsExpression (isExpression);

				var exprType = ctx.Resolve (isExpression.Expression).Type;
				var providedType = ctx.ResolveType (isExpression.Type);

				if (TypeCompatibilityHelper.CheckTypeCompatibility(exprType, providedType) == 
					TypeCompatibilityHelper.TypeCompatiblity.NeverOfProvidedType)
					AddIssue (isExpression, ctx.TranslateString ("Given expression is never of the provided type"));
			}
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:11,代码来源:ExpressionIsNeverOfProvidedTypeIssue.cs

示例4: evalIsExpression_WithAliases

		private bool evalIsExpression_WithAliases(IsExpression isExpression, AbstractType typeToCheck)
		{
			/*
			 * Note: It's needed to let the abstract ast scanner also scan through IsExpressions etc.
			 * in order to find aliases and/or specified template parameters!
			 */

			var expectedTemplateParams = new TemplateParameter[isExpression.TemplateParameterList == null  ? 1 : (isExpression.TemplateParameterList.Length + 1)];
			expectedTemplateParams [0] = isExpression.ArtificialFirstSpecParam;
			if(expectedTemplateParams.Length > 1)
				isExpression.TemplateParameterList.CopyTo (expectedTemplateParams, 1);

			var tpl_params = new DeducedTypeDictionary(expectedTemplateParams);


			var tpd = new TemplateParameterDeduction(tpl_params, ctxt);
			bool retTrue = false;

			if (isExpression.EqualityTest) // 6.
			{
				// a)
				if (isExpression.TypeSpecialization != null)
				{
					tpd.EnforceTypeEqualityWhenDeducing = true;
					retTrue = tpd.Handle(isExpression.ArtificialFirstSpecParam, typeToCheck);
					tpd.EnforceTypeEqualityWhenDeducing = false;
				}
				else // b)
				{
					var r = evalIsExpression_EvalSpecToken(isExpression, typeToCheck, true);
					retTrue = r.Item1;
					tpl_params[isExpression.ArtificialFirstSpecParam] = new TemplateParameterSymbol(isExpression.ArtificialFirstSpecParam, r.Item2);
				}
			}
			else // 5.
				retTrue = tpd.Handle(isExpression.ArtificialFirstSpecParam, typeToCheck);

			if (retTrue && isExpression.TemplateParameterList != null)
				foreach (var p in isExpression.TemplateParameterList)
					if (!tpd.Handle(p, tpl_params[p] != null ? tpl_params[p].Base : null))
						return false;

			if (retTrue)
			{
				foreach (var kv in tpl_params)
					ctxt.CurrentContext.DeducedTemplateParameters[kv.Key] = kv.Value;
			}

			return retTrue;
		}
开发者ID:DinrusGroup,项目名称:D_Parser,代码行数:50,代码来源:Evaluation.IsExpression.cs

示例5: VisitIsExpression

			public override void VisitIsExpression (IsExpression isExpression)
			{
				base.VisitIsExpression (isExpression);

				var type = ctx.Resolve (isExpression.Expression).Type;
				var providedType = ctx.ResolveType (isExpression.Type);

				if (type.GetAllBaseTypes ().All (t => !t.Equals (providedType)))
					return;

				var action = new CodeAction (ctx.TranslateString ("Compare with 'null'"), 
					scrpit => scrpit.Replace (isExpression, new BinaryOperatorExpression (
						isExpression.Expression.Clone (), BinaryOperatorType.InEquality, new PrimitiveExpression (null))));
				AddIssue (isExpression, ctx.TranslateString ("Given expression is always of the provided type. " +
					"Consider comparing with 'null' instead"), new [] { action });
			}
开发者ID:mono-soc-2012,项目名称:NRefactory,代码行数:16,代码来源:ExpressionIsAlwaysOfProvidedTypeIssue.cs

示例6: evalIsExpression_WithAliases

		private bool evalIsExpression_WithAliases(IsExpression isExpression, AbstractType typeToCheck)
		{
			/*
			 * Note: It's needed to let the abstract ast scanner also scan through IsExpressions etc.
			 * in order to find aliases and/or specified template parameters!
			 */

			var expectedTemplateParams = new TemplateParameter[isExpression.TemplateParameterList.Length + 1];
			expectedTemplateParams [0] = isExpression.ArtificialFirstSpecParam;
			if(expectedTemplateParams.Length > 1)
				isExpression.TemplateParameterList.CopyTo (expectedTemplateParams, 1);

			var tpl_params = new DeducedTypeDictionary(expectedTemplateParams);


			var tpd = new TemplateParameterDeduction(tpl_params, ctxt);
			bool retTrue = false;

			if (isExpression.EqualityTest) // 6.
			{
				// a)
				if (isExpression.TypeSpecialization != null)
				{
					tpd.EnforceTypeEqualityWhenDeducing = true;
					retTrue = tpd.Handle(isExpression.ArtificialFirstSpecParam, typeToCheck);
					tpd.EnforceTypeEqualityWhenDeducing = false;
				}
				else // b)
				{
					var r = evalIsExpression_EvalSpecToken(isExpression, typeToCheck, true);
					retTrue = r.Item1;
					tpl_params[isExpression.TypeAliasIdentifierHash] = new TemplateParameterSymbol(null, r.Item2);
				}
			}
			else // 5.
				retTrue = tpd.Handle(isExpression.ArtificialFirstSpecParam, typeToCheck);

			if (retTrue && isExpression.TemplateParameterList != null)
				foreach (var p in isExpression.TemplateParameterList)
					if (!tpd.Handle(p, tpl_params[p.NameHash] != null ? tpl_params[p.NameHash].Base : null))
						return false;

			//TODO: Put all tpl_params results into the resolver context or make a new scope or something! 

			return retTrue;
		}
开发者ID:DinrusGroup,项目名称:DinrusIDE,代码行数:46,代码来源:Evaluation.IsExpression.cs

示例7: VisitIsExpression

			public override void VisitIsExpression (IsExpression isExpression)
			{
				base.VisitIsExpression (isExpression);

				var type = ctx.Resolve (isExpression.Expression).Type;
				var providedType = ctx.ResolveType (isExpression.Type);

//				var foundConversion = conversions.ImplicitConversion(type, providedType);
				if (!IsValidReferenceOrBoxingConversion(type, providedType))
					return;

				var action = new CodeAction (ctx.TranslateString ("Compare with 'null'"), 
					scrpit => scrpit.Replace (isExpression, new BinaryOperatorExpression (
						isExpression.Expression.Clone (), BinaryOperatorType.InEquality, new PrimitiveExpression (null))));
				AddIssue (isExpression, ctx.TranslateString ("Given expression is always of the provided type. " +
					"Consider comparing with 'null' instead"), new [] { action });
			}
开发者ID:RainsSoft,项目名称:playscript-monodevelop,代码行数:17,代码来源:ExpressionIsAlwaysOfProvidedTypeIssue.cs

示例8: GetIsExpression

        /// <summary>
        /// Reads an is expression.
        /// </summary>
        /// <param name="leftHandSide">The expression on the left hand side of the operator.</param>
        /// <param name="previousPrecedence">The precedence of the expression just before this one.</param>
        /// <param name="unsafeCode">Indicates whether the code being parsed resides in an unsafe code block.</param>
        /// <returns>Returns the expression.</returns>
        private IsExpression GetIsExpression(
            Expression leftHandSide, ExpressionPrecedence previousPrecedence, bool unsafeCode)
        {
            Param.AssertNotNull(leftHandSide, "leftHandSide");
            Param.Ignore(previousPrecedence);
            Param.Ignore(unsafeCode);

            IsExpression expression = null;

            // Check the previous precedence to see if we are allowed to gather up the is expression.
            if (this.CheckPrecedence(previousPrecedence, ExpressionPrecedence.Relational))
            {
                // Make sure the left hand side has at least one token.
                Debug.Assert(leftHandSide.Tokens.First != null, "The left hand side should not be empty");

                // Get the is symbol.
                this.tokens.Add(this.GetToken(CsTokenType.Is, SymbolType.Is));

                // The next token must be the type.
                this.GetNextSymbol(SymbolType.Other);

                // Get the expression representing the type.
                LiteralExpression rightHandSide = this.GetTypeTokenExpression(unsafeCode, true, true);
                if (rightHandSide == null || rightHandSide.Tokens.First == null)
                {
                    throw this.CreateSyntaxException();
                }

                // Create the partial token list for the expression.
                CsTokenList partialTokens = new CsTokenList(this.tokens, leftHandSide.Tokens.First, this.tokens.Last);

                // Create and return the expression.
                expression = new IsExpression(partialTokens, leftHandSide, rightHandSide);
            }

            return expression;
        }
开发者ID:transformersprimeabcxyz,项目名称:_TO-FIRST-stylecop,代码行数:44,代码来源:LargeTestFile.cs

示例9: VisitIsExpression

 public StringBuilder VisitIsExpression(IsExpression isExpression, int data)
 {
     throw new SLSharpException("SL# does not have reflection.");
 }
开发者ID:hach-que,项目名称:SLSharp,代码行数:4,代码来源:VisitorBase.Illegal.cs

示例10: PrimaryExpression


//.........这里部分代码省略.........
            }
            #endregion

            if (laKind == (Typeof))
            {
                var startLoc = la.Location;
                return new TypeDeclarationExpression(TypeOf()) {Location=startLoc,EndLocation=t.EndLocation};
            }

            // TypeidExpression
            if (laKind == (Typeid))
            {
                Step();
                var ce = new TypeidExpression() { Location=t.Location};
                LastParsedObject = ce;
                Expect(OpenParenthesis);

                AllowWeakTypeParsing = true;
                ce.Type = Type();
                AllowWeakTypeParsing = false;

                if (ce.Type==null)
                    ce.Expression = AssignExpression();

                Expect(CloseParenthesis);
                ce.EndLocation = t.EndLocation;
                return ce;
            }

            #region IsExpression
            if (laKind == Is)
            {
                Step();
                var ce = new IsExpression() { Location=t.Location};
                LastParsedObject = ce;
                Expect(OpenParenthesis);

                var LookAheadBackup = la;

                AllowWeakTypeParsing = true;
                ce.TestedType = Type();
                AllowWeakTypeParsing = false;

                if (ce.TestedType!=null && laKind == Identifier && (Lexer.CurrentPeekToken.Kind == CloseParenthesis || Lexer.CurrentPeekToken.Kind == Equal
                    || Lexer.CurrentPeekToken.Kind == Colon))
                {
                    Step();
                    ce.TypeAliasIdentifier = strVal;
                }
                else
                // D Language specs mistake: In an IsExpression there also can be expressions!
                if(ce.TestedType==null || !(laKind==CloseParenthesis || laKind==Equal||laKind==Colon))
                {
                    // Reset lookahead token to prior position
                    la = LookAheadBackup;
                    // Reset wrongly parsed type declaration
                    ce.TestedType = null;
                    ce.TestedExpression = ConditionalExpression();
                }

                if(ce.TestedExpression==null && ce.TestedType==null)
                    SynErr(laKind,"In an IsExpression, either a type or an expression is required!");

                if (laKind == CloseParenthesis)
                {
                    Step();
开发者ID:nazriel,项目名称:Mono-D,代码行数:67,代码来源:Parser_Impl.cs

示例11: VisitIsExpression

		public void VisitIsExpression(IsExpression isExpression)
		{
			StartNode(isExpression);
			isExpression.Expression.AcceptVisitor(this);
			Space();
			WriteKeyword(IsExpression.IsKeywordRole);
			isExpression.Type.AcceptVisitor(this);
			EndNode(isExpression);
		}
开发者ID:x-strong,项目名称:ILSpy,代码行数:9,代码来源:CSharpOutputVisitor.cs

示例12: VisitIsExpression

		public virtual void VisitIsExpression (IsExpression isExpression)
		{
			VisitChildren (isExpression);
		}
开发者ID:modulexcite,项目名称:ICSharpCode.Decompiler-retired,代码行数:4,代码来源:DepthFirstAstVisitor.cs

示例13: VisitIsExpression

 public virtual void VisitIsExpression(IsExpression isExpression)
 {
     if (this.ThrowException)
     {
         throw (Exception)this.CreateException(isExpression);
     }
 }
开发者ID:fabriciomurta,项目名称:BridgeUnified,代码行数:7,代码来源:Visitor.Exception.cs

示例14: CreateEqualsOverrides

		List<MethodDeclaration> CreateEqualsOverrides(IType currentClass)
		{
			List<MethodDeclaration> methods = new List<MethodDeclaration>();
			
			AstType boolReference = ConvertType(KnownTypeCode.Boolean);
			AstType objectReference = ConvertType(KnownTypeCode.Object);
			
			MethodDeclaration method = new MethodDeclaration {
				Name = "Equals",
				Modifiers = Modifiers.Public | Modifiers.Override,
				ReturnType = boolReference
			};
			method.Parameters.Add(new ParameterDeclaration(objectReference, "obj"));
			method.Body = new BlockStatement();
			
			AstType currentType = ConvertType(currentClass);
			Expression expr = null;
			
			if (currentClass.Kind == TypeKind.Struct) {
				// return obj is CurrentType && Equals((CurrentType)obj);
				expr = new IsExpression() {
					Expression = new IdentifierExpression("obj"),
					Type = currentType.Clone()
				};
				expr = new ParenthesizedExpression(expr);
				expr = new BinaryOperatorExpression(
					expr, BinaryOperatorType.ConditionalAnd,
					new InvocationExpression(
						new IdentifierExpression("Equals"),
						new List<Expression> {
							new CastExpression(currentType.Clone(), new IdentifierExpression("obj"))
						}));
				method.Body.Add(new ReturnStatement(expr));
				
				methods.Add(method);
				
				// IEquatable implementation:
				method = new MethodDeclaration {
					Name = "Equals",
					Modifiers = Modifiers.Public,
					ReturnType = boolReference.Clone()
				};
				method.Parameters.Add(new ParameterDeclaration(currentType, "other"));
				method.Body = new BlockStatement();
			} else {
				method.Body.Add(new VariableDeclarationStatement(
					currentType.Clone(),
					"other",
					new IdentifierExpression("obj").CastAs(currentType.Clone())));
				method.Body.Add(new IfElseStatement(
					new BinaryOperatorExpression(new IdentifierExpression("other"), BinaryOperatorType.Equality, new PrimitiveExpression(null, "null")),
					new ReturnStatement(new PrimitiveExpression(false, "false"))));
			}
			
			expr = null;
			foreach (IField field in currentClass.GetFields()) {
				if (field.IsStatic) continue;
				
				if (expr == null) {
					expr = TestEquality("other", field);
				} else {
					expr = new BinaryOperatorExpression(expr, BinaryOperatorType.ConditionalAnd,
					                                    TestEquality("other", field));
				}
			}
			
			foreach (IProperty property in currentClass.GetProperties()) {
				if (property.IsStatic || !property.IsAutoImplemented()) continue;
				if (expr == null) {
					expr = TestEquality("other", property);
				} else {
					expr = new BinaryOperatorExpression(expr, BinaryOperatorType.ConditionalAnd,
					                                    TestEquality("other", property));
				}
			}
			
			method.Body.Add(new ReturnStatement(expr ?? new PrimitiveExpression(true, "true")));
			
			methods.Add(method);
			
			return methods;
		}
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:82,代码来源:OverrideEqualsGetHashCodeMethodsDialog.xaml.cs

示例15: CastBlock

 public CastBlock(IEmitter emitter, IsExpression isExpression)
     : base(emitter, isExpression)
 {
     this.Emitter = emitter;
     this.IsExpression = isExpression;
 }
开发者ID:Cestbienmoi,项目名称:Bridge,代码行数:6,代码来源:CastBlock.cs


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