Created
December 31, 2020 17:02
-
-
Save khalidabuhakmeh/4bc936bb4babd2a210e06af2a26874a1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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