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


C# Aplus.GetMemberBinder方法代碼示例

本文整理匯總了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;
        }
開發者ID:sammoorhouse,項目名稱:aplusdotnet,代碼行數:49,代碼來源:VariableHelper.cs

示例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;
        }
開發者ID:sammoorhouse,項目名稱:aplusdotnet,代碼行數:28,代碼來源:VariableHelper.cs


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