Defining Items Based on Text File (C#) -


i'm setting list of items looks this.

list<bankinfo> all_branches = new list<bankinfo>(); equipment.set_slot = "mail"; all_branches.add(new bankinfo {     name = "west bank",     city = "san francisco",     owner = new person { name = "jeff bridges", age = 55 } }); all_branches.add(new bankinfo {     name = "east bank",     city = "concord",     owner = new person { name = "upton sinclair", age = 102 } }); 

writing literally hundreds of these quite cumbersome , i'd prefer if got write this

-- name: west bank city: san francisco owner: jeff bridges, 55 -- name: east bank city: concord owner: upton sinclair, 102 

is there way such thing?

at least there way (in c#) make symbol $item becomes all_branches.add(new bankinfo { $item (like macros in c++)?

i understand mean function taking care of property assignation:

private list<bankinfo> addtobankinfo(string name, string city, string owner_name, int owner_age, list<bankinfo> all_branches) {      return all_branches.add(new bankinfo { name = name, city = city, owner = new person { name = owner_name, age = owner_age } }); } 

which can call:

list<bankinfo> all_branches = new list<bankinfo>(); equipment.set_slot = "mail"; try {     using (system.io.streamreader sr = new system.io.streamreader("input_file.txt"))     {         string line;         while ((line = sr.readline()) != null)         {             if(line != null && line.trim().length > 0 && line.contains(","))             {                 string[] temp = line.split(',');                 if(temp.length >= 4)                 {                     all_branches = addtobankinfo(temp[0], temp[1], temp[2], convert.toint32(temp[3]), all_branches);                 }             }         }     } } catch { } 

in example above assuming inputs in txt file, separated commas. if provide more information exact input format, can update code accordingly.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -