我专门针对ET.Object写了一个BsonExtension,然后调整了Object:
public static class BsonExtensions
{
public static T FromBson<T>(this byte[] bytes)
{
return MongoHelper.Deserialize<T>(bytes);
}
public static byte[] ToBson<T>(this T obj)
where T : Object
{
return MongoHelper.Serialize(obj);
}
public static string ToJson<T>(this T obj)
where T : Object
{
return MongoHelper.ToJson(obj);
}
}
public abstract class Object
{
public override string ToString()
{
return MongoHelper.ToJson(this);
}
}