-
-
Save explorer14/f68a03cbb9cfee64ae4b887926e1c528 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal static string BuildDtoProperty( | |
this PropertyDeclarationSyntax pds, | |
Compilation compilation) | |
{ | |
var blah = compilation | |
.GetSemanticModel(pds.SyntaxTree) | |
.GetDeclaredSymbol(pds); | |
var propSym = (blah as IPropertySymbol); | |
if (propSym.IsOfTypeClass() || propSym.IsOfTypeStruct()) | |
{ | |
if (propSym.Type.NullableAnnotation == NullableAnnotation.Annotated) | |
return $"public {propSym.Type.Name}Dto? {property.Name} {{get; set;}}"; | |
return $"public {propSym.Type.Name()}Dto {property.Name} {{get; set;}}"; | |
} | |
else | |
return $"public {propSym.Type.Name()} {property.Name} {{get; set;}}"; | |
} | |
internal static bool IsOfTypeClass(this IPropertySymbol propSym) => | |
propSym.Type.IsReferenceType && | |
propSym.Type.TypeKind == TypeKind.Class && | |
propSym.Type.ToDisplayString().StartsWith( | |
propSym.ContainingNamespace.ToDisplayString()); | |
internal static bool IsOfTypeStruct(this IPropertySymbol propSym) => | |
propSym.Type.IsValueType && | |
propSym.Type.TypeKind == TypeKind.Struct && | |
propSym.Type.ToDisplayString().StartsWith( | |
propSym.ContainingNamespace.ToDisplayString()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment