First of all, it's my first post here so sorry if it's wrong or anything just warn me it will be better next time.
Second I speak french x).
Ok it's not a problem but I would like to have a better way to acces my data who are stored in a mother class. I know i'm not clear let me show you maybe you will understand.
Main.cs :
namespace Xahor
{
class Program
{
static void Main(string[] args)
{
TProduct test = new TProduct();
test.FillData(1, "Apple", "4857", "A tasty apple.", "Green", false, true);
test.PrintData();
}
}
}
TListNF.cs :
namespace Xahor
{
public class TListNF
{
public TListNF(int iProductID = 0, string sProductName = "", string sProductIDNum = "", string sProductDesc = "", string sColor = "", bool bMake = false, bool bCustom = false)
{
this.iProductID = iProductID;
this.sProductName = sProductName;
this.sProductIDNum = sProductIDNum;
this.sProductDesc = sProductDesc;
this.sColor = sColor;
this.bMake = bMake;
this.bCustom = bCustom;
}
public int iProductID { get; set; }
public string sProductName { get; set; }
public string sProductIDNum { get; set; }
public string sProductDesc { get; set; }
public string sColor { get; set; }
public bool bMake { get; set; }
public bool bCustom { get; set; }
protected List<TListNF> ItemList = new List<TListNF>();
}
}
TProduct.cs :
namespace Xahor
{
class TProduct : TListNF
{
public void FillData(int iProductID, string sProductName, string sProductIDNum, string sProductDesc, string sColor, bool bMake, bool bCustom)
{
ItemList.Add(new TListNF(iProductID, sProductName, sProductIDNum, sProductDesc, sColor, bMake, bCustom));
}
public void PrintData()
{
foreach (TListNF t in ItemList)
{
//Here where * is each of the accessor
Console.WriteLine(t.*.ToString());
Console.WriteLine(t.*.ToString());
...
}
}
}
}
So, basicly what I don't know how to do is to get an easier acces to the getter what it would normally be a foreach so each time we enter the loop the var t get the value
Resolved
@Nair
Thank you I've figured out with the post
How to loop through all the properties of a class?
But your answer help by the way if anyone else need somethings like this I,ve used
foreach (PropertyInfo p in list.GetType().GetProperties())
{
Console.WriteLine(p.Name + " : " + p.GetValue(list));
}
//Where list is the List<ClassName_With_Accesor> list;