In below code i can't return null, that will result in error ( T can be non-Nullable value type)
public static T Deserialize<T>(byte[] serializedData)
{
//if (serializedData == null) { return null; } //// error
MemoryStream memoryStream = new MemoryStream();
BinaryFormatter binaryFormatter = new BinaryFormatter();
memoryStream.Write(serializedData, 0, serializedData.Length);
memoryStream.Seek(0, SeekOrigin.Begin);
return (T)binaryFormatter.Deserialize(memoryStream);
}
By adding default(T) will fix null issue
if (serializedData == null) { return default(T); }
but that will return default value (false for bool etc..) .. is any other way we can do this ?