public AgeController(IAge _age, INumerals _numerals, IFileHandler _fileHandler, CSVtoCreated _csvToCreated) { age = _age; numerals = _numerals; fileHandler = _fileHandler; csvToCreated = _csvToCreated; }
static void Main(string[] args) { Tree tree = new Tree(1978); Person person = new Person("Drika", "Garibalde", 1976); //cria array de referência a IAge IAge[] iAgeArray = new IAge[2]; //iAgeArray[0] se refere ao objeto Tree e iAgeArray[1] ao objeto person de maneira Polimorfica iAgeArray[0] = tree; iAgeArray[1] = person; //exibe informações da árvore string output = tree + ": " + tree.Name + "\nAge is " + tree.Age + "\n\n"; //exibe informações da pessoa output += person + ": " + person.Name + "\nAge is " + person.Age + "\n\n"; //exibe o nome e a idade de cada objeto IAge em IAgeArray foreach (IAge ageReference in iAgeArray) { output += ageReference.Name + " Age is " + ageReference.Age + "\n"; } Console.WriteLine(output); Console.WriteLine(); Console.WriteLine("Demostrating Polymorphism"); }
public InterfaceForm() { InitializeComponent(); Tree tree = new Tree(1978); Person person = new Person("Bob", "Jones", 1971); // create array of IAge references IAge[] iAgeArray = new IAge[2]; // iAgeArray[ 0 ] refers to Tree object polymorphically iAgeArray[0] = (IAge)tree; // iAgeArray[ 1 ] refers to Person object polymorphically iAgeArray[1] = person; // display tree information string output = tree + ": " + tree.Name + "\nAge is " + tree.Age + "\n\n"; // display person information output += person + ": " + person.Name + "\nAge is: " + person.Age + "\n\n"; // display name and age for each IAge object in iAgeArray foreach (IAge ageReference in iAgeArray) { output += ageReference.Name + ": Age is " + ageReference.Age + "\n"; } MessageBox.Show(output, "Demonstrating Polymorphism"); }
static void Main(string[] args) { try { int tAge; //Init 3 Football Players TransferMarket Schnorcher = new TransferMarket("Sepp", "Schnorcher", 34, "FC Haudanebm", 1000); TransferMarket Nixnutz = new TransferMarket("Hans", "Nixnutz", 28, "FC Haudanebm", 30); TransferMarket Schwein = new TransferMarket("Krankes", "Schwein", 12, "SC Stall", 909921); //Init 1 Football Player and 1 Student with the Interface IAge IAge Seppl = new TransferMarket("Seppl", "Dergroße", 50, "FC Haudanebm", 0815); IAge DerNeueSchueler = new Student("Muster", "Schueler", 11); //Array of Interface IAge var ArrIAge = new IAge[] { new TransferMarket("Sepp", "Schnorcher", 34, "FC Haudanebm", 1000), new TransferMarket("Zweiter", "Irgendwas", 24, "CF LangAtem", 4), new Student("Dritter", "Streber", 6), new Student("Vierter", "StreberVier", 7), new Student("Fuenfter", "Fauler", 89) }; //Write in the console Console.WriteLine($"Bester Spieler des Saison wurde Hr. {Schwein.Name.PSecondName}"); //Change the age of a player Console.WriteLine("Aendern des Alters von {0} von {1} auf:", Schnorcher.Name.PSecondName, Schnorcher.Age); tAge = Convert.ToInt32(Console.ReadLine()); Seppl.ChangeAge(tAge); Seppl.PrintAge(); //Print the age of the Student DerNeueSchueler.PrintAge(); Console.WriteLine("----------------------"); //Printing Loop for the Interface foreach (var i in ArrIAge) { i.PrintAge(); } } catch (Exception e) { Console.WriteLine("Error: " + e.Message); } }
private static void UpdateAge(IPatientInfo patientInfo, IAge age) { var previousAge = patientInfo.Age as Age; if (previousAge == null) { return; } previousAge.Year = age.Year; previousAge.Month = age.Month; previousAge.Week = age.Week; previousAge.Day = age.Day; previousAge.Unit = age.Unit; }
/// <summary> /// Преобразует IAge в масив ресуров /// </summary> /// <param name="languagePack">Объект эры</param> /// <returns>Массив русурсов</returns> public static ListResourse ToResource(IAge age) { ResourceItem resourse = null; ResourceItem resourseLevels = null; using (MemoryStream ms = new MemoryStream()) { using (var data = new BinaryWriter(ms, Encoding.UTF8, true)) { data.Write(age.Name); //Поле Name data.Write(age.TranslationIdentifier); //Идентификатор перевода // data.Write(age.Levels.Count); // age.Levels.ForEach((item) => data.Write(item.ID)); var isparent = age.Parent != null; data.Write(isparent); if (isparent) { data.Write(age.Parent.ID); } data.Write(age.Price.Gold); data.Write(age.Price.Brains); } resourse = CreateItem(age.ID, StringNameAgeData + age.Name, FileTypes.Age, ms); } using (MemoryStream ms = new MemoryStream()) { using (var data = new BinaryWriter(ms, Encoding.UTF8, true)) { data.Write(age.Levels.Count); age.Levels.ForEach((item) => data.Write(item.ID)); } resourseLevels = CreateItem(age.ID, StringNameLevelsAgeData + age.Name, FileTypes.LevelsAge, ms); } return(new ListResourse { resourse, resourseLevels }); }
public TicketType(IDatabase database, IAge age) { _database = database.Get(); _age = age; }
static void AgeThat(IAge ageable) { ageable.IncrementAge(); }
public AgeController(IAge ageService) { _ageService = ageService; }
public ClubController(IAge repo) { _repo = repo; }
public DIController1(IAge age) { _age = age; }
public static void MixAge(this IAge age) { Console.WriteLine("{0} years", age.Age); }
private void Display(IAge IA) { richTextBox1.AppendText(IA.ToString() + "\n"); }
public Person(IDatabase database, IAge age) { _database = database.Get(); _age = age; }
public Ticket(IDatabase database, ITicketType ticketType, IAge age) { _database = database.Get(); _ticketType = ticketType; _age = age; }
// You can make a function without creating an object static void AgeThatThing(IAge ageableThing) { ageableThing.IncrementAge(); }
/// <summary> /// Преобразование ресурса в объект типа эра /// </summary> /// <param name="obj">Преобразуемый ресурс</param> /// <param name="lr">список всех ресурсов</param> public static Tuple <IAge, ListResourse> ResourceToAge(ResourceItem obj, ListResourse lr) { obj.Data.Position = 0; IAge result = new Age(); // SerializableInventoryItem s = new SerializableInventoryItem(obj.Data); using (var data = new BinaryReader(obj.Data, Encoding.UTF8, true)) { result.Name = data.ReadString(); result.ID = obj.Identifier; result.TranslationIdentifier = data.ReadString(); { //Обработка уровней var levelsage = lr.FindAllByTypeAndIdentifier(FileTypes.LevelsAge, obj.Identifier); result.Levels = new DataList <ILevel>(); for (int i = 0; i < levelsage.Count; i++) { using (var data1 = new BinaryReader(levelsage[i].Data, Encoding.UTF8, true)) { int levelcount = data1.ReadInt32(); for (int j = 0; j < levelcount; j++) { var levelid = data1.ReadUInt64(); ILevel levelage = LevelCashe.Find((item) => item.ID == levelid); if (levelage != null) { result.Levels.Add(levelage); } else { result.Levels.Add(new Level { ID = levelid }); if (!levelagecashe.ContainsKey(levelid)) { levelagecashe[levelid] = new List <IAge>(); } levelagecashe[levelid].Add(result); } } } } } /*{ //Обработка уровней * int levelcount = data.ReadInt32(); * result.Levels = new DataList<ILevel>(); * for (int j = 0; j < levelcount; j++) * { * var levelid = data.ReadUInt64(); * ILevel levelage = LevelCashe.Find((item) => item.ID == levelid); * if (levelage != null) * { * result.Levels.Add(levelage); * } * else * { * result.Levels.Add(new Level { ID = levelid }); * if (!levelagecashe.ContainsKey(levelid)) * levelagecashe[levelid] = new List<IAge>(); * levelagecashe[levelid].Add(result); * } * } * * * * }*/ { //Обработка родителя эры 1 var Isparent = data.ReadBoolean(); if (Isparent) { var parentid = data.ReadUInt64(); IAge AgeAge = AgeCashe.Find((item) => item.ID == parentid); if (AgeAge != null) { result.Parent = AgeAge; } else { result.Parent = new Age { ID = parentid }; if (!ageagecashe.ContainsKey(parentid)) { ageagecashe[parentid] = new List <IAge>(); } ageagecashe[parentid].Add(result); } } } result.Price = new Money(data.ReadUInt32(), data.ReadUInt32()); { //Обработка родителя эры 2 if (ageagecashe.ContainsKey((ulong)result.ID)) { for (int j = 0; j < levellevelcashe[(ulong)result.ID].Count; j++) { ageagecashe[(ulong)result.ID][j].Parent = result; } } } } AgeCashe.Add(result); return(new Tuple <IAge, ListResourse>(result, new ListResourse { obj })); }
static void Main(string[] args) { try { //PushExampleWithSubject.Run(); string sJSON = ""; int tAge; //Init 3 Football Players TransferMarket Schnorcher = new TransferMarket("Sepp", "Schnorcher", 34, "FC Haudanebm", 1000); TransferMarket Nixnutz = new TransferMarket("Hans", "Nixnutz", 28, "FC Haudanebm", 30); TransferMarket Schwein = new TransferMarket("Krankes", "Schwein", 12, "SC Stall", 909921); //Init 1 Football Player and 1 Student with the Interface IAge IAge Seppl = new TransferMarket("Seppl", "Dergroße", 50, "FC Haudanebm", 0815); IAge DerNeueSchueler = new Student("Muster", "Schueler", 11); //Array of Interface IAge var ArrIAge = new IAge[]{ new TransferMarket("Sepp", "Schnorcher", 34, "FC Haudanebm", 1000), new TransferMarket("Zweiter", "Irgendwas", 24, "CF LangAtem", 4), new Student("Dritter", "Streber", 6), new Student("Vierter", "StreberVier", 7), new Student("Fuenfter", "Fauler", 89) }; //Array of Interface IAge var ArrJSON = new TransferMarket[]{ new TransferMarket("JSON1", "Schnorcher", 65, "FC Haudanebm", 3), new TransferMarket("JSON2", "Irgendwas", 76, "CF LangAtem", 4), }; //Write in the console Console.WriteLine($"Bester Spieler des Saison wurde Hr. {Schwein.Name.PSecondName}"); //Change the age of a player Console.WriteLine("Aendern des Alters von {0} von {1} auf:", Schnorcher.Name.PSecondName, Schnorcher.Age); tAge = Convert.ToInt32(Console.ReadLine()); Seppl.ChangeAge(tAge); Seppl.PrintAge(); //Print the age of the Student DerNeueSchueler.PrintAge(); Console.WriteLine("----------------------"); //Printing Loop for the Interface foreach (var i in ArrIAge) { i.PrintAge(); } sJSON = JsonConvert.SerializeObject(ArrJSON); Console.WriteLine("\n\nJSON OBJECT\n----------------\n{0}\n-------------------\n", sJSON); //Deserialize JSON OBJECT //TransferMarket[] x = JsonConvert.DeserializeObject<TransferMarket[]>(sJSON); //Console.WriteLine(x); //Task6 var ArrIAge_2 = new List<TransferMarket>(); ArrIAge_2.Add(new TransferMarket("Sepp", "Schnorcher", 34, "FC Haudanebm", 1000)); ArrIAge_2.Add(new TransferMarket("Sepp2", "Schnorcher", 34, "FC Haudanebm", 1000)); var producer = new Subject<List<TransferMarket>>(); producer.Subscribe(x => Console.WriteLine($"Empfangener Spieler: {x}")); for (var i = 0; i < 10; i++) { System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1)); producer.OnNext(ArrIAge_2); // push value i to subscribers } //Task Testing TasksExample.Run(); } catch (Exception e) { Console.WriteLine("Error: " + e.Message); } }
public AgeController(IAge age) { _age = age; }