如何加载程序集并创建if的新instans [英] How to load assembly and create new instans of if

查看:50
本文介绍了如何加载程序集并创建if的新instans的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这段代码加载一个程序集并创建一个if的新实例,我怎样才能在aspx页面中使用javascript执行此操作?



Hi,
This code Loads an assembly and creates a new instance of if, how could i do this in an aspx page using javascript?

[Reflection.Assembly]::LoadWithPartialName("MyCustomFrameWork")
$CM = new-object MyCustomFrameWork.Configuration.ConfigurationManager($Web)</pre



<pre lang="C#"><%@ Assembly Name="~/_CONTROLTEMPLATES/MyCustomFrameWork, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f2f41da5e6d39bd0" %>





这样做可能吗?



但我无法创建它的新实例?



MyCustomFrameWork custom = new MyCustomFrameWork?



在javascript中



Doing like this maybe?

But i can not create a new instance of it?

MyCustomFrameWork custom= new MyCustomFrameWork?

In javascript

推荐答案

CM = new-object MyCustomFrameWork.Configuration.ConfigurationManager(
CM = new-object MyCustomFrameWork.Configuration.ConfigurationManager(


Web )< / pre



< pre lang = C# > <%@ 程序集 名称 = 〜/ _CONTROLTEMPLATES / MyCustomFrameWork,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = f2f41da5e6d39bd0 %> ;
Web)</pre <pre lang="C#"><%@ Assembly Name="~/_CONTROLTEMPLATES/MyCustomFrameWork, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f2f41da5e6d39bd0" %>





这样做可能吗?



但是我无法创建它的新实例?



MyCustomFrameWork custom = new MyCustomFrameWork?



在javascript中



Doing like this maybe?

But i can not create a new instance of it?

MyCustomFrameWork custom= new MyCustomFrameWork?

In javascript


首先,不要高估发生的事情创建程序集时的ns。您不会像在.NET上理解的那样创建和组装.NET作为.NET模块化的主要单元和.NET的主要功能对象。



您只需获取对类实例的引用 System.Reflection.Assembly

https://msdn.microsoft.com/en-us/library/system.reflection.assembly%28v=vs.110 %29.aspx [ ^ ]。



你能看出差异吗?这不是程序集,而是表示程序集的类的实例,因为它在反射 technology 中被理解。从本质上讲,这是允许您使用程序集类型的东西,这使您不仅可以使用程序集元数据来实例化某些类并获取有关程序集元数据的任何信息。根据你的工作方式,你可以在反射内容方面有所不同。



你没有费心去解释你将如何处理装配,所以我只想回答你的问题。

要加载程序集,你需要查看方法 Assembly.Load Assembly.LoadFile Assembly.LoadFrom Assembly.LoadWithPartialName Assembly.ReflectionOnlyLoad Assembly.UnsafeLoadFrom

https://msdn.microsoft.com/en-us/library/system.reflection.assembly%28v=vs .110%29.aspx [ ^ ]。



您可以创建 System.Reflection的新实例.Assembly 通过这些方法对象。没有像另存为的东西;这没有任何意义。我希望将 Assembly -type变量分配给另一个变量只会创建对同一对象的新引用,而不是新对象。



此外,您可以动态生成一些程序集。这可以通过CodeDOM或 System.Reflection.Emit 完成。这些是你真正动态创建新代码的情况。你没有提到这样的可能性,所以我只给你基本的参考资料:

https://msdn.microsoft.com/en-us/library/650ax5cx%28v=vs.110%29.aspx [ ^ ],

https://msdn.microsoft.com/en- us / library / 8ffc3x75%28v = vs.85%29.aspx [ ^ ]。



如何在ASP.NET中完成所有操作? ASP.NET基于.NET,所以答案是:以上面解释的相同方式。只为什么?你自己想想;你没有理会解释你的想法。



现在,关于JavaScript:它与程序集以及.NET和ASP.NET无关。它是在浏览器中执行的,即在客户端部分,ASP.NET完全在服务器部分工作。 JavaScript唯一可能的作用就是向服务器端发送一些HTTP请求;并且服务器端可以执行您在服务器端编程的任何操作。要发送HTTP请求,您需要使用AJAX: http://en.wikipedia.org/wiki/Ajax_(programming) [ ^ ]。



整个问题几乎没有任何意义。我担心这是基于一些幻想。



-SA
First of all, don't overestimate what happens when you create "assembly". You don't create and assembly as it is understood on .NET, as the main unit of .NET modularity and main functional object of .NET.

You merely obtain a reference to the instance of the class System.Reflection.Assembly:
https://msdn.microsoft.com/en-us/library/system.reflection.assembly%28v=vs.110%29.aspx[^].

Can you see the difference? This is not the assembly, but the instance of the class representing the assembly as it is understood in reflection technology. Essentially, this is something which allows you to work with assembly types, something which allows you not just to use the assembly metadata to instantiate some classes and fetch any information on the assembly metadata. Depending on how you do it, you can get different in reflection-only content.

You did not bother to explain what you are going to do with the assembly, so I'll just answer your questions.
To load assembly, you need to look at the methods Assembly.Load, Assembly.LoadFile, Assembly.LoadFrom, Assembly.LoadWithPartialName, Assembly.ReflectionOnlyLoad and Assembly.UnsafeLoadFrom:
https://msdn.microsoft.com/en-us/library/system.reflection.assembly%28v=vs.110%29.aspx[^].

You can create a new instance of the System.Reflection.Assembly object through these methods. There is nothing like "save as"; it would not make any sense. I hope that assigning the Assembly-type variable to another variable will merely create a new reference to the same object, not a new object.

Also, you can generate some assembly on the fly. This is done either via CodeDOM or System.Reflection.Emit. These are the cases when you really create new code on the fly. You did not mention any possibilities like that, so I'll only give you the basic references:
https://msdn.microsoft.com/en-us/library/650ax5cx%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/8ffc3x75%28v=vs.85%29.aspx[^].

How to do it all in ASP.NET? ASP.NET is based on .NET, so the answer is: in the same very ways explained above. Only why? You think about it yourself; you did not bother to explain your idea.

Now, about JavaScript: it has nothing to do with assemblies and .NET and ASP.NET. It is something executed in the browser, that is, in the client part, and ASP.NET works totally on the server part. The only possible role of JavaScript would be just to send some HTTP request to the server side; and the server side can do whatever you program on the server side. To send HTTP request, you need to use AJAX: http://en.wikipedia.org/wiki/Ajax_(programming)[^].

The whole question makes very little to no sense. I'm afraid it's based on some illusions.

—SA


这篇关于如何加载程序集并创建if的新instans的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