Domanda

This is what I mean.

I have a class with a constructor like so:

Class() : base(GetConstructorArgument1(), GetConstructorArgument2())
{
}

Because creating the arguments in the call to base, while possible, would be very cumbersome and gross. Both of those GetConstructorArgument methods are, by necessity, static.

GetConstructorArgument2() creates an array of lambdas. In those lambdas, I want to do work on "this", the object I am constructing.

Is there any way to do that?

È stato utile?

Soluzione

These methods, by definition, have to run before this is constructed. This is why they must be static methods. As such, there is no real way to access this within them.

There really isn't a way to do what you're describing.

Altri suggerimenti

Both of those GetConstructorArgument methods are, by necessity, static.

I want to do work on "this", the object I am constructing.

You can't do both of these - if the methods are static, there is no this to work on. Static methods belong to the class, not to the instance, so there's no instance to work with.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top