當前位置: 首頁>>代碼示例>>C#>>正文


C# CSharp.Expression類代碼示例

本文整理匯總了C#中Mono.CSharp.Expression的典型用法代碼示例。如果您正苦於以下問題:C# Expression類的具體用法?C# Expression怎麽用?C# Expression使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Expression類屬於Mono.CSharp命名空間,在下文中一共展示了Expression類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CSharpBinder

		public CSharpBinder (DynamicMetaObjectBinder binder, Compiler.Expression expr, DynamicMetaObject errorSuggestion)
		{
			this.binder = binder;
			this.expr = expr;
			this.restrictions = BindingRestrictions.Empty;
			this.errorSuggestion = errorSuggestion;
		}
開發者ID:bbqchickenrobot,項目名稱:playscript-mono,代碼行數:7,代碼來源:CSharpBinder.cs

示例2: ImplicitTypeParameterConversion

		public static Expression ImplicitTypeParameterConversion (Expression expr, TypeParameterSpec expr_type, TypeSpec target_type)
		{
			//
			// From T to a type parameter U, provided T depends on U
			//
			if (target_type.IsGenericParameter) {
				if (expr_type.TypeArguments != null && expr_type.HasDependencyOn (target_type)) {
					if (expr == null)
						return EmptyExpression.Null;

					if (expr_type.IsReferenceType && !((TypeParameterSpec) target_type).IsReferenceType)
						return new BoxedCast (expr, target_type);

					return new ClassCast (expr, target_type);
				}

				return null;
			}

			//
			// LAMESPEC: From T to dynamic type because it's like T to object
			//
			if (target_type.BuiltinType == BuiltinTypeSpec.Type.Dynamic) {
				if (expr == null)
					return EmptyExpression.Null;

				if (expr_type.IsReferenceType)
					return new ClassCast (expr, target_type);

				return new BoxedCast (expr, target_type);
			}

			//
			// From T to its effective base class C
			// From T to any base class of C (it cannot contain dynamic or be of dynamic type)
			// From T to any interface implemented by C
			//
			var base_type = expr_type.GetEffectiveBase ();
			if (base_type == target_type || TypeSpec.IsBaseClass (base_type, target_type, false) || base_type.ImplementsInterface (target_type, true)) {
				if (expr == null)
					return EmptyExpression.Null;

				if (expr_type.IsReferenceType)
					return new ClassCast (expr, target_type);

				return new BoxedCast (expr, target_type);
			}

			if (target_type.IsInterface && expr_type.IsConvertibleToInterface (target_type)) {
				if (expr == null)
					return EmptyExpression.Null;

				if (expr_type.IsReferenceType)
					return new ClassCast (expr, target_type);

				return new BoxedCast (expr, target_type);
			}

			return null;
		}
開發者ID:nberardi,項目名稱:mono,代碼行數:60,代碼來源:convert.cs

示例3: Bind

		public DynamicMetaObject Bind (DynamicContext ctx, Type callingType)
		{
			Expression res;
			try {
				var rc = new Compiler.ResolveContext (new RuntimeBinderContext (ctx, callingType), ResolveOptions);

				// Static typemanager and internal caches are not thread-safe
				lock (resolver) {
					expr = expr.Resolve (rc, Compiler.ResolveFlags.VariableOrValue);
				}

				if (expr == null)
					throw new RuntimeBinderInternalCompilerException ("Expression resolved to null");

				res = expr.MakeExpression (new Compiler.BuilderContext ());
			} catch (RuntimeBinderException e) {
				if (errorSuggestion != null)
					return errorSuggestion;

				res = CreateBinderException (e.Message);
			} catch (Exception) {
				if (errorSuggestion != null)
					return errorSuggestion;

				throw;
			}

			return new DynamicMetaObject (res, restrictions);
		}
開發者ID:bbqchickenrobot,項目名稱:playscript-mono,代碼行數:29,代碼來源:CSharpBinder.cs

示例4: Argument

		public Argument (Expression expr)
		{
			if (expr == null)
				throw new ArgumentNullException ();

			this.Expr = expr;
		}
開發者ID:pgoron,項目名稱:monodevelop,代碼行數:7,代碼來源:argument.cs

