Tuesday, March 15, 2011


Playing again with the C# 4.0 DynamicObject class. The class DynamicTextFileManager provides a different way to read and write text files.
var path       = String.Format(@"{0}\DynamicTextFile", Environment.GetEnvironmentVariable("TEMP"));
dynamic dtfm   = new DynamicTextFileManager(path, "txt");

dtfm.MyNewFile = "Hello World"; // Write "Hello World" in the file %TEMP%\DynamicTextFile\MyNewFile.txt

string s       = dtfm.MyNewFile; // Read the content of the file %TEMP%\DynamicTextFile\MyNewFile.txt

No comments:

Post a Comment