从静态方法中获取当前实例 [英] Getting the current instance from within a static method

查看:63
本文介绍了从静态方法中获取当前实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从

静态方法中获取正在执行的程序集的当前实例?我正在尝试使用LicenseManager.Validate(类型,实例)

方法并且无法在静态方法中调用它

(特别是控制台'' Main())。


如果它不是静态的,我只需要调用

LicenseManager.Validate(typeof(currentClass),this) ,但这不可用

这是一种静态方法。


-

-AC [MVP MCMS]
http://www.andrewconnell.com
< a rel =nofollowhref =http://www.andrewconnell.com/mvptarget =_ blank> http://www.andrewconnell.com/mvp

How do you get the current instance of an executing assembly from within a
static method? I''m trying to use the LicenseManager.Validate(type,instance)
method and having trouble calling it from within a static method
(specifically a console''s Main()).

If it wasn''t static, I''d just call
LicenseManager.Validate(typeof(currentClass), this), but this isn''t available
when it''s a static method.

--
-AC [MVP MCMS]
http://www.andrewconnell.com
http://www.andrewconnell.com/mvp

推荐答案

如果它不是静态的,我只需要调用
LicenseManager.Validate(typeof(currentClass) ),这个,但这是不可用的
当它是一个静态的方法。
If it wasn''t static, I''d just call
LicenseManager.Validate(typeof(currentClass), this), but this isn''t available
when it''s a static method.




根本没有对象instanc e进入静态方法。也许

另一个Validate重载只需要一个Type更合适

适合你吗?

Mattias


-

Mattias Sj?gren [C#MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com

请回复到新闻组。



There''s simply no object instance to get in a static method. Perhaps
the other Validate overload that only takes a Type is more appropriate
for you?
Mattias

--
Mattias Sj?gren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


我对许可证管理器一无所知,但我发现还有另一个

重载。你为什么不打电话。


LicenseManager.Validate(typeof(currentClass));




I know nothing about license managers, but I see that there is another
overload. Why wouldn''t you just call.

LicenseManager.Validate(typeof(currentClass));

?


您好,


您是否尝试在LicenseValidation的静态Main方法中执行此操作...

这就是你遇到问题的原因吗?


VJ


" AC [MVP MCMS]" < SW ********* @ gmail.com>在留言中写道

news:98 ********************************** @ microsof t.com ...
Hello,

Are you trying to do this in a static Main method for LicenseValidation...
is that why you have the problem?

VJ

"AC [MVP MCMS]" <sw*********@gmail.com> wrote in message
news:98**********************************@microsof t.com...
如何从
静态方法中获取正在执行的程序集的当前实例?我正在尝试使用
LicenseManager.Validate(类型,实例)
方法,并且无法在静态方法中调用它(特别是控制台的Main()) 。

如果它不是静态的,我只需要调用
LicenseManager.Validate(typeof(currentClass),这个),但这不是可用的
当它是静态方法时。

-
-AC [MVP MCMS]
http://www.andrewconnell.com
http://www.andrewconnell.com/mvp



这篇关于从静态方法中获取当前实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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