コード例 #1
0
        public static OptionBuilder ByBirthDate(this OptionBuilder builder, DateTime birthDate)
        {
            if (builder == null)
            {
                builder = new OptionBuilder();
            }

            builder.IsByBirthDate = true;
            builder.BirthDate     = birthDate;

            return(builder);
        }
コード例 #2
0
        public static OptionBuilder ByName(this OptionBuilder builder, string name)
        {
            if (builder == null)
            {
                builder = new OptionBuilder();
            }

            builder.IsByName = true;
            builder.Name     = name;

            return(builder);
        }
コード例 #3
0
        public static OptionBuilder ByAge(this OptionBuilder builder, int age)
        {
            if (builder == null)
            {
                builder = new OptionBuilder();
            }

            builder.IsByAge = true;
            builder.Age     = age;

            return(builder);
        }
コード例 #4
0
        public static List <Person> GetPerson(OptionBuilder builder)
        {
            var lst = new List <Person>();

            bool isNullBuilder = !builder.IsByName && !builder.IsByBirthDate && !builder.IsByAge;

            if (isNullBuilder)
            {
                return(new List <Person>());
            }

            if (builder.IsByAge)
            {
                lst = List.FindAll(x => x.Age == builder.Age);
            }

            if (builder.IsByName)
            {
                if (lst.IsNullOrEmpty())
                {
                    lst = List.FindAll(x => x.Name == builder.Name);
                }
                else
                {
                    lst = lst.FindAll(x => x.Name == builder.Name);
                }
            }

            if (builder.IsByBirthDate)
            {
                if (lst.IsNullOrEmpty())
                {
                    lst = List.FindAll(x => x.BirthDate == builder.BirthDate);
                }
                else
                {
                    lst = lst.FindAll(x => x.BirthDate == builder.BirthDate);
                }
            }

            return(lst);
        }
コード例 #5
0
        public static void Run()
        {
            List.Add(new Person {
                Name = "A", Age = 22, BirthDate = new DateTime(2017, 11, 22)
            });
            List.Add(new Person {
                Name = "B", Age = 11, BirthDate = new DateTime(1993, 11, 22)
            });
            List.Add(new Person {
                Name = "C", Age = 12, BirthDate = new DateTime(2000, 11, 22)
            });
            List.Add(new Person {
                Name = "D", Age = 62, BirthDate = new DateTime(2014, 11, 22)
            });
            List.Add(new Person {
                Name = "E", Age = 73, BirthDate = new DateTime(1990, 11, 22)
            });

            var builder = OptionBuilder.Create();

            var persons = GetPerson(builder.ByAge(22).ByName("A"));
        }