-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
2 changed files
with
30 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,57 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Nager.PublicSuffix.Models; | ||
|
||
namespace Nager.PublicSuffix.Extensions | ||
{ | ||
/// <summary> | ||
/// TldRule Extensions | ||
/// </summary> | ||
public static class TldRuleExtensions | ||
{ | ||
/// <summary> | ||
/// Converts the collection of <see cref="TldRule"/> <paramref name="rules"/> to text. | ||
/// </summary> | ||
/// <param name="rules">The collection of <see cref="TldRule"/> rules</param> | ||
/// <returns></returns> | ||
public static string UnParseRules(this IEnumerable<TldRule> rules) | ||
public static string UnparseRules(this IEnumerable<TldRule> rules) | ||
{ | ||
var rulesData = ""; | ||
foreach (var division in rules.GroupBy(x=>x.Division)) | ||
var rulesData = new StringBuilder(); | ||
foreach (var division in rules.GroupBy(rule => rule.Division)) | ||
{ | ||
switch (division.Key) | ||
{ | ||
case TldRuleDivision.ICANN: | ||
rulesData += "\n// ===BEGIN ICANN DOMAINS===\n"; | ||
rulesData.Append("\n// ===BEGIN ICANN DOMAINS===\n"); | ||
break; | ||
case TldRuleDivision.Private: | ||
rulesData += "\n// ===BEGIN PRIVATE DOMAINS===\n"; | ||
rulesData.Append("\n// ===BEGIN PRIVATE DOMAINS===\n"); | ||
break; | ||
} | ||
|
||
foreach (var rule in division) | ||
{ | ||
rulesData += "\n"; | ||
rulesData.Append("\n"); | ||
|
||
if (rule.Type == TldRuleType.WildcardException) | ||
{ | ||
rulesData += "!"; | ||
rulesData.Append("!"); | ||
} | ||
rulesData += rule.Name; | ||
rulesData.Append(rule.Name); | ||
} | ||
|
||
switch (division.Key) | ||
{ | ||
case TldRuleDivision.ICANN: | ||
rulesData += "\n// ===END ICANN DOMAINS===\n"; | ||
rulesData.Append("\n// ===END ICANN DOMAINS===\n"); | ||
break; | ||
case TldRuleDivision.Private: | ||
rulesData += "\n// ===END PRIVATE DOMAINS===\n"; | ||
rulesData.Append("\n// ===END PRIVATE DOMAINS===\n"); | ||
break; | ||
} | ||
} | ||
|
||
return rulesData; | ||
return rulesData.ToString(); | ||
} | ||
}} |