What does this code do?

Can someone 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 was looking for the msdn library but couldn't figure out what it did.

This is not a complete code, but I obey the rest, this is only this part that I struggle with.

+5
source share
3 answers

It looks like it gets shell actions that a specific program is associated with. For example, Open, Print, Edit, etc.

Open regedit and go to HKEY_LOCAL_MACHINE \ SOFTWARE \ Classes \ textfile

Expand it and look at the Shell key. The code should return verbs like this.

+4
source

This creates a "Shell.Application"COM object and then uses it dynamicto call methods on it.

, .

scripting. . .

+4

To extend Aliostad's answer, a keyword dynamicin C # allows you to call participants and methods of an unknown type. This means that with the variable dynamicyou will not get intellisense, since the compiler does not know what elements or methods the variable actually has. All this is clarified at runtime.

Here is a good explanation .

+1
source

All Articles