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


C# Expression.GetValue方法代码示例

本文整理汇总了C#中Expression.GetValue方法的典型用法代码示例。如果您正苦于以下问题:C# Expression.GetValue方法的具体用法?C# Expression.GetValue怎么用?C# Expression.GetValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Expression的用法示例。


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

示例1: GetUsedResources

        private List<string> GetUsedResources(Expression expression)
        {
            List<string> result = new List<string>();

            if (expression.IsOfType(ExpressionType.Resource))
            {
                result.Add(expression.GetValue(ResourceExpression.KEY));
            }
            foreach (Expression child in expression.Attributes.Values)
            {
                result.AddRange(GetUsedResources(child));
            }

            return result;
        }
开发者ID:snipervld,项目名称:StormXamarin,代码行数:15,代码来源:AbstractBindingHandlerClassGenerator.cs

示例2: GenerateStatementToGetTranslation

 private CodeMethodInvokeExpression GenerateStatementToGetTranslation(CodePropertyReferenceExpression localizationServiceReference, Expression translationExpression)
 {
     List<CodeExpression> parameters = new List<CodeExpression>();
     if (translationExpression.Has(TranslationExpression.UID))
     {
         //use method with two parameters.
         parameters.Add(new CodePrimitiveExpression(translationExpression.GetValue(TranslationExpression.UID)));
     }
     if (translationExpression.Has(TranslationExpression.KEY))
     {
         //use method with only key parameter.
         parameters.Add(new CodePrimitiveExpression(translationExpression.GetValue(TranslationExpression.KEY)));
     }
     CodeMethodInvokeExpression valueReference = new CodeMethodInvokeExpression(localizationServiceReference, "GetString", parameters.ToArray());
     return valueReference;
 }
开发者ID:snipervld,项目名称:StormXamarin,代码行数:16,代码来源:AbstractBindingHandlerClassGenerator.cs

示例3: EmitExactStringKeyHash

		private bool EmitExactStringKeyHash(PhpTypeCode keyTypeCode, Expression keyExpr)
		{
			if (keyExpr != null && keyTypeCode == PhpTypeCode.String && keyExpr.HasValue())
			{
                string skey = (string)keyExpr.GetValue();
				IntStringKey array_key = Convert.StringToArrayKey(skey);
				if (array_key.IsString && skey == array_key.String) // skey was not converted to int
				{
                    il.LdcI4(array_key.GetHashCode());  // == array_key.Integer == IntStringKey.StringKeyToArrayIndex(skey) // previously: skey.GetHashCode()
					return true;
				}
			}
			return false;
		}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:14,代码来源:CodeGenerator.cs

示例4: EmitArrayKey

		internal PhpTypeCode EmitArrayKey(ChainBuilder chain, Expression key)
		{
			PhpTypeCode result;

			if (key != null)
			{
				if (chain != null) chain.Create();
				
                // convert the key into integer if necessary and possible in compile time
                IntStringKey array_key;
                if (key.HasValue() && Convert.ObjectToArrayKey(key.GetValue(), out array_key) && array_key.IsInteger)
                {
                    il.LdcI4(array_key.Integer);
                    result = PhpTypeCode.Integer;
                }
                else
                {
                    // Emit index and box the result
                    switch (result = key.Emit(this))
                    {
                        case PhpTypeCode.Integer:
                            break;

                        case PhpTypeCode.String:
                            break;

                        default:
                            EmitBoxing(result);
                            result = PhpTypeCode.Object;
                            break;
                    }
                }
				
				if (chain != null) chain.End();
			}
			else
				result = PhpTypeCode.Invalid;

			return result;
		}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:40,代码来源:CodeGenerator.cs

