fix: Fixes sourcegen spacing (#766)

This commit is contained in:
Kamron Batman 2021-09-05 13:18:31 -07:00 committed by GitHub
parent 04b5a6c609
commit 21aa6aaade
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 8 deletions

View file

@ -225,12 +225,12 @@ namespace SerializationGenerator
if (attrTypeArg.Kind == TypedConstantKind.Primitive && attrTypeArg.Value is string attrStr)
{
source.AppendLine($"{indent} {attrStr}");
source.AppendLine($"{indent}{attrStr}");
}
else
{
var attrType = (ITypeSymbol)attrTypeArg.Value;
source.GenerateAttribute(attrType?.Name, ctorArgs[1].Values);
source.GenerateAttribute(indent, attrType?.Name, ctorArgs[1].Values);
}
}
@ -245,6 +245,7 @@ namespace SerializationGenerator
{
source.GenerateSerializableProperty(
compilation,
indent,
fieldSymbol,
getterAccessor,
setterAccessor,
@ -357,7 +358,7 @@ namespace SerializationGenerator
int index = 0;
foreach (var (order, _) in serializableFieldSaveFlags)
{
source.GenerateEnumValue($"{indent} ", true, serializableProperties[order].Name, index++);
source.GenerateEnumValue($"{indent} ", true, serializableProperties[order].Name, index++);
}
source.GenerateEnumEnd($"{indent} ");

View file

@ -24,6 +24,7 @@ namespace SerializationGenerator
public static void GenerateSerializableProperty(
this StringBuilder source,
Compilation compilation,
string indent,
IFieldSymbol fieldSymbol,
Accessibility getter,
Accessibility? setter,
@ -43,9 +44,8 @@ namespace SerializationGenerator
) ?? false
);
const string indent = " ";
const string innerIndent = " ";
const string propertyIndent = " ";
var propertyIndent = $"{indent} ";
var innerIndent = $"{propertyIndent} ";
var propertyAccessor = setter > getter ? setter : getter;
var getterAccessor = getter == propertyAccessor ? Accessibility.NotApplicable : getter;

View file

@ -21,9 +21,14 @@ namespace SerializationGenerator
{
public static partial class SourceGeneration
{
public static void GenerateAttribute(this StringBuilder source, string attrClassName, ImmutableArray<TypedConstant> args)
public static void GenerateAttribute(
this StringBuilder source,
string indent,
string attrClassName,
ImmutableArray<TypedConstant> args
)
{
source.Append($" [{attrClassName}");
source.Append($"{indent}[{attrClassName}");
var hasArgs = args.Length > 0;
if (hasArgs)