コード例 #1
0
ファイル: Extensions.cs プロジェクト: IIITanbI/EpamProjects
 public static void AddCloneRange <T>(this ICloneCollection <T> source, IEnumerable <T> collection) where T : ICloneable
 {
     foreach (var value in collection)
     {
         source.Add((T)value.Clone());
     }
 }
コード例 #2
0
ファイル: Extensions.cs プロジェクト: IIITanbI/EpamProjects
 public static void AddRange <T>(this ICloneCollection <T> source, IEnumerable <T> collection)
 {
     foreach (var value in collection)
     {
         source.Add(value);
     }
 }
コード例 #3
0
ファイル: Extensions.cs プロジェクト: IIITanbI/EpamProjects
        public static ICloneCollection <IVegetable> CloneObjects <T>(this ICloneCollection <T> source) where T : ICloneable
        {
            var copy = (ICloneCollection <IVegetable>)source.Clone();
            var tt   = copy.ToArray();

            copy.InitializeClone(tt);

            return(copy);
        }
コード例 #4
0
ファイル: Extensions.cs プロジェクト: IIITanbI/EpamProjects
        public static IVegetable[] CloneObjectsToArray <T>(this ICloneCollection <T> source) where T : ICloneable
        {
            IVegetable[] copy = new IVegetable[source.Count];
            int          ind  = 0;

            foreach (var veg in source)
            {
                copy[ind] = (IVegetable)veg.Clone();
                ind++;
            }

            return(copy);
        }
コード例 #5
0
        static void Main(string[] args)
        {
            Calories cl = new Calories(2, 3, 4);
            Calories c2 = 2 * cl;

            var potato  = new  Potato(100);
            var cucmber = new Cucumber(100);
            var carrot  = new Carrot(200);

            var cust = new CustomVegetable("1", 2, new Calories());

            Console.WriteLine(cust);
            cust.Weight   = 3;
            cust.Calories = new Calories();
            cust.Name     = "13";
            Console.WriteLine(cust);

            Console.WriteLine(potato.Name + " " + potato.Calories + " " + potato.Weight);
            Console.WriteLine(cucmber.Name + " " + cucmber.Calories + " " + cucmber.Weight);
            Console.WriteLine(carrot.Name + " " + carrot.Calories + " " + carrot.Weight);
            List <IVegetable> lst = new List <IVegetable>();

            lst.Add(cucmber);


            Salad salad = new Salad(new CloneList <IVegetable>());

            salad.Add(potato);
            salad.Add(carrot);
            salad.Add(cucmber);
            Console.WriteLine("total calories = " + salad.TotalCalories);
            Console.WriteLine();
            Console.WriteLine();
            salad.PrintVegetables();
            var tt = salad.GetVegetables(0, 1000);

            Console.WriteLine();
            Console.WriteLine();
            salad.PrintVegetables();

            salad.Sort(VegetableComparasions.CompareByName);
            Console.WriteLine();
            Console.WriteLine();

            Console.WriteLine("BEFORE SRT");
            salad.PrintVegetables();

            salad.Sort(vegetable => vegetable.Calories, new CompareByCalories());

            Func <int, int> d = delegate(int i) { return(i * 3); };

            Console.WriteLine("AFTER SRT");
            salad.PrintVegetables();
            salad.Sort(VegetableComparasions.CompareByWeight);
            Console.WriteLine("BEFORE REMOVE");
            salad.PrintVegetables();
            salad.Remove(potato);

            Console.WriteLine("AFTER REMOVE");
            salad.PrintVegetables();

            Console.WriteLine("TESTTTT");
            CloneList <IVegetable> list = new CloneList <IVegetable>();

            List <int> li = new List <int>();

            list.Add(potato);
            list.Add(cucmber);
            list.Add(carrot);
            foreach (var v in list)
            {
                Console.WriteLine(v.Name + " " + v.Calories + " " + v.Weight);
            }
            Console.WriteLine("CLONE");

            ICloneCollection <IVegetable> list2 = list.CloneObjects();

            foreach (var v in list2)
            {
                Console.WriteLine(v.Name + " " + v.Calories + " " + v.Weight);
            }
            list[0].Weight = 0;
            list[1].Weight = 0;
            list[2].Weight = 0;

            Console.WriteLine("TESTTTT");

            foreach (var v in list)
            {
                Console.WriteLine(v.Name + " " + v.Calories + " " + v.Weight);
            }
            Console.WriteLine("CLONE");


            foreach (var v in list2)
            {
                Console.WriteLine(v.Name + " " + v.Calories + " " + v.Weight);
            }
        }
コード例 #6
0
ファイル: Extensions.cs プロジェクト: IIITanbI/EpamProjects
 public static void InitializeClone <T>(this ICloneCollection <T> source, IEnumerable <T> collection) where T : ICloneable
 {
     source.Clear();
     source.AddCloneRange(collection);
 }
コード例 #7
0
ファイル: Extensions.cs プロジェクト: IIITanbI/EpamProjects
 public static void Initialize <T>(this ICloneCollection <T> source, IEnumerable <T> collection)
 {
     source.Clear();
     source.AddRange(collection);
 }
コード例 #8
0
ファイル: Salad.cs プロジェクト: IIITanbI/EpamProjects
        //public Salad()
        //{
        //    this._ingridients = new CloneList<IVegetable>();
        //}

        public Salad(ICloneCollection <IVegetable> ingridients)
        {
            this._ingridients = ingridients;
        }