本文整理汇总了C#中Aplus.GetMemberBinder方法的典型用法代码示例。如果您正苦于以下问题:C# Aplus.GetMemberBinder方法的具体用法?C# Aplus.GetMemberBinder怎么用?C# Aplus.GetMemberBinder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Aplus
的用法示例。
在下文中一共展示了Aplus.GetMemberBinder方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetVariable
/// <summary>
/// Constructs a DLR Expression tree representing setting a variable inside a context.
/// </summary>
/// <param name="runtime"></param>
/// <param name="variableContainer">The container where the lookup should be performed</param>
/// <param name="contextParts">
/// Contains 2 strings:
/// 1. The name of the context
/// 2. The name of the variable inside the context
/// </param>
/// <param name="value">Expression containing the value of the variable</param>
/// <remarks>
/// The returned DLR Expression tree will try to fetch the context inside the container.
/// If the context does not exists, this will result an exception.
/// If the exception occured, the context will be created inside the catch block.
/// After this the context surely exists, so we can simply set the variable to the provided value.
///
/// </remarks>
/// <returns>>Expression tree for setting a value for the given context parts</returns>
internal static DLR.Expression SetVariable(Aplus runtime, DLR.Expression variableContainer, string[] contextParts, DLR.Expression value)
{
// Get the context
DLR.Expression getContext =
DLR.Expression.TryCatch(
DLR.Expression.Dynamic(
runtime.GetMemberBinder(contextParts[0]),
typeof(object),
variableContainer
),
DLR.Expression.Catch(
// Context not found, create one!
typeof(Error.Value),
DLR.Expression.Dynamic(
runtime.SetMemberBinder(contextParts[0]),
typeof(object),
variableContainer,
DLR.Expression.Constant(new ScopeStorage())
)
)
);
DLR.Expression setVariable = DLR.Expression.Dynamic(
runtime.SetMemberBinder(contextParts[1]),
typeof(object),
getContext,
value
);
return setVariable;
}
示例2: GetVariable
/// <summary>
/// Constructs a DLR Expression tree representing accessing a variable inside a context
/// </summary>
/// <param name="runtime"></param>
/// <param name="variableContainer">The container where the lookup should be performed</param>
/// <param name="contextParts">
/// Contains 2 strings:
/// 1. The name of the context
/// 2. The name of the variable inside the context
/// </param>
/// <returns>Expression tree for retrieving a value for the given context parts</returns>
internal static DLR.Expression GetVariable(Aplus runtime, DLR.Expression variableContainer, string[] contextParts)
{
// Get the context
DLR.Expression contextAccess = DLR.Expression.Dynamic(
runtime.GetMemberBinder(contextParts[0]),
typeof(object),
variableContainer
);
// Get the variable from the context
DLR.Expression variableAccess = DLR.Expression.Dynamic(
runtime.GetMemberBinder(contextParts[1]),
typeof(object),
contextAccess
);
return variableAccess;
}