-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
1 parent
c3f2f28
commit 055d18e
Showing
8 changed files
with
100 additions
and
9 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
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
59 changes: 59 additions & 0 deletions
59
src/jQueryDatatableServerSideNetCore/Services/HtmlService/HtmlService.cs
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.ComponentModel.DataAnnotations; | ||
using System.Reflection; | ||
using System.Text; | ||
|
||
namespace jQueryDatatableServerSideNetCore.Services.HtmlService | ||
{ | ||
public class HtmlService : IHtmlService | ||
{ | ||
public byte[] Write<T>(IList<T> registers) | ||
{ | ||
StringBuilder sb = new StringBuilder(); | ||
|
||
sb.Append("<table>\n"); | ||
sb.Append("\t<thead>\n"); | ||
sb.Append("\t\t<tr>\n"); | ||
|
||
Type type = typeof(T); | ||
PropertyInfo[] properties = type.GetProperties(); | ||
|
||
for (var i = 0; i < properties.Length; i++) | ||
{ | ||
string value = properties[i].Name; | ||
|
||
var attribute = properties[i].GetCustomAttribute(typeof(DisplayAttribute)); | ||
if (attribute != null) | ||
{ | ||
value = (attribute as DisplayAttribute).Name; | ||
} | ||
|
||
sb.Append("\t\t\t<td>"); | ||
sb.Append(value); | ||
sb.Append("</td>\n"); | ||
} | ||
|
||
sb.Append("\t\t</tr>\n"); | ||
sb.Append("\t</thead>\n"); | ||
sb.Append("\t<tbody>\n"); | ||
|
||
foreach (var register in registers) | ||
{ | ||
sb.Append("\t\t<tr>\n"); | ||
|
||
for (var i = 0; i < properties.Length; i++) | ||
{ | ||
sb.Append("\t\t\t<td>"); | ||
sb.Append(properties[i].GetValue(register, null)); | ||
sb.Append("</td>\n"); | ||
} | ||
|
||
sb.Append("\t\t</tr>\n"); | ||
} | ||
|
||
sb.Append("\t</tbody>\n"); | ||
sb.Append("</table>"); | ||
|
||
return Encoding.ASCII.GetBytes(sb.ToString()); | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/jQueryDatatableServerSideNetCore/Services/HtmlService/IHtmlService.cs
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,7 @@ | ||
namespace jQueryDatatableServerSideNetCore.Services.HtmlService | ||
{ | ||
public interface IHtmlService | ||
{ | ||
byte[] Write<T>(IList<T> registers); | ||
} | ||
} |
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