示例5: ExplicitConversion

        /// <summary>
        ///   Performs an explicit conversion of the expression `expr' whose
        ///   type is expr.Type to `target_type'.
        /// </summary>
        public static Expression ExplicitConversion(ResolveContext ec, Expression expr,
			TypeSpec target_type, Location loc)
        {
            Expression e = ExplicitConversionCore (ec, expr, target_type, loc);
            if (e != null) {
                //
                // Don't eliminate explicit precission casts
                //
                if (e == expr) {
                    if (target_type.BuiltinType == BuiltinTypeSpec.Type.Float)
                        return new OpcodeCast (expr, target_type, OpCodes.Conv_R4);

                    if (target_type.BuiltinType == BuiltinTypeSpec.Type.Double)
                        return new OpcodeCast (expr, target_type, OpCodes.Conv_R8);
                }

                return e;
            }

            TypeSpec expr_type = expr.Type;
            if (target_type.IsNullableType) {
                TypeSpec target;

                if (expr_type.IsNullableType) {
                    target = Nullable.NullableInfo.GetUnderlyingType (target_type);
                    Expression unwrap = Nullable.Unwrap.Create (expr);
                    e = ExplicitConversion (ec, unwrap, target, expr.Location);
                    if (e == null)
                        return null;

                    return new Nullable.LiftedConversion (e, unwrap, target_type).Resolve (ec);
                }
                if (expr_type.BuiltinType == BuiltinTypeSpec.Type.Object) {
                    return new UnboxCast (expr, target_type);
                }

                target = TypeManager.GetTypeArguments (target_type) [0];
                e = ExplicitConversionCore (ec, expr, target, loc);
                if (e != null)
                    return TypeSpec.IsReferenceType (expr.Type) ? new UnboxCast (expr, target_type) : Nullable.Wrap.Create (e, target_type);
            } else if (expr_type.IsNullableType) {
                e = ImplicitBoxingConversion (expr, Nullable.NullableInfo.GetUnderlyingType (expr_type), target_type);
                if (e != null)
                    return e;

                e = Nullable.Unwrap.Create (expr, false);
                e = ExplicitConversionCore (ec, e, target_type, loc);
                if (e != null)
                    return EmptyCast.Create (e, target_type);
            }

            e = ExplicitUserConversion (ec, expr, target_type, loc);

            if (e != null)
                return e;

            expr.Error_ValueCannotBeConverted (ec, target_type, true);
            return null;
        }
開發者ID:exodrifter,項目名稱:mcs-ICodeCompiler,代碼行數:63,代碼來源:convert.cs

示例6: Const

		public Const (DeclSpace parent, FullNamedExpression type, string name,
			      Expression expr, int mod_flags, Attributes attrs, Location loc)
			: base (parent, type, mod_flags, AllowedModifiers,
				new MemberName (name, loc), attrs)
		{
			initializer = expr;
			ModFlags |= Modifiers.STATIC;
		}
開發者ID:lewurm,項目名稱:benchmarker,代碼行數:8,代碼來源:const.cs

示例7: EnumMember

		public EnumMember (Enum parent, EnumMember prev_member, string name, Expression expr,
				   Attributes attrs, Location loc)
			: base (parent, new EnumTypeExpr (parent), name, expr, Modifiers.PUBLIC,
				attrs, loc)
		{
			this.ParentEnum = parent;
			this.ValueExpr = expr;
			this.prev_member = prev_member;
		}
開發者ID:calumjiao,項目名稱:Mono-Class-Libraries,代碼行數:9,代碼來源:enum.cs

示例8: ExplicitConversion

        /// <summary>
        ///   Performs an explicit conversion of the expression `expr' whose
        ///   type is expr.Type to `target_type'.
        /// </summary>
        public static Expression ExplicitConversion(ResolveContext ec, Expression expr,
            TypeSpec target_type, Location loc)
        {
            Expression e = ExplicitConversionCore (ec, expr, target_type, loc);
            if (e != null) {
                //
                // Don't eliminate explicit precission casts
                //
                if (e == expr) {
                    if (target_type == TypeManager.float_type)
                        return new OpcodeCast (expr, target_type, OpCodes.Conv_R4);

                    if (target_type == TypeManager.double_type)
                        return new OpcodeCast (expr, target_type, OpCodes.Conv_R8);
                }

                return e;
            }

            TypeSpec expr_type = expr.Type;
            if (TypeManager.IsNullableType (target_type)) {
                if (TypeManager.IsNullableType (expr_type)) {
                    TypeSpec target = Nullable.NullableInfo.GetUnderlyingType (target_type);
                    Expression unwrap = Nullable.Unwrap.Create (expr);
                    e = ExplicitConversion (ec, unwrap, target, expr.Location);
                    if (e == null)
                        return null;

                    return new Nullable.Lifted (e, unwrap, target_type).Resolve (ec);
                } else if (expr_type == TypeManager.object_type) {
                    return new UnboxCast (expr, target_type);
                } else {
                    TypeSpec target = TypeManager.GetTypeArguments (target_type) [0];

                    e = ExplicitConversionCore (ec, expr, target, loc);
                    if (e != null)
                        return Nullable.Wrap.Create (e, target_type);
                }
            } else if (TypeManager.IsNullableType (expr_type)) {
                bool use_class_cast;
                if (ImplicitBoxingConversionExists (Nullable.NullableInfo.GetUnderlyingType (expr_type), target_type, out use_class_cast))
                    return new BoxedCast (expr, target_type);

                e = Nullable.Unwrap.Create (expr, false);
                e = ExplicitConversionCore (ec, e, target_type, loc);
                if (e != null)
                    return EmptyCast.Create (e, target_type);
            }

            e = ExplicitUserConversion (ec, expr, target_type, loc);
            if (e != null)
                return e;

            expr.Error_ValueCannotBeConverted (ec, loc, target_type, true);
            return null;
        }
