Skip to content

Instantly share code, notes, and snippets.

@khalidabuhakmeh
Created December 31, 2020 17:02
Show Gist options
  • Save khalidabuhakmeh/4bc936bb4babd2a210e06af2a26874a1 to your computer and use it in GitHub Desktop.
Save khalidabuhakmeh/4bc936bb4babd2a210e06af2a26874a1 to your computer and use it in GitHub Desktop.
public static class PropertyNameDataCollector
{
public static async Task Scan(this Assembly assembly, string outputFilePath, bool includeHeader = true)
{
var properties = assembly
.GetTypes()
.SelectMany(x => x.GetProperties())
// only want BCL types
.Where(x => x.PropertyType.Namespace != null && x.PropertyType.Namespace.StartsWith("System"))
.Select(x => new
{
x.Name,
Type = x.PropertyType.IsGenericType
? x.PropertyType.GetGenericTypeDefinition().FullName
: x.PropertyType.FullName,
});
var csv = new StringBuilder();
if (includeHeader)
{
csv.AppendLine("Name,Type");
}
foreach (var property in properties) {
var row = $"{property.Name},{property.Type}";
Console.WriteLine($"- {row}");
csv.AppendLine(row);
}
await File.AppendAllTextAsync(outputFilePath,
csv.ToString(),
Encoding.UTF8
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment