Skip to content

Instantly share code, notes, and snippets.

@explorer14
Last active July 18, 2021 18:41
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 explorer14/fadf91e64acc38f82920687d92efc178 to your computer and use it in GitHub Desktop.
Save explorer14/fadf91e64acc38f82920687d92efc178 to your computer and use it in GitHub Desktop.
foreach (var pds in allProperties)
{
var symbol = context.Compilation
.GetSemanticModel(pds.SyntaxTree)
.GetDeclaredSymbol(pds);
var property = (symbol as IPropertySymbol);
if (property.IsOfTypeClass() || property.IsOfTypeStruct())
{
if (property.Type.NullableAnnotation == NullableAnnotation.Annotated)
codeBuilder.AppendLine($"\t\t\t\t\t{property.Name} = entity.{property.Name}?.ToDto() ?? null,");
else
codeBuilder.AppendLine($"\t\t\t\t\t{property.Name} = entity.{property.Name}.ToDto(),");
}
else
codeBuilder.AppendLine($"\t\t\t\t\t{property.Name} = entity.{property.Name},");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment