public void SetFields(ClassDeclarationSyntax classNode, AbstractionModel model) { try { var parser = new CodeParser() { AccessLevel = "public" }; var fields = parser .FilterByAccessLevel(parser.GetFields(classNode), accessLevel: "public") .Select(p => (p as FieldDeclarationSyntax).Declaration); foreach (var field in fields) { var fieldName = field.Variables.First().Identifier.ToString(); var fieldValue = field.Variables.First().Initializer?.Value.ToString() ?? "default"; var type = field.Type.ToString(); model.AddField(fieldName, fieldValue, type); if (field.HasLeadingTrivia) { var parsedDocumentation = GetDocumentation(field); model.AddDocumentation(fieldName, parsedDocumentation); } } } catch (Exception e) { Logging.Log($"Failed to set fields in AbstractionModelManager.\nError: {e}"); } }
public void SetProperties(ClassDeclarationSyntax classNode, AbstractionModel model) { try { var parser = new CodeParser() { AccessLevel = "public" }; var properties = parser .FilterByAccessLevel(parser.GetProperties(classNode), accessLevel: "public") .Select(p => (p as PropertyDeclarationSyntax)); foreach (var property in properties) { if (property == null) { continue; } var propertyName = property.Identifier.ValueText; model.AddProperty(propertyName, property.Initializer?.Value.ToString() ?? "default", type: property.Type.ToString()); if (property.HasLeadingTrivia) { var parsedDocumentation = GetDocumentation(property); model.AddDocumentation(propertyName, parsedDocumentation); } } } catch (Exception e) { Logging.Log($"Failed to set properties in AbstractionModelManager.\nError: {e}"); } }