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


C# CSharp.ExpressionStatement类代码示例

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


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

示例1: DoResolve

        protected override bool DoResolve(BlockContext ec)
        {
            //
            // When delegate returns void, only expression statements can be used
            //
            if (ec.ReturnType == TypeManager.void_type) {
                Expr = Expr.Resolve (ec);
                if (Expr == null)
                    return false;

                statement = Expr as ExpressionStatement;
                if (statement == null)
                    Expr.Error_InvalidExpressionStatement (ec);

                return true;
            }

            return base.DoResolve (ec);
        }
开发者ID:RainsSoft,项目名称:MonoCompilerAsAService,代码行数:19,代码来源:lambda.cs

示例2: GetActions

		public IEnumerable<CodeAction> GetActions(RefactoringContext context)
		{
			//TODO: implement variable assignment & ctor param
			var varInit = context.GetNode<VariableInitializer>();
			if (varInit != null) {
				AstType type = varInit.GetPrevNode() as AstType;
				if (type == null) yield break;
				if (varInit.Parent is FieldDeclaration) yield break;
				if (CannotExtractField(varInit)) yield break;
				
				yield return new CodeAction("Extract field", s=>{
					var name = varInit.Name;
					FieldDeclaration field = new FieldDeclaration(){
						ReturnType = type.Clone(),
						Variables = { new VariableInitializer(name) }
					};
					AstNode nodeToRemove = RemoveDeclaration(varInit) ? varInit.Parent : type;
					s.Remove(nodeToRemove, true);
					s.InsertWithCursor(context.TranslateString("Extract field"),Script.InsertPosition.Before,field);
					s.FormatText(varInit.Parent);
				});
			}
			
			var idntf = context.GetNode<Identifier>();
			if (idntf == null) yield break;
			var paramDec = idntf.Parent as ParameterDeclaration;
			if (paramDec != null) {
				var ctor = paramDec.Parent as ConstructorDeclaration;
				if (ctor == null) yield break;
				MemberReferenceExpression thisField = new MemberReferenceExpression(new ThisReferenceExpression(), idntf.Name, new AstType[]{});
				var assign = new AssignmentExpression(thisField, AssignmentOperatorType.Assign, new IdentifierExpression(idntf.Name));
				var statement = new ExpressionStatement(assign);
				var type = (idntf.GetPrevNode() as AstType).Clone();
				FieldDeclaration field = new FieldDeclaration(){
					ReturnType = type.Clone(),
					Variables = { new VariableInitializer(idntf.Name) }
				};
				yield return new CodeAction("Extract field", s=>{
					s.InsertWithCursor(context.TranslateString("Extract field"),Script.InsertPosition.Before,field);
					s.AddTo(ctor.Body, statement);
				});
			}
		}
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:43,代码来源:ExtractFieldAction.cs

示例3: ResolveFieldInitializers

		public void ResolveFieldInitializers (BlockContext ec)
		{
			Debug.Assert (!IsPartialPart);

			if (ec.IsStatic) {
				if (initialized_static_fields == null)
					return;

				bool has_complex_initializer = !ec.Module.Compiler.Settings.Optimize;
				int i;
				ExpressionStatement [] init = new ExpressionStatement [initialized_static_fields.Count];
				for (i = 0; i < initialized_static_fields.Count; ++i) {
					FieldInitializer fi = initialized_static_fields [i];
					ExpressionStatement s = fi.ResolveStatement (ec);
					if (s == null) {
						s = EmptyExpressionStatement.Instance;
					} else if (!fi.IsSideEffectFree) {
						has_complex_initializer = true;
					}

					init [i] = s;
				}

				for (i = 0; i < initialized_static_fields.Count; ++i) {
					FieldInitializer fi = initialized_static_fields [i];
					//
					// Need special check to not optimize code like this
					// static int a = b = 5;
					// static int b = 0;
					//
					if (!has_complex_initializer && fi.IsDefaultInitializer)
						continue;

					ec.AssignmentInfoOffset += fi.AssignmentOffset;
					ec.CurrentBlock.AddScopeStatement (new StatementExpression (init [i]));
				}

				return;
			}

			if (initialized_fields == null)
				return;

			for (int i = 0; i < initialized_fields.Count; ++i) {
				FieldInitializer fi = initialized_fields [i];

				//
				// Clone before resolving otherwise when field initializer is needed
				// in more than 1 constructor any resolve after the initial one would
				// only took the resolved expression which is problem for expressions
				// that generate extra expressions or code during Resolve phase
				//
				var cloned = fi.Clone (new CloneContext ());

				ExpressionStatement s = fi.ResolveStatement (ec);
				if (s == null) {
					initialized_fields [i] = new FieldInitializer (fi.Field, ErrorExpression.Instance, Location.Null);
					continue;
				}

				//
				// Field is re-initialized to its default value => removed
				//
				if (fi.IsDefaultInitializer && Kind != MemberKind.Struct && ec.Module.Compiler.Settings.Optimize)
					continue;

				ec.AssignmentInfoOffset += fi.AssignmentOffset;
				ec.CurrentBlock.AddScopeStatement (new StatementExpression (s));
				initialized_fields [i] = (FieldInitializer) cloned;
			}
		}
