需要反射时使用dynamic

//使用dynamic的写法
dynamic fileExplorerData = _currentFolder.FileExplorerData;
var data = fileExplorerData.InsertFromPath(newPath);

//使用反射的写法
MethodInfo InsertMethod = _currentFolder.FileExplorerData.GetType().GetMethod("InsertFromPath");
var fileExplorerData = InsertMethod.Invoke(_currentFolder.FileExplorerData, new object[] { newPath });
var data = fileExplorerData as FileExplorerData;

 

posted @ 2013-01-07 09:37  xiaokang088  阅读(504)  评论(1编辑  收藏  举报