At the time of writing this post, and having spent several hours scouring the internet, I couldn't for the life of me find a way to get a yield return statement.
The reason for this will be explained in another post (TODO:addlink) but the basic premise was to have the following line in the generated class:
01 yield return () => SomeStringProperty;
All the properties returned strings, so this was fine.
Trying to generate this was proving a problem, until I came across this...hmm...workaround (don't want to use the word hack here)
While it ties the generated code to be specifically C#, this, again was not a problem for the code base that we were working against.
Here is the code that produced the line:
01 generatedProperty.GetStatements.Add(new CodeSnippetExpression(string.Format("yield return () => {0}", existingProperty.Name)));
The genereatedProperty is of type CodeMemberProperty as is the existingProperty.
I wouldn't recommend this for all solutions, but it worked in this case where we were not trying to add to a generic code generator.
No comments:
Post a Comment