Getting the current instance from within a static method

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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.

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
 
I know nothing about license managers, but I see that there is another
overload. Why wouldn't you just call.

LicenseManager.Validate(typeof(currentClass));

?
 
Hello,

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

VJ
 
Thanks.. that's what I was looking for... making sure there wasn't a way to
get the instance of the current class in a static method because that class
doesn't have an instance.

I got what I was looking for by creating a helper class... I just posted ot
make sure what I was doing wasn't just a workaround, but the only option.
 
Because the one you mentioned returns nothing (void) vs the one I'm trying to
use has a return value which I need.
 
Because the [overload of LicenseManager.Validate] you mentioned returns nothing (void) vs the one I'm trying to use has a return value which I need.

Ewww. I just went and looked at that now that you pointed it out.

Doesn't that violate generally accepted rules for creating overloads?
The documentation isn't even accurate: both methods are documented as:
"determines whether a license can be granted," but the second one
should also mention that the license _is_ granted if it can be granted:

http://msdn2.microsoft.com/en-us/library/fx418fwc(VS.80).aspx

Two overloads that do subtly different things. Yuck. I sent MS feedback
about the documentation.
 
Bruce Wood said:
Because the [overload of LicenseManager.Validate] you mentioned returns
nothing (void) vs the one I'm trying to use has a return value which I
need.
Doesn't that violate generally accepted rules for creating overloads?

Yes, the code (c# and vb.net) with overloads of a method with different
return type does not compile...

The documentation isn't even accurate: both methods are documented as:
"determines whether a license can be granted," but the second one
should also mention that the license _is_ granted if it can be granted:

http://msdn2.microsoft.com/en-us/library/fx418fwc(VS.80).aspx

Two overloads that do subtly different things. Yuck. I sent MS feedback
about the documentation.

Mmmm... I never seen these classes but I see in MSDN that the istance on
wich the license is validated need to be marked with
[LicenseProvider(typeof(LicFileLicenseProvider))]This is the reason for wich
is needed an istance, and not why it is simply a different overload.
 
Fabio said:
Bruce Wood said:
Because the [overload of LicenseManager.Validate] you mentioned returns
nothing (void) vs the one I'm trying to use has a return value which I
need.
Doesn't that violate generally accepted rules for creating overloads?

Yes, the code (c# and vb.net) with overloads of a method with different
return type does not compile...

Yes it does - if the signatures differ, which they do in this case. The
problem here isn't a compilation issue, it's a semantic issue -
overloads *usually* shouldn't differ in return type, because they
should usually do the same kind of thing with different inputs.

In this case, the behaviour is signficantly different between the two
overloads.

Jon
 
Back
Top