Thursday, July 22, 2010

Serializing Generic Types

There is no way currently of constraining a Generic type to ensure it is serializable at compile-time. However, there is a quick and easy way to check.


if (!typeof(T).IsSerializable)
{
throw new ArgumentException("type is not serializable");
}

No comments:

Post a Comment