-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
parameter property generate error CS0120 #88
Comments
I don't follow why these properties should be static? It would make more sense to me that they would be specific to the template instance - that way, runtime text templates could have multiple instances without risk of accidentally mixing up parameters (especially when using multiple threads). |
I did try to implement them not being static and the engine was not able to reference the property. making the read only property static was the simplest solution to making it work. |
Unless I'm misreading something, the template code appears to be trying to initialize a const string with an instance property value and then use that constant from a static property? IMO this is a problem with the template code, not the generated code. |
after everything was said and done. the following links are the working T4 templates. the files them selves are used in a vsix template. |
I don't see any parameters in those templates though? |
settings.ttinclude line 1. the the vsix template replaces |
I see. So the pattern here is an include that adds a parameter to the template class, and then defines a nested static helper class that wants to access that parameter from the template class instance. The template class also has to be aware of this and initialize the settings class by assigning it the host value. I can think of a few alternatives:
|
assuming, I am remembering the code correctly that sounds about right. what you are suggesting is in line with dependency injection pattern. That would solve the problem in a way that applicable for everyone. If I have the time to experiment I look into it. currently working on other projects that actually put bread on the table. |
Closing this for now as making these properties static would cause other problems and there are ways to structure a template so that the static properties are not needed. |
CS0120
GeneratedTextTransformation.txt
after looking at the code that was generated it looks like the field and the property need to be declared static
The text was updated successfully, but these errors were encountered: