Skip to content

Instantly share code, notes, and snippets.

@MikeCodesDotNET
Created May 11, 2020 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MikeCodesDotNET/3492a844090f8b7d94d25f4a42a75f6e to your computer and use it in GitHub Desktop.
Save MikeCodesDotNET/3492a844090f8b7d94d25f4a42a75f6e to your computer and use it in GitHub Desktop.
private void ValidatePropertyDeclarationSyntax(PropertyDeclarationSyntax declarationSyntax)
{
IPropertySymbol symbol = semanticModel.GetDeclaredSymbol(declarationSyntax) as IPropertySymbol;
if (symbol.IsStatic)
{
errors.Add((ValidationErrorType.Illegal_Feature, "Static properties are not allowed"));
return;
}
if (symbol.IsOverride)
{
errors.Add((ValidationErrorType.Illegal_Feature, "Overriding properties is not allowed"));
return;
}
if (symbol.IsAbstract)
{
errors.Add((ValidationErrorType.Illegal_Feature, "Abstract properties are not allowed"));
return;
}
if (symbol.IsVirtual)
{
errors.Add((ValidationErrorType.Illegal_Feature, "Virtual properties are not allowed"));
return;
}
string assemblyName = symbol.Type.ContainingAssembly.Name;
if (IsIllegalAssemblyName(assemblyName))
{
errors.Add((ValidationErrorType.Illegal_Assembly, $"Types from assembly {assemblyName} are not allowed"));
return;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment