mirror of
https://github.com/AlexMacocian/WpfExtended.git
synced 2026-07-15 14:59:30 +00:00
e6df17358b
Implement INotifyPropertyChanged Generator
80 lines
4.0 KiB
C#
80 lines
4.0 KiB
C#
using Microsoft.CodeAnalysis;
|
|
using Microsoft.CodeAnalysis.Text;
|
|
|
|
namespace System.Extensions
|
|
{
|
|
internal static class Diagnostics
|
|
{
|
|
public const string DependencyPropertyGenerator_NoAttributeFound = "DGD 0001";
|
|
public const string DependencyPropertyGenerator_ClassMustBeTopLevel = "DGD 1001";
|
|
public const string DependencyPropertyGenerator_ClassMustBePartial = "DGD 1002";
|
|
public const string DependencyPropertyGenerator_ClassMustBeInNamespace = "DGD 1003";
|
|
public const string DependencyPropertyGenerator_ClassMustImplementINotifyPropertyChanged = "DGD 1004";
|
|
|
|
public static Diagnostic MissingAttributeDiagnostic(string attributeName, string attributeNamespace) => Diagnostic.Create(
|
|
new DiagnosticDescriptor(
|
|
DependencyPropertyGenerator_NoAttributeFound,
|
|
$"{attributeNamespace}.{attributeName} not found",
|
|
"Could not find attribute with name {0} in namespace {1}.",
|
|
"WpfExtended.SourceGeneration",
|
|
DiagnosticSeverity.Error,
|
|
true,
|
|
$"This error occurs when the attribute generated by the {nameof(DependencyPropertyGenerator)} is not found",
|
|
null),
|
|
Location.None,
|
|
attributeName, attributeNamespace);
|
|
|
|
public static Diagnostic ClassNotTopLevelDiagnostic(string className, string containingSymbol, SyntaxTree syntaxTree, TextSpan textSpan) => Diagnostic.Create(
|
|
new DiagnosticDescriptor(
|
|
DependencyPropertyGenerator_ClassMustBeTopLevel,
|
|
$"{className} must be top level",
|
|
"Class {0} must be top level. It is currently declared under {1}.",
|
|
"WpfExtended.SourceGeneration",
|
|
DiagnosticSeverity.Error,
|
|
true,
|
|
null,
|
|
null),
|
|
Location.Create(syntaxTree, textSpan),
|
|
className, containingSymbol);
|
|
|
|
public static Diagnostic ClassNotPartial(string className) => Diagnostic.Create(
|
|
new DiagnosticDescriptor(
|
|
DependencyPropertyGenerator_ClassMustBePartial,
|
|
$"{className} is not partial",
|
|
"Class {0} must be marked as partial in order for the generator to work",
|
|
"WpfExtended.SourceGeneration",
|
|
DiagnosticSeverity.Error,
|
|
true,
|
|
null,
|
|
null),
|
|
Location.None,
|
|
className);
|
|
|
|
public static Diagnostic ClassNotInNamespace(string className) => Diagnostic.Create(
|
|
new DiagnosticDescriptor(
|
|
DependencyPropertyGenerator_ClassMustBeInNamespace,
|
|
$"{className} is not defined in a namespace",
|
|
"Class {0} must be defined inside a namespace for the generator to work",
|
|
"WpfExtended.SourceGeneration",
|
|
DiagnosticSeverity.Error,
|
|
true,
|
|
null,
|
|
null),
|
|
Location.None,
|
|
className);
|
|
|
|
public static Diagnostic ClassDoesNotImplementINotifyPropertyChanged(string className) => Diagnostic.Create(
|
|
new DiagnosticDescriptor(
|
|
DependencyPropertyGenerator_ClassMustImplementINotifyPropertyChanged,
|
|
$"{className} must implement INotifyPropertyChanged",
|
|
"Class {0} must implement INotifyPropertyChanged for the generator to work",
|
|
"WpfExtended.SourceGeneration",
|
|
DiagnosticSeverity.Error,
|
|
true,
|
|
null,
|
|
null),
|
|
Location.None,
|
|
className);
|
|
}
|
|
}
|