mirror of
				https://github.com/disposable-email-domains/disposable-email-domains.git
				synced 2025-05-29 01:49:27 +08:00 
			
		
		
		
	shorten c# example code
This commit is contained in:
		
							parent
							
								
									0e27a144cd
								
							
						
					
					
						commit
						862ee297ae
					
				
							
								
								
									
										30
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								README.md
									
									
									
									
									
								
							@ -89,30 +89,14 @@ rl.on('close', () => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
**C#**
 | 
					**C#**
 | 
				
			||||||
```C#
 | 
					```C#
 | 
				
			||||||
private static readonly Lazy<HashSet<string>> _emailBlackList =
 | 
					private static readonly Lazy<HashSet<string>> _emailBlackList = new Lazy<HashSet<string>>(() =>
 | 
				
			||||||
  new Lazy<HashSet<string>>(
 | 
					{ 
 | 
				
			||||||
    () =>
 | 
					  var lines = File.ReadLines("disposable_email_blacklist.conf")
 | 
				
			||||||
    {
 | 
					    .Where(line => !string.IsNullOrWhiteSpace(line) && !line.TrimStart().StartsWith("//"));
 | 
				
			||||||
      var result = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
 | 
					  return new HashSet<string>(lines, StringComparer.OrdinalIgnoreCase);
 | 
				
			||||||
      using (var reader = new StreamReader("disposable_email_blacklist.conf"))
 | 
					});
 | 
				
			||||||
      {
 | 
					 | 
				
			||||||
        string line;
 | 
					 | 
				
			||||||
        while ((line = reader.ReadLine()) != null)
 | 
					 | 
				
			||||||
          if (!string.IsNullOrWhiteSpace(line) && !line.TrimStart().StartsWith("//"))
 | 
					 | 
				
			||||||
            result.Add(line);
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
      return result;
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
private static bool IsBlacklisted(string domain)
 | 
					private static bool IsBlacklisted(string domain) => _emailBlackList.Value.Contains(domain);
 | 
				
			||||||
{
 | 
					 | 
				
			||||||
  var parts = domain.Split('.');
 | 
					 | 
				
			||||||
  var len = parts.Length;
 | 
					 | 
				
			||||||
  return
 | 
					 | 
				
			||||||
    len == 1 && _emailBlackList.Value.Contains(domain)
 | 
					 | 
				
			||||||
    || _emailBlackList.Value.Contains($"{parts[len - 2]}.{parts[len - 1]}")
 | 
					 | 
				
			||||||
    || len > 2 && _emailBlackList.Value.Contains($"{parts[len - 3]}.{parts[len - 2]}.{parts[len - 1]}");
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
...
 | 
					...
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user