diff --git a/src/JsonMergePatch.SourceGenerator/GeneratedTypeFilter.cs b/src/JsonMergePatch.SourceGenerator/GeneratedTypeFilter.cs index 3ede7c7..c37e5bd 100644 --- a/src/JsonMergePatch.SourceGenerator/GeneratedTypeFilter.cs +++ b/src/JsonMergePatch.SourceGenerator/GeneratedTypeFilter.cs @@ -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().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; } diff --git a/src/JsonMergePatch.SourceGenerator/TypeBuilder.cs b/src/JsonMergePatch.SourceGenerator/TypeBuilder.cs index 487b03a..c6c8ee1 100644 --- a/src/JsonMergePatch.SourceGenerator/TypeBuilder.cs +++ b/src/JsonMergePatch.SourceGenerator/TypeBuilder.cs @@ -150,7 +150,9 @@ private string ConvertToNullableIfRequired(PropertyInformation propertyInfo, ITy private void BuildAttributes(BuilderState state, IEnumerable 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}]"); @@ -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();