public void Load() { if (File.Exists(fileName)) { var accountsToLoad = new List <T>(); var document = new XmlDocument(); document.Load(fileName); XmlNode accounts = document.DocumentElement; foreach (XmlNode account in accounts) { var AccountToLoad = Activator.CreateInstance(genericType, new[] { account.Attributes[constructorAttributeName].Value }); PropertyInfo[] properties = genericType.GetProperties(); foreach (var property in properties) { if (property.CanWrite) { if (property.PropertyType.Equals(typeof(int))) { int value = Convert.ToInt32(account.Attributes[property.Name].Value); property.SetValue(AccountToLoad, value); } else if (property.PropertyType.Equals(typeof(DateTime))) { DateTime value = Convert.ToDateTime(account.Attributes[property.Name].Value); property.SetValue(AccountToLoad, value); } else { property.SetValue(AccountToLoad, account.Attributes[property.Name].Value); } } } accountsToLoad.Add((T)AccountToLoad); } foreach (var item in accountsToLoad) { databaseProvider.AddItem(item); } } }