Exemple #1
0
        private void BuildGetMethodMetadata(InterfaceDescription interfaceDescription, OperationDescription method)
        {
            Output
            .Append("private IList<object> ")
            .Append(GetMethodMetadataName(method))
            .AppendLine("()")
            .AppendLine("{");

            using (Output.Indent())
            {
                Output
                .AppendLine("var metadata = new List<object>();")
                .AppendLine("ServiceGetMetadata(metadata);");

                var implementation = method.Method.Source;
                if (SyntaxTools.IsInterface(_contract.ContractInterface))
                {
                    Output
                    .Append("// copy attributes from method ")
                    .Append(interfaceDescription.InterfaceType.Name)
                    .Append(".")
                    .AppendLine(implementation.Name);
                }
                else
                {
                    implementation = _contract.ContractInterface.GetInterfaceImplementation(method.Method.Source);
                    Output
                    .Append("// copy attributes from method ")
                    .Append(implementation.Name)
                    .Append(", implementation of ")
                    .Append(interfaceDescription.InterfaceType.Name)
                    .Append(".")
                    .AppendLine(method.Method.Name);
                }

                var length = Output.Length;

                foreach (var attribute in FilterAttributes(implementation.GetAttributes()))
                {
                    Output.Append("metadata.Add(");
                    WriteNewAttribute(Output, attribute);
                    Output.AppendLine(");");
                }

                if (Output.Length == length)
                {
                    Output.AppendLine("// no applicable attributes found");
                }

                Output
                .Append(GetMethodMetadataName(method))
                .AppendLine("Override(metadata);")
                .AppendLine("return metadata;");
            }

            Output.AppendLine("}");
        }
Exemple #2
0
 public virtual void CompileLines()
 {
     foreach (string Line in Lines)
     {
         string   newLine = SyntaxTools.GetNewLine(Line);
         string[] Words   = newLine.Split('=');
         Tools.ExecuteAllAnalyzerFunc(Words, this);
     }
 }
        private void BuildServerStreamingResultAdapter(OperationDescription operation, string functionName)
        {
            var returnType = SyntaxTools.GetFullName(operation.Method.ReturnTypeSymbol.GenericTypeArguments()[0]);

            Output
            .Append("private static ")
            .Append(returnType)
            .Append(" ")
            .Append(functionName)
            .Append("(")
            .Append(nameof(ValueTuple))
            .Append("<")
            .Append(operation.HeaderResponseType !.ClassName)
            .Append(", IAsyncEnumerable<")
            .Append(operation.ResponseType.Properties[0])
            .Append(">>")
            .AppendLine("response)");

            Output.AppendLine("{");
            using (Output.Indent())
            {
                Output.AppendLine("var message = response.Item1;");

                Output
                .Append("return new ")
                .Append(returnType)
                .Append("(");

                // operation.ResponseTypeIndex;
                var propertiesCount = operation.HeaderResponseTypeInput.Length + 1;
                for (var i = 0; i < propertiesCount; i++)
                {
                    string value;
                    if (i == operation.ResponseTypeIndex)
                    {
                        value = "response.Item2";
                    }
                    else
                    {
                        var index = Array.IndexOf(operation.HeaderResponseTypeInput, i) + 1;
                        value = "message.Value" + index.ToString(CultureInfo.InvariantCulture);
                    }

                    if (i > 0)
                    {
                        Output.Append(", ");
                    }

                    Output.Append(value);
                }

                Output.AppendLine(");");
            }

            Output.AppendLine("}");
        }
Exemple #4
0
        private static IEnumerable <TestCaseData> GetWriteNewAttributeCases()
        {
            var type   = typeof(WriteNewAttributeCases);
            var symbol = Compilation.GetTypeByMetadataName(type);

            foreach (var method in SyntaxTools.GetInstanceMethods(symbol))
            {
                var attributes = CSharpServiceEndpointBinderBuilder.FilterAttributes(method.GetAttributes()).ToList();
                attributes.Count.ShouldBe(1);

                var expected = (string)type
                               .GetMethod(method.Name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)
                               ?.Invoke(new WriteNewAttributeCases(), Array.Empty <object>()) !;

                yield return(new TestCaseData(attributes[0], expected)
                {
                    TestName = "WriteAttribute." + method.Name
                });
            }
        }
Exemple #5
0
        private void InitializeCallOptionsBuilderVariable(OperationDescription operation)
        {
            Output
            .Append("var ")
            .Append(VarCallOptionsBuilder)
            .Append(" = new ")
            .AppendType(typeof(CallOptionsBuilder))
            .Append("(DefaultCallOptionsFactory)");

            using (Output.Indent())
            {
                for (var i = 0; i < operation.ContextInput.Length; i++)
                {
                    var parameter = operation.Method.Parameters[operation.ContextInput[i]];
                    var type      = SyntaxTools.IsNullable(parameter.TypeSymbol) ? parameter.TypeSymbol.GenericTypeArguments()[0] : parameter.TypeSymbol;
                    Output
                    .AppendLine()
                    .Append(".With").Append(type.Name).Append("(").Append(parameter.Name).Append(")");
                }

                Output.AppendLine(";");
            }
        }
 public static bool Math(AttributeData attributeData)
 {
     return(attributeData.AttributeClass != null &&
            "ServiceModel.Grpc.DesignTime.ExportGrpcServiceAttribute".Equals(SyntaxTools.GetFullName(attributeData.AttributeClass), StringComparison.Ordinal));
 }