Reputation: 908
Could someone please explain to me what the following lines of code do?
dynamic shellApplication = Activator.CreateInstance(Type.GetTypeFromProgID("Shell.Application"));
string path = System.IO.Path.GetDirectoryName(filePath);
string fileName = System.IO.Path.GetFileName(filePath);
dynamic directory = shellApplication.NameSpace(path);
dynamic link = directory.ParseName(fileName);
dynamic verbs = link.Verbs();
I've searched the msdn library, but couldn't really understand what it did.
This isn't the full code, but I undertand the rest, it is just this part that I'm struggling with.
Upvotes: 5
Views: 740
Reputation: 88044
Looks like it is retrieving the shell actions that a particular program is associated with. For example Open, Print, Edit, etc.
Open regedit and navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Classes\textfile
Expand it out and look at the Shell key. The code should be returning verbs similar to that.
Upvotes: 4
Reputation: 27773
To expand on Aliostad's answer, the dynamic
keyword in C# allows you to call members and methods on an unknown type. This means using a dynamic
variable you won't get intellisense since the compiler has no clue what members or methods the variable actually has. This is all figured out at runtime.
Here is a good explanation.
Upvotes: 1