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


C# ExpressionSyntax.Member方法代码示例

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


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

示例1: GenerateMethodDispatcher

        /// <summary>
        /// Returns syntax for dispatching <paramref name="event"/> to <paramref name="method"/> on <paramref name="grain"/>.
        /// </summary>
        /// <param name="event">
        /// The event.
        /// </param>
        /// <param name="grain">
        /// The grain.
        /// </param>
        /// <param name="method">
        /// The method.
        /// </param>
        /// <returns>
        /// Syntax for dispatching <paramref name="event"/> to <paramref name="method"/> on <paramref name="grain"/>.
        /// </returns>
        private static StatementSyntax GenerateMethodDispatcher(
            ExpressionSyntax @event, 
            ExpressionSyntax grain, 
            MethodInfo method)
        {
            // Construct expressions to retrieve each of the method's parameters, starting with the 'self' parameter.
            var parameters = new List<ExpressionSyntax>();
            var methodParameters = method.GetParameters().ToList();
            for (var i = 0; i < methodParameters.Count; i++)
            {
                var parameter = methodParameters[i];
                var parameterType = parameter.ParameterType.GetTypeSyntax();
                var indexArg =
                    SF.Argument(
                        SF.LiteralExpression(SyntaxKind.NumericLiteralExpression, SF.Literal(i)));
                var getArg =
                    SF.InvocationExpression(@event.Member("Arg", parameterType)).AddArgumentListArguments(indexArg);
                parameters.Add(getArg);
            }

            var grainMethodCall =
                SF.InvocationExpression(grain.Member(method.Name))
                    .AddArgumentListArguments(parameters.Select(SF.Argument).ToArray());

            return SF.ReturnStatement(SF.InvocationExpression(grainMethodCall.Member("Box")));
        }
开发者ID:Bee-Htcpcp,项目名称:OrleansEventJournal,代码行数:41,代码来源:EventDispatcherGenerator.cs

示例2: GenerateActorBlock

        /// <summary>
        /// Returns syntax for dispatching <paramref name="event"/> to <paramref name="actor"/>.
        /// </summary>
        /// <param name="event">
        /// The event.
        /// </param>
        /// <param name="actor">
        /// The actor description.
        /// </param>
        /// <returns>
        /// Syntax for dispatching <paramref name="event"/> to <paramref name="actor"/>.
        /// </returns>
        private static StatementSyntax GenerateActorBlock(
            ExpressionSyntax @event, 
            ActorDescription actor)
        {
            var @var = SF.IdentifierName("var");
            var grainType = actor.Type.GetTypeSyntax();
            var getGrain =
                SF.InvocationExpression(SF.IdentifierName("GrainFactory").Member("GetGrain", grainType))
                    .AddArgumentListArguments(SF.Argument(@event.Member("To").Member("Id")));
            var grain = SF.VariableDeclarator("grain").WithInitializer(SF.EqualsValueClause(getGrain));
            var grainDeclaration = SF.LocalDeclarationStatement(SF.VariableDeclaration(@var).AddVariables(grain));

            var returnNull = SF.ReturnStatement(SF.LiteralExpression(SyntaxKind.NullLiteralExpression));

            var defaultSection = SF.SwitchSection().AddLabels(SF.DefaultSwitchLabel()).AddStatements(returnNull);
            var methodSwitch =
                SF.SwitchStatement(@event.Member("Type"))
                    .AddSections(
                        actor.Methods.Values.Where(_ => _.Visible)
                            .Select(method => GetMethodSwitchCase(@event, method))
                            .ToArray())
                    .AddSections(defaultSection);
            var methodDispatcher = SF.Block().AddStatements(grainDeclaration, methodSwitch);
            return methodDispatcher;
        }
开发者ID:Bee-Htcpcp,项目名称:OrleansEventJournal,代码行数:37,代码来源:EventDispatcherGenerator.cs


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