コード例 #1
0
        protected override string GetBasicMethodImpl(MethodInfo methodInfo)
        {
            var invokeArguments = GetInvokeArguments(methodInfo);

            int methodId = GrainInterfaceData.ComputeMethodId(methodInfo);
            string methodImpl;
            string optional = null;

            if (GrainInterfaceData.IsReadOnly(methodInfo))
                optional = ", options:= Global.Orleans.CodeGeneration.InvokeMethodOptions.ReadOnly";
            
            if (GrainInterfaceData.IsUnordered(methodInfo))
            {
                if (optional == null)
                    optional = ", options:= ";
                else
                    optional += " | ";

                optional += " Global.Orleans.CodeGeneration.InvokeMethodOptions.Unordered";
            }

            if (GrainInterfaceData.IsAlwaysInterleave(methodInfo))
            {
                if (optional == null)
                    optional = ", options:= ";
                else
                    optional += " | ";

                optional += " Global.Orleans.CodeGeneration.InvokeMethodOptions.AlwaysInterleave";
            }

            if (methodInfo.ReturnType == typeof(void))
            {
                methodImpl = string.Format(@"
                MyBase.InvokeOneWayMethod({0}, New System.Object() {{{1}}} {2})",
                methodId, invokeArguments, optional);
            }
            else
            {
                if (methodInfo.ReturnType == typeof (Task))
                {
                    methodImpl = string.Format(@"
                Return MyBase.InvokeMethodAsync(Of System.Object)({0}, New System.Object() {{{1}}} {2})",
                        methodId,
                        invokeArguments,
                        optional);
                }
                else
                {
                    methodImpl = string.Format(@"
                Return MyBase.InvokeMethodAsync(Of {0})({1}, New System.Object() {{{2}}} {3})",
                        GetActualMethodReturnType(methodInfo.ReturnType, SerializeFlag.NoSerialize),
                        methodId,
                        invokeArguments,
                        optional);
                }
            }
            return GetParamGuardCheckStatements(methodInfo) + methodImpl;
        }
コード例 #2
0
        /// <summary>
        /// Returns syntax for the options argument to <see cref="GrainReference.InvokeMethodAsync{T}"/> and <see cref="GrainReference.InvokeOneWayMethod"/>.
        /// </summary>
        /// <param name="method">The method which an invoke call is being generated for.</param>
        /// <returns>
        /// Argument syntax for the options argument to <see cref="GrainReference.InvokeMethodAsync{T}"/> and
        /// <see cref="GrainReference.InvokeOneWayMethod"/>, or <see langword="null"/> if no options are to be specified.
        /// </returns>
        private static ArgumentSyntax GetInvokeOptions(MethodInfo method)
        {
            var options = new List <ExpressionSyntax>();

            if (GrainInterfaceData.IsReadOnly(method))
            {
                options.Add(typeof(InvokeMethodOptions).GetNameSyntax().Member(InvokeMethodOptions.ReadOnly.ToString()));
            }

            if (GrainInterfaceData.IsUnordered(method))
            {
                options.Add(typeof(InvokeMethodOptions).GetNameSyntax().Member(InvokeMethodOptions.Unordered.ToString()));
            }

            if (GrainInterfaceData.IsAlwaysInterleave(method))
            {
                options.Add(typeof(InvokeMethodOptions).GetNameSyntax().Member(InvokeMethodOptions.AlwaysInterleave.ToString()));
            }

            ExpressionSyntax allOptions;

            if (options.Count <= 1)
            {
                allOptions = options.FirstOrDefault();
            }
            else
            {
                allOptions =
                    options.Aggregate((a, b) => SF.BinaryExpression(SyntaxKind.BitwiseOrExpression, a, b));
            }

            if (allOptions == null)
            {
                return(null);
            }

            return(SF.Argument(SF.NameColon("options"), SF.Token(SyntaxKind.None), allOptions));
        }
コード例 #3
0
ファイル: CSharpCodeGenerator.cs プロジェクト: uehara/orleans
        protected override string GetBasicMethodImpl(MethodInfo methodInfo)
        {
            string invokeArguments = GetInvokeArguments(methodInfo);
            int    methodId        = GrainInterfaceData.ComputeMethodId(methodInfo);
            string methodImpl;
            string optional = null;

            if (GrainInterfaceData.IsReadOnly(methodInfo))
            {
                optional = ", options: global::Orleans.CodeGeneration.InvokeMethodOptions.ReadOnly";
            }

            if (GrainInterfaceData.IsUnordered(methodInfo))
            {
                if (optional == null)
                {
                    optional = ", options: ";
                }
                else
                {
                    optional += " | ";
                }

                optional += " global::Orleans.CodeGeneration.InvokeMethodOptions.Unordered";
            }

            if (GrainInterfaceData.IsAlwaysInterleave(methodInfo))
            {
                if (optional == null)
                {
                    optional = ", options: ";
                }
                else
                {
                    optional += " | ";
                }

                optional += " global::Orleans.CodeGeneration.InvokeMethodOptions.AlwaysInterleave";
            }

            if (methodInfo.ReturnType == typeof(void))
            {
                methodImpl = string.Format(@"
                    base.InvokeOneWayMethod({0}, {1} {2});",
                                           methodId,
                                           invokeArguments.Equals(string.Empty) ? "null" : String.Format("new object[] {{{0}}}", invokeArguments),
                                           optional);
            }
            else
            {
                if (methodInfo.ReturnType == typeof(Task))
                {
                    methodImpl = string.Format(@"
                return base.InvokeMethodAsync<object>({0}, {1} {2});",
                                               methodId,
                                               invokeArguments.Equals(string.Empty) ? "null" : String.Format("new object[] {{{0}}}", invokeArguments),
                                               optional);
                }
                else
                {
                    methodImpl = string.Format(@"
                return base.InvokeMethodAsync<{0}>({1}, {2} {3});",
                                               GetActualMethodReturnType(methodInfo.ReturnType, SerializeFlag.NoSerialize),
                                               methodId,
                                               invokeArguments.Equals(string.Empty) ? "null" : String.Format("new object[] {{{0}}}", invokeArguments),
                                               optional);
                }
            }
            return(GetParamGuardCheckStatements(methodInfo) + methodImpl);
        }