static void Main(string[] args) { Prototype prototype = new Prototype(); prototype.Class = "Стрижка"; prototype.State = ""; var Haircut = prototype.Clone() as Prototype; Haircut.Class = "Середня стрижка"; Haircut.State = "Середня"; Console.WriteLine($"Cloned {Haircut.Class}"); var BobHaircut = Haircut.Clone(); BobHaircut.Class = "Боб"; BobHaircut.State = "Коротка"; Console.WriteLine($"Cloned {BobHaircut.Class}"); var CareHaircut = Haircut.Clone(); CareHaircut.Class = "Каре"; CareHaircut.State = "Не коротка"; Console.WriteLine($"Cloned {CareHaircut.Class}"); }
static void Main(string[] args) { Prototype prototype = new Prototype(); ClassForDoingPrototype prot = prototype.Clone() as ClassForDoingPrototype; Console.WriteLine(prot.ToString()); ClassForDoingPrototype prot2 = prototype.Clone() as ClassForDoingPrototype; prot2.StringParam = "opa2"; prot2.Param = 10; prot2.ClassParam = new InnerClass { InenrParam = 111 }; // if only change param value first prot changed to; Console.WriteLine(prot2.ToString()); Console.WriteLine(prot.ToString()); Console.ReadKey(); }
static void Main(string[] args) { Prototype a = new Prototype(); a.Name = "saeed"; a.Family = "rezaei"; a.Token = new Token { Roles = "admin", UserName = "******" }; Console.WriteLine(a.Name); Console.WriteLine(a.Family); Console.WriteLine(a.Token.Roles); Console.WriteLine(a.Token.UserName); Console.WriteLine("________________Class A_______________"); Prototype b = a.Clone() as Prototype; b.Name = "Ali "; b.Family = "Joudi "; b.Token.Roles = "guest"; b.Token.UserName = "******"; Console.WriteLine(b.Name); Console.WriteLine(b.Family); Console.WriteLine(b.Token.Roles); Console.WriteLine(b.Token.UserName); Console.WriteLine("________________Class B _______________"); Console.WriteLine(a.Name); Console.WriteLine(a.Family); Console.WriteLine(a.Token.Roles); Console.WriteLine(a.Token.UserName); Console.WriteLine("________________Class A_______________"); Prototype c = a.ObjectMemberwiseClone() as Prototype; c.Name = "Sina"; c.Family = "Rezaei"; c.Token.Roles = "guest,admin"; c.Token.UserName = "******"; Console.WriteLine(c.Name); Console.WriteLine(c.Family); Console.WriteLine(c.Token.Roles); Console.WriteLine(c.Token.UserName); Console.WriteLine("________________Class C_______________"); Console.WriteLine(a.Name); Console.WriteLine(a.Family); Console.WriteLine(a.Token.Roles); Console.WriteLine(a.Token.UserName); Console.WriteLine("________________Class A_______________"); }
static void Main(string[] args) { // ken is the prototype, except a few things, the properties won't change much in clones. // https://en.wikipedia.org/wiki/Prototype_pattern var ken = new Prototype { Name = "Ken", Age = 27 }; var barry = (Prototype) ken.Clone(); barry.Name = "Barry"; }
static void Main(string[] args) { // ken is the prototype, except a few things, the properties won't change much in clones. // https://en.wikipedia.org/wiki/Prototype_pattern var ken = new Prototype { Name = "Ken", Age = 27 }; var barry = (Prototype)ken.Clone(); barry.Name = "Barry"; }