The above referenced Stack Overflow question has an answer posted which includes details about the solution to this issue. The IFieldInitializerOperation can be obtained by discovering the EqualsValueClauseSyntax child node of the FieldDeclarationSyntax for inline field initializers. The manual parsing of the MarshalAsAttribute(s) provided by the referenced readonly field should be abandoned in favor of the much more powerful IOperation APIs.
Additional considerations
This issue depends on #15 as it refers to the same areas of the code.
Also, the Stack Overflow answer provides details about parsing values assigned to the readonly field inside of a constructor. This is currently not supported at all, and will be added as a new issue which will depend on this one.
Describe the issue
The methods in the
MarshalInfo
class in theincremental-generator
branch are responsible for parsing user-suppliedMarshalAsAttribute
s. It is supported for this attribute to be supplied by a reference to areadonly
field, but previously this was not properly implemented. The correct Roslyn APIs necessary were not understood. See GetOperation returning null for VariableDeclaratorSyntax, VariableDeclarationSyntax, and FieldDeclarationSyntax - Stack Overflow for more information.Proposed solution
The above referenced Stack Overflow question has an answer posted which includes details about the solution to this issue. The
IFieldInitializerOperation
can be obtained by discovering theEqualsValueClauseSyntax
child node of theFieldDeclarationSyntax
for inline field initializers. The manual parsing of theMarshalAsAttribute
(s) provided by the referencedreadonly
field should be abandoned in favor of the much more powerfulIOperation
APIs.Additional considerations
This issue depends on #15 as it refers to the same areas of the code.
Also, the Stack Overflow answer provides details about parsing values assigned to the
readonly
field inside of a constructor. This is currently not supported at all, and will be added as a new issue which will depend on this one.