开发者ID:razzfazz,项目名称:mono,代码行数:71,代码来源:class.cs

示例4: DynamicEventCompoundAssign

        public DynamicEventCompoundAssign(string name, Arguments args, ExpressionStatement assignment, ExpressionStatement invoke, Location loc)
            : base(null, args, loc)
        {
            this.name = name;
            base.binder = this;

            // Used by += or -= only
            type = TypeManager.bool_type;

            condition = new If (
                new Binary (Binary.Operator.Equality, this, new BoolLiteral (true, loc), loc),
                new StatementExpression (invoke), new StatementExpression (assignment),
                loc);
        }
开发者ID:speier,项目名称:shake,代码行数:14,代码来源:dynamic.cs

示例5: DoResolve

		protected override Expression DoResolve (ResolveContext ec)
		{
			// Field initializer can be resolved (fail) many times
			if (source == null)
				return null;

			if (resolved == null) {
				var ctx = new FieldInitializerContext (mc, ec);
				resolved = base.DoResolve (ctx) as ExpressionStatement;
			}

			return resolved;
		}
开发者ID:pgoron,项目名称:monodevelop,代码行数:13,代码来源:assign.cs

示例6: Visit

			public override object Visit (StatementErrorExpression statementErrorExpression)
			{
				var result = new ExpressionStatement ();
				var expr = statementErrorExpression.Expression.Accept (this) as Expression;
				if (expr != null)
					result.AddChild ((Expression)expr, ExpressionStatement.Roles.Expression);
				return result;
			}
开发者ID:N3X15,项目名称:ILSpy,代码行数:8,代码来源:CSharpParser.cs

