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


C# IdentifierExpression.Eval方法代码示例

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


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

示例1: Eval

			/// <summary>
			/// Evaluates to the final value, found based on the stored (and evaluated) property identifiers,
			/// and optionally the given parameters.
			/// Returns null inc ase something went wrong.
			/// </summary>
			public override L20nObject Eval(LocaleContext ctx, params L20nObject[] argv)
			{
				L20nObject maybe;
				int i = 0;

				// The root entity is either given as a parameter
				// or we need to get it using the first identifier.
				// See this.GetEntity for more information.
				if (argv == null || argv.Length == 0 || argv [0] as Dummy != null)
				{
					maybe = GetEntity(ctx, m_Identifiers [i]);
					i += 1;
				} else
				{
					maybe = argv [0];
				}

				// return null in case we have no root entity at all
				if (maybe == null)
				{
					Logger.Warning("<PropertyExpression>: couldn't evaluate first expression");
					return maybe;
				}

				L20nObject obj = maybe;

				// in case this property is pointing to a root entity,
				// directly requested by the L20n-user, we need to
				// evaluate it using the current identifier, such that
				// we can return null in case the Entity is private
				// and should thus not be requested.
				if (argv.Length == 1 && i < m_Identifiers.Length && (argv [0] as Dummy) != null)
				{
					obj = obj.Eval(ctx, argv [0], m_Identifiers [i]);
					++i;
				}

				// go through each identifier and replace the current Entity,
				// such that we can go deeper until we went through the
				// entire identifier list.
				for (; i < m_Identifiers.Length; ++i)
				{
					if (obj == null)
					{
						Logger.WarningFormat(
							"<PropertyExpression>: couldn't evaluate expression #{0}", i);
						return obj;
					}

					// check if we are dealing with a string
					// in which case we want to make it into an identifierExpression
					var stringObject = obj as StringOutput;
					if (stringObject != null)
					{
						// we do want to fall back to it being just a regular string,
						// in case that was the actual intention of the user
						L20nObject alt = new IdentifierExpression(stringObject.Value);
						alt = alt.Eval(ctx, m_Identifiers [i]);
						if (alt != null)
						{
							obj = alt;
							continue;
						}
					}

					obj = obj.Eval(ctx, m_Identifiers [i]);
				}

				if (obj == null)
				{
					Logger.Warning(
						"<PropertyExpression>: couldn't evaluate the final expression");
					return obj;
				}

				// if all is fine, we can now return the evaluation
				// of the last found value.
				return obj.Eval(ctx);
			}
开发者ID:GlenDC,项目名称:L20n.cs,代码行数:84,代码来源:PropertyExpression.cs


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