Skip to content

Commit

Permalink
Handling enums and nullable attributes that do not exist in netcoreapp31
Browse files Browse the repository at this point in the history
  • Loading branch information
ladeak committed Mar 1, 2021
1 parent fea4149 commit 4536914
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/JsonMergePatch.SourceGenerator/GeneratedTypeFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ public static bool IsGeneratableType(ITypeSymbol typeInfo)
bool generic = false;
if (typeInfo is INamedTypeSymbol namedTypeInfo)
generic = namedTypeInfo.IsGenericType;
return typeInfo.SpecialType == SpecialType.None && !typeInfo.IsAnonymousType && !typeInfo.IsAbstract && !generic;
//&& typeInfo.GetMembers().OfType<IMethodSymbol>().Where(x => x.MethodKind == MethodKind.Constructor).AnyOrNull(x => x.Parameters.IsEmpty);
return typeInfo.SpecialType == SpecialType.None && !typeInfo.IsAnonymousType && !typeInfo.IsAbstract && !generic && !typeInfo.IsStatic && typeInfo.TypeKind != TypeKind.Enum;
}


Expand Down
5 changes: 3 additions & 2 deletions src/JsonMergePatch.SourceGenerator/TypeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ private string ConvertToNullableIfRequired(PropertyInformation propertyInfo, ITy
private void BuildAttributes(BuilderState state, IEnumerable<AttributeData> attributes)
{
foreach (var attribute in attributes)
BuildAttribute(state, attribute);
if (attribute.AttributeClass?.ToDisplayString() != "System.Runtime.CompilerServices.NullableContextAttribute" &&
attribute.AttributeClass?.ToDisplayString() != "System.Runtime.CompilerServices.NullableAttribute")
BuildAttribute(state, attribute);
}

private void BuildAttribute(BuilderState state, AttributeData attribute) => state.AppendLine($"[{attribute}]");
Expand Down Expand Up @@ -209,7 +211,6 @@ private void SetInitOnlyProperties(BuilderState state)
{
if (!state.TypeInfo.Properties.Any(x => IsInitOnlyProperty(x.Property)))
return;
//state.AppendLine($"var tmp = new {state.TypeInfo.SourceTypeName}()");
CallConstructIfEmpty(state, "var tmp =", leaveOpen: true);
state.AppendLine("{");
var initializerState = state.IncrementIdentation();
Expand Down

0 comments on commit 4536914

Please sign in to comment.