.editor config + fix line endings

This commit is contained in:
Stef Heyenrath
2021-08-03 06:13:13 +00:00
parent 8eb0733d6f
commit 7b158adadc
21 changed files with 528 additions and 523 deletions
@@ -1,77 +1,77 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis;
namespace ProxyInterfaceSourceGenerator.FileGenerators
{
internal abstract class BaseGenerator
{
protected readonly Context _context;
public BaseGenerator(Context context)
{
_context = context;
}
protected string GetPropertyType(IPropertySymbol property, out bool isReplaced)
{
return GetReplacedType(property.Type, out isReplaced);
}
protected string GetParameterType(IParameterSymbol property, out bool isReplaced)
{
return GetReplacedType(property.Type, out isReplaced);
}
protected string GetReplacedType(ITypeSymbol typeSymbol, out bool isReplaced)
{
isReplaced = false;
var typeSymbolAsString = typeSymbol.ToString();
var existing = _context.CandidateInterfaces.Values.FirstOrDefault(x => x.RawTypeName == typeSymbolAsString);
if (existing is not null)
{
if (!_context.ReplacedTypes.ContainsKey(typeSymbolAsString))
{
_context.ReplacedTypes.Add(typeSymbolAsString, existing.InterfaceName);
}
isReplaced = true;
return existing.InterfaceName;
}
if (typeSymbol is INamedTypeSymbol namedTypedSymbol)
{
var propertyTypeAsStringToBeModified = typeSymbolAsString;
foreach (var typeArgument in namedTypedSymbol.TypeArguments)
{
var typeArgumentAsString = typeArgument.ToString();
var exist = _context.CandidateInterfaces.Values.FirstOrDefault(x => x.RawTypeName == typeArgumentAsString);
if (exist is not null)
{
isReplaced = true;
if (!_context.ReplacedTypes.ContainsKey(typeArgumentAsString))
{
_context.ReplacedTypes.Add(typeArgumentAsString, exist.InterfaceName);
}
propertyTypeAsStringToBeModified = propertyTypeAsStringToBeModified.Replace(typeArgumentAsString, exist.InterfaceName);
}
}
return propertyTypeAsStringToBeModified;
}
return typeSymbolAsString;
}
protected INamedTypeSymbol GetNamedTypeSymbolByFullName(string name, IEnumerable<string>? usings = null)
{
// The GetTypeByMetadataName method returns null if no type matches the full name or if 2 or more types (in different assemblies) match the full name.
var symbol = _context.GeneratorExecutionContext.Compilation.GetTypeByMetadataName(name);
using System.Linq;
using Microsoft.CodeAnalysis;
namespace ProxyInterfaceSourceGenerator.FileGenerators
{
internal abstract class BaseGenerator
{
protected readonly Context _context;
public BaseGenerator(Context context)
{
_context = context;
}
protected string GetPropertyType(IPropertySymbol property, out bool isReplaced)
{
return GetReplacedType(property.Type, out isReplaced);
}
protected string GetParameterType(IParameterSymbol property, out bool isReplaced)
{
return GetReplacedType(property.Type, out isReplaced);
}
protected string GetReplacedType(ITypeSymbol typeSymbol, out bool isReplaced)
{
isReplaced = false;
var typeSymbolAsString = typeSymbol.ToString();
var existing = _context.CandidateInterfaces.Values.FirstOrDefault(x => x.RawTypeName == typeSymbolAsString);
if (existing is not null)
{
if (!_context.ReplacedTypes.ContainsKey(typeSymbolAsString))
{
_context.ReplacedTypes.Add(typeSymbolAsString, existing.InterfaceName);
}
isReplaced = true;
return existing.InterfaceName;
}
if (typeSymbol is INamedTypeSymbol namedTypedSymbol)
{
var propertyTypeAsStringToBeModified = typeSymbolAsString;
foreach (var typeArgument in namedTypedSymbol.TypeArguments)
{
var typeArgumentAsString = typeArgument.ToString();
var exist = _context.CandidateInterfaces.Values.FirstOrDefault(x => x.RawTypeName == typeArgumentAsString);
if (exist is not null)
{
isReplaced = true;
if (!_context.ReplacedTypes.ContainsKey(typeArgumentAsString))
{
_context.ReplacedTypes.Add(typeArgumentAsString, exist.InterfaceName);
}
propertyTypeAsStringToBeModified = propertyTypeAsStringToBeModified.Replace(typeArgumentAsString, exist.InterfaceName);
}
}
return propertyTypeAsStringToBeModified;
}
return typeSymbolAsString;
}
protected INamedTypeSymbol GetNamedTypeSymbolByFullName(string name, IEnumerable<string>? usings = null)
{
// The GetTypeByMetadataName method returns null if no type matches the full name or if 2 or more types (in different assemblies) match the full name.
var symbol = _context.GeneratorExecutionContext.Compilation.GetTypeByMetadataName(name);
if (symbol is not null)
{
return symbol;
@@ -86,10 +86,10 @@ namespace ProxyInterfaceSourceGenerator.FileGenerators
{
return symbol;
}
}
}
throw new Exception($"The type '{name}' is not found.");
}
}
}
}
throw new Exception($"The type '{name}' is not found.");
}
}
}
@@ -1,6 +1,6 @@
namespace ProxyInterfaceSourceGenerator.FileGenerators
{
internal record FileData(string FileName, string Text)
{
}
namespace ProxyInterfaceSourceGenerator.FileGenerators
{
internal record FileData(string FileName, string Text)
{
}
}
@@ -1,7 +1,7 @@
namespace ProxyInterfaceSourceGenerator.FileGenerators
{
internal interface IFileGenerator
{
FileData GenerateFile();
}
namespace ProxyInterfaceSourceGenerator.FileGenerators
{
internal interface IFileGenerator
{
FileData GenerateFile();
}
}
@@ -1,9 +1,9 @@
using System.Collections.Generic;
namespace ProxyInterfaceSourceGenerator.FileGenerators
{
internal interface IFilesGenerator
{
IEnumerable<FileData> GenerateFiles();
}
using System.Collections.Generic;
namespace ProxyInterfaceSourceGenerator.FileGenerators
{
internal interface IFilesGenerator
{
IEnumerable<FileData> GenerateFiles();
}
}
@@ -1,11 +1,10 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.CodeAnalysis;
using ProxyInterfaceSourceGenerator.Enums;
using ProxyInterfaceSourceGenerator.Extensions;
using ProxyInterfaceSourceGenerator.SyntaxReceiver;
using ProxyInterfaceSourceGenerator.Utils;
using System.Collections.Generic;
using System.Text;
namespace ProxyInterfaceSourceGenerator.FileGenerators
{
@@ -83,7 +82,7 @@ namespace {ns}
var type = ps.GetTypeEnum() == TypeEnum.Complex ? GetParameterType(ps, out _) : ps.Type.ToString();
methodParameters.Add($"{ps.GetParamsPrefix()}{ps.GetRefPrefix()}{type} {ps.GetSanitizedName()}{ps.GetDefaultValue()}");
}
str.AppendLine($" {GetReplacedType(method.ReturnType, out _)} {method.GetMethodNameWithOptionalTypeParameters()}({string.Join(", ", methodParameters)}){method.GetWhereStatement()};");
str.AppendLine();
}