I want to use a generic WriteList(List value) function to write a List using the BinaryWriter. Here is the code I am using:
public void WriteList<T>(List<T> value)
{
for (int i = 0; i < value.Count; i++)
{
_writer.Write(value[i]);
}
}
The error I am receiving is:
Error 1 The best overloaded method match for 'System.IO.BinaryWriter.Write(bool)' has some invalid arguments
Error 2 Argument 1: cannot convert from 'T' to 'bool'
The BinaryFormatter is absolutely not an option.
If you check out the docs for BinaryWriter you'll see it doesnt accept an argument of object (Writes primitive types), and the compiler is trying its best at an overload, and failing, since you can't cast your T to bool, or anything else that BinarwWriter would like.
You're going to have to convert your object into something the BinaryWriter will work with.