mirror of
https://github.com/AnnulusGames/Alchemy.git
synced 2025-01-22 08:18:51 -05:00
Add: ShouldBeNonSerialized DiagnosticDescriptor
This commit is contained in:
parent
0a74551727
commit
fbde143664
@ -51,14 +51,27 @@ namespace Alchemy.SourceGenerator
|
|||||||
foreach (var variable in field.Declaration.Variables)
|
foreach (var variable in field.Declaration.Variables)
|
||||||
{
|
{
|
||||||
var fieldSymbol = model.GetDeclaredSymbol(variable) as IFieldSymbol;
|
var fieldSymbol = model.GetDeclaredSymbol(variable) as IFieldSymbol;
|
||||||
var attribute = fieldSymbol.GetAttributes()
|
var alchemySerializeAttribute = fieldSymbol.GetAttributes()
|
||||||
.FirstOrDefault(x =>
|
.FirstOrDefault(x =>
|
||||||
x.AttributeClass.Name is "AlchemySerializeField"
|
x.AttributeClass.Name is "AlchemySerializeField"
|
||||||
or "AlchemySerializeFieldAttribute"
|
or "AlchemySerializeFieldAttribute"
|
||||||
or "Alchemy.Serialization.AlchemySerializeField"
|
or "Alchemy.Serialization.AlchemySerializeField"
|
||||||
or "Alchemy.Serialization.AlchemySerializeFieldAttribute");
|
or "Alchemy.Serialization.AlchemySerializeFieldAttribute");
|
||||||
if (attribute != null)
|
|
||||||
|
var nonSerializedAttribute = fieldSymbol.GetAttributes()
|
||||||
|
.FirstOrDefault(x =>
|
||||||
|
x.AttributeClass.Name is "NonSerialized"
|
||||||
|
or "NonSerializedAttribute"
|
||||||
|
or "System.NonSerialized"
|
||||||
|
or "System.NonSerializedAttribute");
|
||||||
|
|
||||||
|
if (alchemySerializeAttribute != null)
|
||||||
{
|
{
|
||||||
|
if (nonSerializedAttribute == null)
|
||||||
|
{
|
||||||
|
context.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.ShouldBeNonSerialized, variable.Identifier.GetLocation(), fieldSymbol.Name));
|
||||||
|
}
|
||||||
|
|
||||||
fieldSymbols.Add(fieldSymbol);
|
fieldSymbols.Add(fieldSymbol);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,16 @@ namespace Alchemy.SourceGenerator
|
|||||||
messageFormat: "The AlchemySerialize class '{0}' must be not nested type.",
|
messageFormat: "The AlchemySerialize class '{0}' must be not nested type.",
|
||||||
category: Category,
|
category: Category,
|
||||||
defaultSeverity: DiagnosticSeverity.Error,
|
defaultSeverity: DiagnosticSeverity.Error,
|
||||||
isEnabledByDefault: true);
|
isEnabledByDefault: true
|
||||||
|
);
|
||||||
|
|
||||||
|
public static readonly DiagnosticDescriptor ShouldBeNonSerialized = new(
|
||||||
|
id: "ALCHEMY003",
|
||||||
|
title: "AlchemySerializeField should be NonSerialized to avoid duplicate serialization.",
|
||||||
|
messageFormat: "AlchemySerializeField '{0}' should be NonSerialized to avoid duplicate serialization.",
|
||||||
|
category: Category,
|
||||||
|
defaultSeverity: DiagnosticSeverity.Warning,
|
||||||
|
isEnabledByDefault: true
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user