Fixes https://github.com/Azure/autorest.csharp/issues/4327
`CodeWriterDeclaration` is useful, but it is not suitable to put inside
`FieldDeclaration` or `PropertyDeclaration`.
When writing the expressions for a type, we define the fields and
properties in one place, and may use them in other members, for example,
we might use the fields and properties in ctors, other fields, other
properties, or methods.
The `CodeWriterDeclaration` instance cannot be properly used unless it
has been "declared" somewhere first, but we cannot always guarantee that
when we are using this field, the field has been declared.
This is the first reason I would like to remove the usage of
`CodeWriterDeclaration` from these two types.
The second reason is: `CodeWriterDeclaration` is useful because the
`CodeWriter` tracks if there is already a declaration with the same
name, if so, it will append digits to the declaration so that in our
generated code, there would not be duplicated declared local variables.
This feature actually shows us that `CodeWriterDeclaration` should only
be used for local variable/parameter declaration to avoid name
collisions, and since it might rename the name, it is not suitable to
use to define a field or property, because we usually always want the
generated field/property to be exactly the name we give it.
Fixes https://github.com/Azure/autorest.csharp/issues/4630
This PR also includes a refactor to remove the
constant/reference/ReferenceOrConstant class, because we now have
expressions and statements, we could fully express those concepts using
the expressions/statements therefore we do not need these pre-expression
era things.
This PR fixes the case where setters were being generated for model
properties that were collection types. Model properties that are
collection types will no longer generated a setter unless they are
nullable.
---------
Co-authored-by: ShivangiReja <45216704+ShivangiReja@users.noreply.github.com>
Co-authored-by: Dapeng Zhang <ufo54153@gmail.com>
Co-authored-by: ShivangiReja <shivangi.reja@microsoft.com>
Migrated from
https://github.com/jorgerangel-msft/Microsoft.Generator.CSharp/pull/49.
This PR adds the client type provider and adds the initial type factory
method for CreateOperationMethods which constructs a collection of
CSharpMethod types for a given InputOperation. The implementation of
creating each of the methods for an input operation will be addressed in
follow up items.