forked from dotnet/wcf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OperationInvoker source generator
- Loading branch information
Showing
24 changed files
with
2,078 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/System.ServiceModel.BuildTools/src/AnalyzerReleases.Shipped.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
1 change: 1 addition & 0 deletions
1
src/System.ServiceModel.BuildTools/src/AnalyzerReleases.Unshipped.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Linq; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
|
||
namespace System.ServiceModel.BuildTools | ||
{ | ||
internal static class MethodSymbolExtensions | ||
{ | ||
public static bool? IsGeneratedCode(this IMethodSymbol methodSymbol) | ||
=> methodSymbol.Locations.FirstOrDefault()?.SourceTree?.FilePath.EndsWith(".g.cs"); | ||
|
||
public static bool IsMatchingUserProvidedMethod(this IMethodSymbol methodSymbol, IMethodSymbol userProvidedMethodSymbol, INamedTypeSymbol? coreWCFInjectedAttribute, INamedTypeSymbol? fromServicesAttribute) | ||
{ | ||
int parameterFound = 0; | ||
if (methodSymbol.Name != userProvidedMethodSymbol.Name) | ||
{ | ||
return false; | ||
} | ||
|
||
var parameters = methodSymbol.Parameters; | ||
|
||
for (int i = 0,j = 0; i < userProvidedMethodSymbol.Parameters.Length; i++) | ||
{ | ||
IParameterSymbol parameterSymbol = userProvidedMethodSymbol.Parameters[i]; | ||
if (parameterSymbol.GetOneAttributeOf(coreWCFInjectedAttribute, fromServicesAttribute) is not null) | ||
{ | ||
continue; | ||
} | ||
|
||
if (parameterSymbol.IsMatchingParameter(parameters[j])) | ||
{ | ||
j++; | ||
parameterFound++; | ||
} | ||
} | ||
|
||
return parameterFound == parameters.Length; | ||
} | ||
} | ||
|
||
internal static class ParameterSymbolExtensions | ||
{ | ||
public static bool IsMatchingParameter(this IParameterSymbol symbol, IParameterSymbol parameterSymbol) | ||
=> SymbolEqualityComparer.Default.Equals(symbol.Type, parameterSymbol.Type); | ||
} | ||
|
||
internal static class SymbolExtensions | ||
{ | ||
public static AttributeData? GetOneAttributeOf(this ISymbol symbol, params INamedTypeSymbol?[] attributeTypeSymbols) | ||
{ | ||
if (attributeTypeSymbols.Length == 0) | ||
{ | ||
return null; | ||
} | ||
|
||
foreach (var attribute in symbol.GetAttributes()) | ||
{ | ||
foreach (var namedTypeSymbol in attributeTypeSymbols.Where(static s => s is not null)) | ||
{ | ||
if (SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, namedTypeSymbol)) | ||
{ | ||
return attribute; | ||
} | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public static bool HasOneAttributeInheritFrom(this ISymbol symbol, params INamedTypeSymbol?[] attributeTypeSymbols) | ||
{ | ||
if (attributeTypeSymbols.Length == 0) | ||
{ | ||
return false; | ||
} | ||
|
||
foreach (var attribute in symbol.GetAttributes()) | ||
{ | ||
foreach (var @interface in attribute.AttributeClass!.AllInterfaces) | ||
{ | ||
foreach (var namedTypeSymbol in attributeTypeSymbols.Where(static s => s is not null)) | ||
{ | ||
if (SymbolEqualityComparer.Default.Equals(@interface, namedTypeSymbol)) | ||
{ | ||
return true; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
|
||
internal static class NamedTypeSymbolExtensions | ||
{ | ||
public static bool IsPartial(this INamedTypeSymbol namedTypeSymbol, out INamedTypeSymbol parentType) | ||
{ | ||
bool result = namedTypeSymbol.DeclaringSyntaxReferences.Select(static s => s.GetSyntax()).OfType<ClassDeclarationSyntax>().All(static c => c.Modifiers.Any(static m => m.IsKind(SyntaxKind.PartialKeyword))); | ||
if (result && namedTypeSymbol.ContainingType != null) | ||
{ | ||
return namedTypeSymbol.ContainingType.IsPartial(out parentType); | ||
} | ||
parentType = namedTypeSymbol; | ||
return result; | ||
} | ||
} | ||
|
||
internal static class TypedConstantExtensions | ||
{ | ||
public static string ToSafeCSharpString(this TypedConstant typedConstant) | ||
{ | ||
if (typedConstant.Kind == TypedConstantKind.Array) | ||
{ | ||
return $"new [] {typedConstant.ToCSharpString()}"; | ||
} | ||
|
||
return typedConstant.ToCSharpString(); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace System.ServiceModel.BuildTools | ||
{ | ||
internal sealed class Indentor | ||
{ | ||
const string ____ = " "; | ||
const string ________ = " "; | ||
const string ____________ = " "; | ||
const string ________________ = " "; | ||
const string ____________________ = " "; | ||
const string ________________________ = " "; | ||
const string ____________________________ = " "; | ||
const string ________________________________ = " "; | ||
public int Level { get; private set; } = 0; | ||
public void Increment() | ||
{ | ||
Level++; | ||
} | ||
|
||
public void Decrement() | ||
{ | ||
Level--; | ||
} | ||
|
||
public override string ToString() => Level switch | ||
{ | ||
0 => string.Empty, | ||
1 => ____, | ||
2 => ________, | ||
3 => ____________, | ||
4 => ________________, | ||
5 => ____________________, | ||
6 => ________________________, | ||
7 => ____________________________, | ||
8 => ________________________________, | ||
_ => throw new InvalidOperationException() | ||
}; | ||
} | ||
} |
Oops, something went wrong.