示例7: DynamicEventCompoundAssign

		public DynamicEventCompoundAssign (string name, Arguments args, ExpressionStatement assignment, ExpressionStatement invoke, Location loc)
			: base (null, args, loc)
		{
			this.name = name;
			this.assignment = assignment;
			this.invoke = invoke;
			base.binder = this;

			// Used by += or -= only
			type = TypeManager.bool_type;
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:11,代码来源:dynamic.cs

示例8: Create

 public static ExpressionStatement Create(ExpressionStatement s, Expression orig)
 {
     return new ReducedExpressionStatement (s, orig);
 }
开发者ID:speier,项目名称:shake,代码行数:4,代码来源:ecore.cs

示例9: DoResolve

		protected override bool DoResolve (BlockContext ec)
		{
			//
			// When delegate returns void, only expression statements can be used
			//
			if (ec.ReturnType.Kind == MemberKind.Void) {
				Expr = Expr.Resolve (ec);
				if (Expr == null)
					return false;

				statement = Expr as ExpressionStatement;
				if (statement == null) {
					var reduced = Expr as IReducedExpressionStatement;
					if (reduced != null) {
						statement = EmptyExpressionStatement.Instance;
					} else {
						Expr.Error_InvalidExpressionStatement (ec);
					}
				}

				return true;
			}

			return base.DoResolve (ec);
		}
开发者ID:Profit0004,项目名称:mono,代码行数:25,代码来源:lambda.cs

示例10: GetActions

		public override IEnumerable<CodeAction> GetActions(RefactoringContext context)
		{
			//TODO: implement variable assignment & ctor param
			var varInit = context.GetNode<VariableInitializer>();
			if (varInit != null) {
				var selectedNode = varInit.GetNodeAt(context.Location);
				if (selectedNode != varInit.NameToken)
					yield break;

				AstType type = varInit.GetPrevNode() as AstType;
				if (type == null) yield break;
				if (varInit.Parent is FieldDeclaration) yield break;
				if (CannotExtractField(context, varInit)) yield break;
				
				yield return new CodeAction(context.TranslateString("Assign to new field"), s=>{
					var name = varInit.Name;

					AstType extractedType;
					if (type.IsVar()) {
						IType resolvedType = context.Resolve(varInit.Initializer).Type;
						extractedType = context.CreateShortType(resolvedType);
					}
					else {
						extractedType = (AstType) type.Clone();
					}

					AstNode entityDeclarationNode = varInit.Parent;
					while (!(entityDeclarationNode is EntityDeclaration) || (entityDeclarationNode is Accessor)) {
						entityDeclarationNode = entityDeclarationNode.Parent;
					}
					var entity = (EntityDeclaration) entityDeclarationNode;
					bool isStatic = entity.HasModifier(Modifiers.Static);

					FieldDeclaration field = new FieldDeclaration(){
						Modifiers = isStatic ? Modifiers.Static : Modifiers.None,
						ReturnType = extractedType,
						Variables = { new VariableInitializer(name) }
					};
					AstNode nodeToRemove = RemoveDeclaration(varInit) ? varInit.Parent : type;
					s.Remove(nodeToRemove, true);
					s.InsertWithCursor(context.TranslateString("Insert new field"),Script.InsertPosition.Before,field);
					s.FormatText(varInit.Parent);
				}, varInit);
			}
			
			var idntf = context.GetNode<Identifier>();
			if (idntf == null) yield break;
			var paramDec = idntf.Parent as ParameterDeclaration;
			if (paramDec != null) {
				var ctor = paramDec.Parent as ConstructorDeclaration;
				if (ctor == null) yield break;
				MemberReferenceExpression thisField = new MemberReferenceExpression(new ThisReferenceExpression(), idntf.Name, new AstType[]{});
				var assign = new AssignmentExpression(thisField, AssignmentOperatorType.Assign, new IdentifierExpression(idntf.Name));
				var statement = new ExpressionStatement(assign);
				var type = (idntf.GetPrevNode() as AstType).Clone();
				FieldDeclaration field = new FieldDeclaration(){
					ReturnType = type.Clone(),
					Variables = { new VariableInitializer(idntf.Name) }
				};
				yield return new CodeAction(context.TranslateString("Assign to new field"), s=>{
					s.InsertWithCursor(context.TranslateString("Insert new field"),Script.InsertPosition.Before,field);
					s.AddTo(ctor.Body, statement);
				}, paramDec);
			}
		}
开发者ID:qhta,项目名称:NRefactory,代码行数:65,代码来源:ExtractFieldAction.cs

示例11: ResolveVariable

		bool ResolveVariable (EmitContext ec)
		{
			ExpressionStatement a = new SimpleAssign (var, init, loc);
			a = a.ResolveStatement (ec);
			if (a == null)
				return false;

			assign = a;

			if (TypeManager.ImplementsInterface (a.Type, TypeManager.idisposable_type)) {
				converted_var = var;
				return true;
			}

			Expression e = Convert.ImplicitConversionStandard (ec, a, TypeManager.idisposable_type, var.Location);
			if (e == null) {
				Error_IsNotConvertibleToIDisposable (var);
				return false;
			}

			converted_var = e;

			return true;
		}
开发者ID:lewurm,项目名称:benchmarker,代码行数:24,代码来源:statement.cs

示例12: StatementExpression

		public StatementExpression (ExpressionStatement expr)
		{
			this.expr = expr;
			loc = expr.Location;
		}
开发者ID:alisci01,项目名称:mono,代码行数:5,代码来源:statement.cs

示例13: ReducedExpressionStatement

 public ReducedExpressionStatement(ExpressionStatement stm, Expression orig)
 {
     this.orig_expr = orig;
     this.stm = stm;
     this.loc = orig.Location;
 }
开发者ID:speier,项目名称:shake,代码行数:6,代码来源:ecore.cs

示例14: DoResolve

		protected override Expression DoResolve (ResolveContext ec)
		{
			// Field initializer can be resolved (fail) many times
			if (source == null)
				return null;

			if (resolved == null) {
				//
				// Field initializers are tricky for partial classes. They have to
				// share same constructor (block) but they have they own resolve scope.
				//

				IMemberContext old = ec.MemberContext;
				ec.MemberContext = rc;

				using (ec.Set (ResolveContext.Options.FieldInitializerScope)) {
					resolved = base.DoResolve (ec) as ExpressionStatement;
				}

				ec.MemberContext = old;
			}

			return resolved;
		}
开发者ID:ikvm,项目名称:mono,代码行数:24,代码来源:assign.cs

示例15: DynamicEventCompoundAssign

		public DynamicEventCompoundAssign (string name, Arguments args, ExpressionStatement assignment, ExpressionStatement invoke, Location loc)
		{
			condition = new IsEvent (name, args, loc);
			this.invoke = invoke;
			this.assign = assignment;
			this.loc = loc;
		}
开发者ID:caomw,项目名称:mono,代码行数:7,代码来源:dynamic.cs


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