本文整理汇总了C#中IContext.Get方法的典型用法代码示例。如果您正苦于以下问题:C# IContext.Get方法的具体用法?C# IContext.Get怎么用?C# IContext.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IContext
的用法示例。
在下文中一共展示了IContext.Get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: interpolate
/// <summary> Utility method to interpolate context variables
/// into string literals. So that the following will
/// work:
/// *
/// #set $name = "candy"
/// $image.getURI("${name}.jpg")
/// *
/// And the string literal argument will
/// be transformed into "candy.jpg" before
/// the method is executed.
/// </summary>
public static String interpolate(String argStr, IContext vars)
{
StringBuilder argBuf = new StringBuilder();
for(int cIdx = 0; cIdx < argStr.Length;)
{
char ch = argStr[cIdx];
switch(ch)
{
case '$':
StringBuilder nameBuf = new StringBuilder();
for(++cIdx; cIdx < argStr.Length; ++cIdx)
{
ch = argStr[cIdx];
if (ch == '_' || ch == '-' || Char.IsLetterOrDigit(ch))
{
nameBuf.Append(ch);
}
else if (ch == '{' || ch == '}')
{
continue;
}
else
{
break;
}
}
if (nameBuf.Length > 0)
{
Object value = vars.Get(nameBuf.ToString());
if (value == null)
{
argBuf.Append("$").Append(nameBuf.ToString());
}
else
{
//UPGRADE_TODO: The equivalent in .NET for method 'java.Object.toString' may return a different value. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1043"'
argBuf.Append(value.ToString());
}
}
break;
default:
argBuf.Append(ch);
++cIdx;
break;
}
}
return argBuf.ToString();
}
示例2: GetVariableValue
public Object GetVariableValue(IContext context, String variable)
{
return context.Get(variable);
}