我有一个类,我正在使用它来保存我的应用程序的各种数据。我从来没有真正实例化类,因为我希望可以从所有表单访问数据。我想序列化这个类,但它不会让我去除非我创建它的一个实例。有没有办法解决这个问题,或者更好的方法来完成我想要做的事情?序列化一个非实例化的类
这里是类:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;
using System.IO;
namespace Man
{
public class ListProduct
{
public string Name;
public int Quantity;
public decimal Cost;
public DateTime Date;
}
public class Product
{
public string Name;
public bool IsCompound;
public decimal BuyPrice;
public decimal SellPrice;
public List<ListProduct> SubItems = new List<ListProduct>();
}
public class ListEmployee
{
public string FirstName;
public string LastName;
public decimal Cost;
public decimal Hours;
public DateTime Date;
}
public class Employee
{
public string FirstName;
public string LastName;
public decimal Wage;
}
[Serializable()]
public class Items : ISerializable
{
public static List<Product> ProdList = new List<Product>();
public static List<Employee> EmpList = new List<Employee>();
public static List<ListProduct> BuyList = new List<ListProduct>();
public static List<ListProduct> SellList = new List<ListProduct>();
public static List<ListEmployee> EmpHours = new List<ListEmployee>();
}
}