-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
190 additions
and
19 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="Writer\" /> | ||
<Folder Include="Reader\" /> | ||
</ItemGroup> | ||
</Project> |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System.Diagnostics.Metrics; | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Reflection.Emit; | ||
using System.Text; | ||
|
||
namespace nyingi.Kafa.Reflection | ||
{ | ||
internal partial class KafaReflection | ||
{ | ||
public async Task<TextWriter> GetProperties<T>(List<T> entities, TextWriter textWriter) | ||
{ | ||
|
||
bool readHeader = false; | ||
int propertyCount = 0; | ||
int count = 0; | ||
PropertyInfo[] propertyInfos = default!; | ||
foreach (var entity in entities) | ||
{ | ||
propertyInfos = entity.GetType().GetProperties(); | ||
|
||
if(TypeInfo.KafaOptions.HasHeader && !readHeader) | ||
{ | ||
int countHeader = 0; | ||
foreach (var propertyInfo in propertyInfos) | ||
{ | ||
await textWriter.WriteAsync(propertyInfo.Name); | ||
|
||
if (countHeader < propertyInfos.Length - 1) | ||
{ | ||
await textWriter.WriteAsync((char)TypeInfo.KafaOptions.FileType); | ||
|
||
} | ||
countHeader++; | ||
} | ||
|
||
await textWriter.WriteLineAsync(); | ||
readHeader= true; | ||
} | ||
|
||
propertyCount = propertyInfos.Length; | ||
foreach (var propertyInfo in propertyInfos) | ||
{ | ||
await textWriter.WriteAsync($"{propertyInfo.GetValue(entity)}"); | ||
|
||
if (count < propertyCount - 1) | ||
{ | ||
await textWriter.WriteAsync((char)TypeInfo.KafaOptions.FileType); | ||
} | ||
count++; | ||
} | ||
await textWriter.WriteLineAsync(); | ||
count = 0; | ||
} | ||
|
||
return textWriter; | ||
} | ||
} | ||
} |
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
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