開發者ID:speier,項目名稱:shake,代碼行數:60,代碼來源:convert.cs

示例9: Const

        public Const(DeclSpace parent, FullNamedExpression type, string name,
            Expression expr, Modifiers mod_flags, Attributes attrs, Location loc)
            : base(parent, type, mod_flags, AllowedModifiers,
				new MemberName (name, loc), attrs)
        {
            if (expr != null)
                initializer = new ConstInitializer (this, expr);

            ModFlags |= Modifiers.STATIC;
        }
開發者ID:speier,項目名稱:shake,代碼行數:10,代碼來源:const.cs

示例10: MakeSimpleCall

		static public Expression MakeSimpleCall (EmitContext ec, MethodGroupExpr mg,
							 Expression e, Location loc)
		{
			ArrayList args;
			MethodBase method;
			
			args = new ArrayList (1);
			args.Add (new Argument (e, Argument.AType.Expression));
			method = Invocation.OverloadResolve (ec, (MethodGroupExpr) mg, args, loc);

			if (method == null)
				return null;

			return new StaticCallExpr ((MethodInfo) method, args, loc);
		}
開發者ID:emtees,項目名稱:old-code,代碼行數:15,代碼來源:expression.cs

示例11: CreateFromExpression

		CodeAction CreateFromExpression(RefactoringContext context, Expression expression)
		{
			var resolveResult = context.Resolve(expression);
			if (resolveResult.IsError)
				return null;
			
			return new CodeAction(context.TranslateString("Extract method"), script => {
				string methodName = "NewMethod";
				var method = new MethodDeclaration {
					ReturnType = context.CreateShortType(resolveResult.Type),
					Name = methodName,
					Body = new BlockStatement {
						new ReturnStatement(expression.Clone())
					}
				};
				if (!StaticVisitor.UsesNotStaticMember(context, expression))
					method.Modifiers |= Modifiers.Static;

				var usedVariables = VariableLookupVisitor.Analyze(context, expression);
				
				var inExtractedRegion = new VariableUsageAnalyzation (context, usedVariables);

				usedVariables.Sort ((l, r) => l.Region.Begin.CompareTo (r.Region.Begin));
				var target = new IdentifierExpression(methodName);
				var invocation = new InvocationExpression(target);
				foreach (var variable in usedVariables) {
					Expression argumentExpression = new IdentifierExpression(variable.Name); 
					
					var mod = ParameterModifier.None;
					if (inExtractedRegion.GetStatus (variable) == VariableState.Changed) {
						mod = ParameterModifier.Ref;
						argumentExpression = new DirectionExpression(FieldDirection.Ref, argumentExpression);
					}
					
					method.Parameters.Add(new ParameterDeclaration(context.CreateShortType(variable.Type), variable.Name, mod));
					invocation.Arguments.Add(argumentExpression);
				}

				script
					.InsertWithCursor(context.TranslateString("Extract method"), Script.InsertPosition.Before, method)
					.ContinueScript (delegate {
						script.Replace(expression, invocation);
						script.Link(target, method.NameToken);
					});
			}, expression);
		}
開發者ID:0xb1dd1e,項目名稱:NRefactory,代碼行數:46,代碼來源:ExtractMethodAction.cs

示例12: OptionalAssign

		public OptionalAssign (Expression t, Expression s, Location loc)
			: base (t, s, loc)
		{
		}
開發者ID:KAW0,項目名稱:Alter-Native,代碼行數:4,代碼來源:eval.cs

示例13: OptionalAssign

		public OptionalAssign (Expression s, Location loc)
			: base (null, s, loc)
		{
		}
開發者ID:FrancisVarga,項目名稱:mono,代碼行數:4,代碼來源:eval.cs

示例14: Visit

			public override object Visit (Expression expression)
			{
				Console.WriteLine ("Visit unknown expression:" + expression);
				return null;
			}
開發者ID:pgoron,項目名稱:monodevelop,代碼行數:5,代碼來源:CSharpParser.cs

示例15: HoistedFieldAssign

			public HoistedFieldAssign (Expression target, Expression source)
				: base (target, source, target.Location)
			{
			}
開發者ID:rabink,項目名稱:mono,代碼行數:4,代碼來源:anonymous.cs


注:本文中的Mono.CSharp.Expression類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。