在运行时投射对象
我想使用反射执行以下代码行。
IWshRuntimeLibrary.IWshShortcut desktopShortCut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(Environment.SpecialFolder.Desktop.ToString()+"\\Max Y+Y.lnk");
我已经成功地得到了表达的正确部分。
WshShell.CreateShortcut(....)
通过使用
this.assembly = Assembly.LoadFrom(Environment.CurrentDirectory + "\\Interop.IWshRuntimeLibrary.dll");
AppDomain.CurrentDomain.Load(assembly.GetName());
this.WshShellClass = assembly.GetType("IWshRuntimeLibrary.WshShellClass");
object classInstance = Activator.CreateInstance(this.WshShellClass, null);
object[] parameters = new object[1];
parameters[0] = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Max Y+Y.lnk";
MethodInfo methodInfo = this.WshShellClass.GetMethod("CreateShortcut");
object result = methodInfo.Invoke(classInstance, parameters);
Now,我想将其转换为类型 IWshRuntimeLibrary.IWshShortcut
结果的对象,并将其分配给上面的情况。
IWshRuntimeLibrary.IWshShortcut desktopShortCut,
这怎么可能?
I want to perform the following line of code using reflection.
IWshRuntimeLibrary.IWshShortcut desktopShortCut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(Environment.SpecialFolder.Desktop.ToString()+"\\Max Y+Y.lnk");
I have successfully get the right part of expression.
WshShell.CreateShortcut(....)
By using
this.assembly = Assembly.LoadFrom(Environment.CurrentDirectory + "\\Interop.IWshRuntimeLibrary.dll");
AppDomain.CurrentDomain.Load(assembly.GetName());
this.WshShellClass = assembly.GetType("IWshRuntimeLibrary.WshShellClass");
object classInstance = Activator.CreateInstance(this.WshShellClass, null);
object[] parameters = new object[1];
parameters[0] = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Max Y+Y.lnk";
MethodInfo methodInfo = this.WshShellClass.GetMethod("CreateShortcut");
object result = methodInfo.Invoke(classInstance, parameters);
Now I want to cast it to object of Type IWshRuntimeLibrary.IWshShortcut
result in above case and assign it to.
IWshRuntimeLibrary.IWshShortcut desktopShortCut,
How is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果
WshShellClass.CreateShortcut
返回一个IWshRuntimeLibrary.IWshShortcut
那么你可以说我错过了什么吗?
If
WshShellClass.CreateShortcut
returns aIWshRuntimeLibrary.IWshShortcut
then you could just sayAm I missing something?