示例5: EmitEval

        /// <summary>
        /// Emit call to <see cref="DynamicCode.Assert"/> or <see cref="DynamicCode.Eval"/>.
        /// </summary>
        internal PhpTypeCode EmitEval(EvalKinds kind, Expression/*!*/code, Text.Span span, QualifiedName? currentNamespace, Dictionary<string, QualifiedName> currentAliases)
        {
            Debug.Assert(code != null);

            // LOAD DynamicCode.<Eval | Assert>(<code>, context, definedVariables, self, includer, source, line, column, evalId, naming)
            if (kind == EvalKinds.Assert)
            {
                // an argument of the assert is boxed:
                EmitBoxing(code.Emit(this));
            }
            else if (kind == EvalKinds.SyntheticEval)
            {
                Debug.Assert(code.HasValue());
                Debug.Assert(code.GetValue() is string);

                // an argument of the eval is converted to a string:
                il.Emit(OpCodes.Ldstr, (string)code.GetValue());
                il.Emit(OpCodes.Ldc_I4_1);
            }
            else
            {
                // an argument of the eval is converted to a string:
                EmitConversion(code, PhpTypeCode.String);
                il.Emit(OpCodes.Ldc_I4_0);
            }

            var position = new Text.TextPoint(this.SourceUnit.LineBreaks, span.Start);

            EmitLoadScriptContext();
            EmitLoadRTVariablesTable();
            EmitLoadSelf();
            EmitLoadClassContext();
            EmitEvalInfoPass(position.Line, position.Column);
            EmitNamingContext(currentNamespace, currentAliases, span.Start);

            il.Emit(OpCodes.Call, (kind == EvalKinds.Assert) ? Methods.DynamicCode.Assert : Methods.DynamicCode.Eval);

            return (kind == EvalKinds.Assert) ? PhpTypeCode.Boolean : PhpTypeCode.Object;
        }
开发者ID:dw4dev,项目名称:Phalanger,代码行数:42,代码来源:CodeGenerator.cs

示例6: EmitConversion

		/// <summary>
		/// Emits IL instructions that convert the top of evaluation stack to a specified type.
		/// </summary>
		/// <remarks>
		/// Emits a call to one of <see cref="PHP.Core.Convert"/> methods to do the conversion.
		/// The method result is left on the evaluation stack.
		/// </remarks>
		internal void EmitConversion(Expression/*!*/ expression, PhpTypeCode dst)
		{
			// expression is evaluable:
			if (expression.HasValue())
			{
				switch (dst)
				{
					case PhpTypeCode.String:
						il.Emit(OpCodes.Ldstr, PHP.Core.Convert.ObjectToString(expression.GetValue()));
						break;

					case PhpTypeCode.Boolean:
                        il.LdcI4(PHP.Core.Convert.ObjectToBoolean(expression.GetValue()) ? 1 : 0);
						break;

					case PhpTypeCode.Integer:
                        il.LdcI4(PHP.Core.Convert.ObjectToInteger(expression.GetValue()));
						break;

					case PhpTypeCode.Double:
                        il.Emit(OpCodes.Ldc_R8, PHP.Core.Convert.ObjectToDouble(expression.GetValue()));
						break;

					case PhpTypeCode.Object:
                        il.LoadLiteral(expression.GetValue());
						break;

					default:
						Debug.Fail("Conversion not implemented.");
						break;
				}
			}
			else
			{
				// emits the expression:
				PhpTypeCode src = expression.Emit(this);

				// emits no conversion if types are the same:
				if (src == dst) return;

				// emits boxing if needed (conversion methods takes object):
				EmitBoxing(src);

				switch (dst)
				{
					case PhpTypeCode.String:
						il.Emit(OpCodes.Call, Methods.Convert.ObjectToString);
						break;

					case PhpTypeCode.Boolean:
						il.Emit(OpCodes.Call, Methods.Convert.ObjectToBoolean);
						break;

					case PhpTypeCode.Integer:
						il.Emit(OpCodes.Call, Methods.Convert.ObjectToBoolean);
						break;

					case PhpTypeCode.Double:
						il.Emit(OpCodes.Call, Methods.Convert.ObjectToDouble);
						break;

					case PhpTypeCode.Object:
						// nop //
						break;

					default:
						Debug.Fail("Conversion is not implemented.");
						break;
				}
			}
		}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:78,代码来源:CodeGenerator.cs


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