mercredi 30 décembre 2015

How to make a routine deal with observable collection of instances of a generic class

I want to make a logger (in a library) that iterates through every field of whatever class and sets all values in a comma separated values line. It's input value is a observable collection of whatever class. To make it generic I made it

ObservableCollection newObcObject.

public static bool WriteLog_Reflection(string fileName, long maxLogSizeMB, ObservableCollection<object>newObcObject, out string strError)
{
  try
  {
    strError = string.Empty;
    string lines = string.Empty;
    foreach (var item in newObcObject)
    {
      foreach (var prop in item.GetType().GetProperties())
      {
        //string str = prop.Name + " = " + prop.GetValue(item, null).ToString();
        lines += prop.GetValue(item, null).ToString() + "; ";
      }
    }

    return true;
  }
  catch (Exception exc)
  {
    strError = exc.ToString();
    return false;
  }
}

and this works..

The problem now is how to convert a specific observable collection to an object observable collection.

E.g. ObservableCollection ------> ObservableCollection

This is my solution but I'm open to whatever other solutions. thanx





Aucun commentaire:

Enregistrer un commentaire