當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。