protected override void Read(StreamReader s, Person[] ps) { base.Read(s, ps); string linha; linha = s.ReadLine(); //categoria _categoria = (Categoria)Enum.Parse(typeof(Categoria), linha); }
public static Person[] ReadFilePersons(string fich) { var sr = new StreamReader(fich); string linha1; linha1 = sr.ReadLine(); int contador; contador = int.Parse(linha1); Person[] persons = new Person[contador]; string linha; int i; try { for (i = 0; i < contador; i++) { Person p; linha = sr.ReadLine(); Type tipo = Type.GetType(linha); // Type - é uma classe da API de Reflexão que devolve informação sobre // uma determinada classe //ConstructorInfo[] info_const1 = tipo.GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance); //p= info_const1[0].Invoke(new object[0]) as Person; p = Activator.CreateInstance(tipo, true) as Person; // var infocampos = tipo.GetFields(BindingFlags.NonPublic | BindingFlags.Instance); p.Read(sr, persons); /* if (infocampos[0].FieldType == typeof(string)) infocampos[0].SetValue(p, "xpto"); */ persons[i] = p; } } catch (Exception erro) { Console.WriteLine("erro {0} na leitura", erro); } sr.Close(); return persons; }
protected override void Read(StreamReader s, Person[] ps) { base.Read(s, ps); string linha; linha = s.ReadLine(); //nr aluno _nr_aluno = int.Parse(linha); linha = s.ReadLine(); //id_prof int id_prof = int.Parse(linha); foreach (Person p in ps) { if (p != null && p.Id == id_prof) { Teacher t = (Teacher)p; t.AddStudent(this); } } }
public static void SavePersons(Person[] array, string fich) { int contador = 0; foreach (Person p in array) { if (p != null) { contador++; } } var save = new StreamWriter(fich); // StreamWriter permite escrever num ficheiro fisico save.WriteLine(contador); foreach (Person p in array) { if (p != null) { save.WriteLine(p.GetType().FullName); p.SaveFile(save); } } save.Close(); }
protected virtual void Read(StreamReader s, Person [] ps) { string linha; linha = s.ReadLine(); //id _id = int.Parse(linha); Name = s.ReadLine(); //nome linha = s.ReadLine(); //dt nasc _birthdate = DateTime.Parse(linha); linha = s.ReadLine(); //vip _vip = bool.Parse(linha); }