Skip to content

Commit d52df52

Browse files
committed
Add OperationInvoker source generator
1 parent 6a652f6 commit d52df52

24 files changed

+2072
-0
lines changed

System.ServiceModel.sln

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.ServiceModel.UnixDom
8989
EndProject
9090
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Binding.UDS.IntegrationTests", "src\System.Private.ServiceModel\tests\Scenarios\Binding\UDS\Binding.UDS.IntegrationTests.csproj", "{B7C7D4F1-DE4D-421B-9CE9-C7320A503D58}"
9191
EndProject
92+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.ServiceModel.BuildTools.Roslyn4.0", "src\System.ServiceModel.BuildTools\src\System.ServiceModel.BuildTools.Roslyn4.0.csproj", "{C03919A5-503D-4FC1-A9C2-F534EE25D84B}"
93+
EndProject
94+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.ServiceModel.BuildTools.Roslyn3.11", "src\System.ServiceModel.BuildTools\src\System.ServiceModel.BuildTools.Roslyn3.11.csproj", "{83BB41BB-CB6E-4D32-9CD1-384FEAE88949}"
95+
EndProject
96+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.ServiceModel.BuildTools.Roslyn3.11.Tests", "src\System.ServiceModel.BuildTools\tests\System.ServiceModel.BuildTools.Roslyn3.11.Tests.csproj", "{5D1B7FB8-3A9B-487F-96C0-76ACC43D98A2}"
97+
EndProject
98+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.ServiceModel.BuildTools.Roslyn4.0.Tests", "src\System.ServiceModel.BuildTools\tests\System.ServiceModel.BuildTools.Roslyn4.0.Tests.csproj", "{6B670970-CAD2-446E-AC83-2BF097E4CD5E}"
99+
EndProject
92100
Global
93101
GlobalSection(SolutionConfigurationPlatforms) = preSolution
94102
Debug|Any CPU = Debug|Any CPU
@@ -259,6 +267,22 @@ Global
259267
{B7C7D4F1-DE4D-421B-9CE9-C7320A503D58}.Debug|Any CPU.Build.0 = Debug|Any CPU
260268
{B7C7D4F1-DE4D-421B-9CE9-C7320A503D58}.Release|Any CPU.ActiveCfg = Release|Any CPU
261269
{B7C7D4F1-DE4D-421B-9CE9-C7320A503D58}.Release|Any CPU.Build.0 = Release|Any CPU
270+
{C03919A5-503D-4FC1-A9C2-F534EE25D84B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
271+
{C03919A5-503D-4FC1-A9C2-F534EE25D84B}.Debug|Any CPU.Build.0 = Debug|Any CPU
272+
{C03919A5-503D-4FC1-A9C2-F534EE25D84B}.Release|Any CPU.ActiveCfg = Release|Any CPU
273+
{C03919A5-503D-4FC1-A9C2-F534EE25D84B}.Release|Any CPU.Build.0 = Release|Any CPU
274+
{83BB41BB-CB6E-4D32-9CD1-384FEAE88949}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
275+
{83BB41BB-CB6E-4D32-9CD1-384FEAE88949}.Debug|Any CPU.Build.0 = Debug|Any CPU
276+
{83BB41BB-CB6E-4D32-9CD1-384FEAE88949}.Release|Any CPU.ActiveCfg = Release|Any CPU
277+
{83BB41BB-CB6E-4D32-9CD1-384FEAE88949}.Release|Any CPU.Build.0 = Release|Any CPU
278+
{5D1B7FB8-3A9B-487F-96C0-76ACC43D98A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
279+
{5D1B7FB8-3A9B-487F-96C0-76ACC43D98A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
280+
{5D1B7FB8-3A9B-487F-96C0-76ACC43D98A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
281+
{5D1B7FB8-3A9B-487F-96C0-76ACC43D98A2}.Release|Any CPU.Build.0 = Release|Any CPU
282+
{6B670970-CAD2-446E-AC83-2BF097E4CD5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
283+
{6B670970-CAD2-446E-AC83-2BF097E4CD5E}.Debug|Any CPU.Build.0 = Debug|Any CPU
284+
{6B670970-CAD2-446E-AC83-2BF097E4CD5E}.Release|Any CPU.ActiveCfg = Release|Any CPU
285+
{6B670970-CAD2-446E-AC83-2BF097E4CD5E}.Release|Any CPU.Build.0 = Release|Any CPU
262286
EndGlobalSection
263287
GlobalSection(SolutionProperties) = preSolution
264288
HideSolutionNode = FALSE
@@ -296,6 +320,8 @@ Global
296320
{E8E40B62-E737-4768-82C2-039E90ED9A39} = {D6302510-AB10-4775-BCE9-98FA96FDEB76}
297321
{88918456-A2B2-431F-BB95-BAAD2818BFC7} = {DFDC71CF-6E65-481D-99D7-C35ED7EF6D4E}
298322
{B7C7D4F1-DE4D-421B-9CE9-C7320A503D58} = {D6302510-AB10-4775-BCE9-98FA96FDEB76}
323+
{5D1B7FB8-3A9B-487F-96C0-76ACC43D98A2} = {DFDC71CF-6E65-481D-99D7-C35ED7EF6D4E}
324+
{6B670970-CAD2-446E-AC83-2BF097E4CD5E} = {DFDC71CF-6E65-481D-99D7-C35ED7EF6D4E}
299325
EndGlobalSection
300326
GlobalSection(ExtensibilityGlobals) = postSolution
301327
SolutionGuid = {E0638FAC-BA6B-4E18-BAE6-468C3191BE58}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Linq;
5+
using Microsoft.CodeAnalysis;
6+
using Microsoft.CodeAnalysis.CSharp;
7+
using Microsoft.CodeAnalysis.CSharp.Syntax;
8+
9+
namespace System.ServiceModel.BuildTools
10+
{
11+
internal static class MethodSymbolExtensions
12+
{
13+
public static bool? IsGeneratedCode(this IMethodSymbol methodSymbol)
14+
=> methodSymbol.Locations.FirstOrDefault()?.SourceTree?.FilePath.EndsWith(".g.cs");
15+
16+
public static bool IsMatchingUserProvidedMethod(this IMethodSymbol methodSymbol, IMethodSymbol userProvidedMethodSymbol, INamedTypeSymbol? coreWCFInjectedAttribute, INamedTypeSymbol? fromServicesAttribute)
17+
{
18+
int parameterFound = 0;
19+
if (methodSymbol.Name != userProvidedMethodSymbol.Name)
20+
{
21+
return false;
22+
}
23+
24+
var parameters = methodSymbol.Parameters;
25+
26+
for (int i = 0,j = 0; i < userProvidedMethodSymbol.Parameters.Length; i++)
27+
{
28+
IParameterSymbol parameterSymbol = userProvidedMethodSymbol.Parameters[i];
29+
if (parameterSymbol.GetOneAttributeOf(coreWCFInjectedAttribute, fromServicesAttribute) is not null)
30+
{
31+
continue;
32+
}
33+
34+
if (parameterSymbol.IsMatchingParameter(parameters[j]))
35+
{
36+
j++;
37+
parameterFound++;
38+
}
39+
}
40+
41+
return parameterFound == parameters.Length;
42+
}
43+
}
44+
45+
internal static class ParameterSymbolExtensions
46+
{
47+
public static bool IsMatchingParameter(this IParameterSymbol symbol, IParameterSymbol parameterSymbol)
48+
=> SymbolEqualityComparer.Default.Equals(symbol.Type, parameterSymbol.Type);
49+
}
50+
51+
internal static class SymbolExtensions
52+
{
53+
public static AttributeData? GetOneAttributeOf(this ISymbol symbol, params INamedTypeSymbol?[] attributeTypeSymbols)
54+
{
55+
if (attributeTypeSymbols.Length == 0)
56+
{
57+
return null;
58+
}
59+
60+
foreach (var attribute in symbol.GetAttributes())
61+
{
62+
foreach (var namedTypeSymbol in attributeTypeSymbols.Where(static s => s is not null))
63+
{
64+
if (SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, namedTypeSymbol))
65+
{
66+
return attribute;
67+
}
68+
}
69+
}
70+
71+
return null;
72+
}
73+
74+
public static bool HasOneAttributeInheritFrom(this ISymbol symbol, params INamedTypeSymbol?[] attributeTypeSymbols)
75+
{
76+
if (attributeTypeSymbols.Length == 0)
77+
{
78+
return false;
79+
}
80+
81+
foreach (var attribute in symbol.GetAttributes())
82+
{
83+
foreach (var @interface in attribute.AttributeClass!.AllInterfaces)
84+
{
85+
foreach (var namedTypeSymbol in attributeTypeSymbols.Where(static s => s is not null))
86+
{
87+
if (SymbolEqualityComparer.Default.Equals(@interface, namedTypeSymbol))
88+
{
89+
return true;
90+
}
91+
}
92+
}
93+
}
94+
95+
return false;
96+
}
97+
}
98+
99+
internal static class NamedTypeSymbolExtensions
100+
{
101+
public static bool IsPartial(this INamedTypeSymbol namedTypeSymbol, out INamedTypeSymbol parentType)
102+
{
103+
bool result = namedTypeSymbol.DeclaringSyntaxReferences.Select(static s => s.GetSyntax()).OfType<ClassDeclarationSyntax>().All(static c => c.Modifiers.Any(static m => m.IsKind(SyntaxKind.PartialKeyword)));
104+
if (result && namedTypeSymbol.ContainingType != null)
105+
{
106+
return namedTypeSymbol.ContainingType.IsPartial(out parentType);
107+
}
108+
parentType = namedTypeSymbol;
109+
return result;
110+
}
111+
}
112+
113+
internal static class TypedConstantExtensions
114+
{
115+
public static string ToSafeCSharpString(this TypedConstant typedConstant)
116+
{
117+
if (typedConstant.Kind == TypedConstantKind.Array)
118+
{
119+
return $"new [] {typedConstant.ToCSharpString()}";
120+
}
121+
122+
return typedConstant.ToCSharpString();
123+
124+
}
125+
}
126+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace System.ServiceModel.BuildTools
5+
{
6+
internal sealed class Indentor
7+
{
8+
const string ____ = " ";
9+
const string ________ = " ";
10+
const string ____________ = " ";
11+
const string ________________ = " ";
12+
const string ____________________ = " ";
13+
const string ________________________ = " ";
14+
const string ____________________________ = " ";
15+
const string ________________________________ = " ";
16+
public int Level { get; private set; } = 0;
17+
public void Increment()
18+
{
19+
Level++;
20+
}
21+
22+
public void Decrement()
23+
{
24+
Level--;
25+
}
26+
27+
public override string ToString() => Level switch
28+
{
29+
0 => string.Empty,
30+
1 => ____,
31+
2 => ________,
32+
3 => ____________,
33+
4 => ________________,
34+
5 => ____________________,
35+
6 => ________________________,
36+
7 => ____________________________,
37+
8 => ________________________________,
38+
_ => throw new InvalidOperationException()
39+
};
40+
}
41+
}

0 commit comments

Comments
 (0)