I need to be able to store a type value into a file, and read it back into a type value later. What's the best way to go about this?
Type type = typeof(SomeClass);
binaryWriter.Write?(type);
I'd store the assembly-qualified name, assuming the assembly will still be present later:
binaryWriter.Write(type.AssemblyQualifiedName);
...
string typeName = binaryReader.ReadString();
Type type = Type.GetType(typeName);
If you already know what assembly the type will be in, you could just use the full name (i.e. namespace and type name, but not assembly). Then use Assembly.GetType(string)
later.
See more on this question at Stackoverflow