Skip to content

Instantly share code, notes, and snippets.

@hatelove
Last active November 22, 2018 15:09
Show Gist options
  • Save hatelove/700e7283aa6923a6ea0e8279ff03bdb0 to your computer and use it in GitHub Desktop.
Save hatelove/700e7283aa6923a6ea0e8279ff03bdb0 to your computer and use it in GitHub Desktop.
.net framework 2.0 version sample code
using System.Collections.Generic;
namespace UnitTestProject4
{
public class Medical
{
public Medical(int year, string content)
{
Year = year;
Content = content;
}
public int Year { get; }
public string Content { get; }
private delegate bool Validate(string content);
public bool IsValid()
{
//var validators = new Dictionary<int, Func<string, bool>>
Dictionary<int, Validate> validators = new Dictionary<int, Validate>
{
{106, this.Validator106 },
{107, this.Validator107 },
};
return validators.ContainsKey(Year) && validators[Year](Content);
}
private bool Validator107(string content)
{
return GetWhiteList().Contains(content);
}
private static List<string> GetWhiteList()
{
List<string> numberList = new List<string>();
for (int i = 1; i <= 14; i++)
{
numberList.Add(i.ToString());
}
numberList.Remove("2");
numberList.Remove("12");
numberList.AddRange(new[] { "2a", "2b", "99" });
return numberList;
//var numberList = Enumerable.Range(1, 14).Except(new[] { 2, 12 });
//return numberList.Select(x => x.ToString()).Concat(new[] { "2a", "2b", "99" });
}
private bool Validator106(string content)
{
int value;
if (int.TryParse(content, out value))
{
return (value >= 1 && value <= 11) || value == 99;
}
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment