Skip to content
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

Make Parameter & PropertyDeclaration Classes Instead of Records #3450

Merged
merged 10 commits into from
May 30, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal class SystemModelSnippets : ModelSnippets
{
public override CSharpMethod BuildFromOperationResponseMethod(TypeProvider typeProvider, MethodSignatureModifiers modifiers)
{
var result = new Parameter("response", $"The result to deserialize the model from.", typeof(PipelineResponse), null, ValidationType.None, null);
var result = new Parameter("response", $"The result to deserialize the model from.", typeof(PipelineResponse));
return new CSharpMethod
(
new MethodSignature(ClientModelPlugin.Instance.Configuration.ApiTypes.FromResponseName, null, $"Deserializes the model from a raw response.", modifiers, typeProvider.Type, null, new[] { result }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ private ClientPipelineExtensionsProvider()
: base(null)
{
Name = "ClientPipelineExtensions";
_pipelineParam = new Parameter("pipeline", null, typeof(ClientPipeline), null, ValidationType.None, null);
_messageParam = new Parameter("message", null, typeof(PipelineMessage), null, ValidationType.None, null);
_requestContextParam = new Parameter("requestContext", null, typeof(RequestOptions), null, ValidationType.None, null);
_pipelineParam = new Parameter("pipeline", $"The pipeline.", typeof(ClientPipeline));
_messageParam = new Parameter("message", $"The message.", typeof(PipelineMessage));
_requestContextParam = new Parameter("requestContext", $"The request context.", typeof(RequestOptions));
_pipeline = new ParameterReference(_pipelineParam);
_message = new ParameterReference(_messageParam);
_requestContext = new ParameterReference(_requestContextParam);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Microsoft.Generator.CSharp.ClientModel
internal sealed class MrwSerializationTypeProvider : TypeProvider
{
private readonly Parameter SerializationOptionsParameter =
new("options", null, typeof(ModelReaderWriterOptions), null, ValidationType.None, null);
new("options", $"The client options.", typeof(ModelReaderWriterOptions));
private readonly CSharpType _iJsonModelTInterface;
private readonly CSharpType? _iJsonModelObjectInterface;
private readonly CSharpType _iPersistableModelTInterface;
Expand Down Expand Up @@ -85,7 +85,7 @@ protected override CSharpType[] BuildImplements()
/// </summary>
internal CSharpMethod BuildJsonModelWriteMethod()
{
Parameter utf8JsonWriterParameter = new("writer", null, typeof(Utf8JsonWriter), null, ValidationType.None, null);
Parameter utf8JsonWriterParameter = new("writer", $"The JSON writer.", typeof(Utf8JsonWriter));
// void IJsonModel<T>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
return new CSharpMethod
(
Expand All @@ -100,7 +100,7 @@ internal CSharpMethod BuildJsonModelWriteMethod()
/// </summary>
internal CSharpMethod BuildJsonModelCreateMethod()
{
Parameter utf8JsonReaderParameter = new("reader", null, typeof(Utf8JsonReader), null, ValidationType.None, null, IsRef: true);
Parameter utf8JsonReaderParameter = new("reader", $"The JSON reader.", typeof(Utf8JsonReader), isRef: true);
// T IJsonModel<T>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
var typeOfT = GetModelArgumentType(_iJsonModelTInterface);
return new CSharpMethod
Expand Down Expand Up @@ -131,7 +131,7 @@ internal CSharpMethod BuildIModelWriteMethod()
/// </summary>
internal CSharpMethod BuildIModelCreateMethod()
{
Parameter dataParameter = new("data", null, typeof(BinaryData), null, ValidationType.None, null);
Parameter dataParameter = new("data", $"The data to parse.", typeof(BinaryData));
// IPersistableModel<T>.Create(BinaryData data, ModelReaderWriterOptions options)
var typeOfT = GetModelArgumentType(_iPersistableModelTInterface);
return new CSharpMethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ internal class ScmTypeFactory : TypeFactory

public override Parameter CreateCSharpParam(InputParameter inputParameter)
{
return Parameter.FromInputParameter(inputParameter);
return new Parameter(inputParameter);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

namespace Microsoft.Generator.CSharp
{
internal record AutoPropertyBody(bool HasSetter, MethodSignatureModifiers SetterModifiers = MethodSignatureModifiers.None, ValueExpression? InitializationExpression = null) : PropertyBody;
internal record AutoPropertyBody(bool HasSetter, MethodSignatureModifiers SetterModifiers = MethodSignatureModifiers.None, ValueExpression? InitializationExpression = null) : PropertyBody(HasSetter);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private ChangeTrackingDictionaryProvider(SourceInputModel? sourceInputModel)
: base(sourceInputModel)
{
WhereClause = Where.NotNull(_tKey);
_indexParam = new Parameter("key", null, _tKey, null, ValidationType.None, null);
_indexParam = new Parameter("key", $"The key.", _tKey);
_IDictionary = new CSharpType(typeof(IDictionary<,>), _tKey, _tValue);
_dictionary = new CSharpType(typeof(Dictionary<,>), _tKey, _tValue);
_IReadOnlyDictionary = new CSharpType(typeof(IReadOnlyDictionary<,>), _tKey, _tValue);
Expand Down Expand Up @@ -81,7 +81,7 @@ protected override CSharpMethod[] BuildConstructors()

private CSharpMethod ConstructorWithReadOnlyDictionary()
{
var dictionaryParam = new Parameter("dictionary", null, _IReadOnlyDictionary, null, ValidationType.None, null);
var dictionaryParam = new Parameter("dictionary", $"The inner dictionary.", _IReadOnlyDictionary);
var dictionary = new DictionaryExpression(_tKey, _tValue, dictionaryParam);
var signature = new ConstructorSignature(Type, null, null, MethodSignatureModifiers.Public, new[] { dictionaryParam });
return new CSharpMethod(signature, new MethodBodyStatement[]
Expand All @@ -100,7 +100,7 @@ private CSharpMethod ConstructorWithReadOnlyDictionary()

private CSharpMethod ConstructorWithDictionary()
{
var dictionaryParam = new Parameter("dictionary", null, _IDictionary, null, ValidationType.None, null);
var dictionaryParam = new Parameter("dictionary", $"The inner dictionary.", _IDictionary);
var dictionary = new ParameterReference(dictionaryParam);
var signature = new ConstructorSignature(Type, null, null, MethodSignatureModifiers.Public, new[] { dictionaryParam });
return new CSharpMethod(signature, new MethodBodyStatement[]
Expand Down Expand Up @@ -152,7 +152,7 @@ private PropertyDeclaration BuildEnumerableKeys()

private PropertyDeclaration BuildIndexer()
{
var indexParam = new Parameter("key", null, _tKey, null, ValidationType.None, null);
var indexParam = new Parameter("key", $"The key.", _tKey);
return new IndexerDeclaration(null, MethodSignatureModifiers.Public, _tValue, indexParam, new MethodPropertyBody(
new MethodBodyStatement[]
{
Expand Down Expand Up @@ -190,7 +190,7 @@ private PropertyDeclaration BuildKeys()

private PropertyDeclaration BuildIsReadOnly()
{
return new PropertyDeclaration(null, MethodSignatureModifiers.Public, typeof(bool), "IsReadOnly",
return new PropertyDeclaration($"Gets the IsReadOnly", MethodSignatureModifiers.Public, typeof(bool), "IsReadOnly",
new ExpressionPropertyBody(new TernaryConditionalOperator(
IsUndefined,
False,
Expand Down Expand Up @@ -242,8 +242,8 @@ protected override CSharpMethod[] BuildMethods()

private CSharpMethod BuildTryGetValue()
{
var keyParam = new Parameter("key", null, _tKey, null, ValidationType.None, null);
var valueParam = new Parameter("value", null, _tValue, null, ValidationType.None, null, IsOut: true);
var keyParam = new Parameter("key", $"The key to search for.", _tKey);
var valueParam = new Parameter("value", $"The value.", _tValue, isOut: true);
var value = new ParameterReference(valueParam);
var signature = GetSignature("TryGetValue", typeof(bool), parameters: new[] { keyParam, valueParam });
return new CSharpMethod(signature, new MethodBodyStatement[]
Expand All @@ -259,7 +259,7 @@ private CSharpMethod BuildTryGetValue()

private CSharpMethod BuildRemoveKey()
{
var keyParam = new Parameter("key", null, _tKey, null, ValidationType.None, null);
var keyParam = new Parameter("key", $"The key.", _tKey);
var signature = GetSignature("Remove", typeof(bool), parameters: new[] { keyParam });
return new CSharpMethod(signature, new MethodBodyStatement[]
{
Expand All @@ -273,7 +273,7 @@ private CSharpMethod BuildRemoveKey()

private CSharpMethod BuildContainsKey()
{
var keyParam = new Parameter("key", null, _tKey, null, ValidationType.None, null);
var keyParam = new Parameter("key", $"The key to search for.", _tKey);
var signature = GetSignature("ContainsKey", typeof(bool), parameters: new[] { keyParam });
return new CSharpMethod(signature, new MethodBodyStatement[]
{
Expand All @@ -287,8 +287,8 @@ private CSharpMethod BuildContainsKey()

private CSharpMethod BuildAdd()
{
var keyParam = new Parameter("key", null, _tKey, null, ValidationType.None, null);
var valueParam = new Parameter("value", null, _tValue, null, ValidationType.None, null);
var keyParam = new Parameter("key", $"The key.", _tKey);
var valueParam = new Parameter("value", $"The value to add.", _tValue);
var signature = GetSignature("Add", null, parameters: new[] { keyParam, valueParam });
return new CSharpMethod(signature, new MethodBodyStatement[]
{
Expand All @@ -298,7 +298,7 @@ private CSharpMethod BuildAdd()

private CSharpMethod BuildRemovePair()
{
var itemParam = new Parameter("item", null, _keyValuePair, null, ValidationType.None, null);
var itemParam = new Parameter("item", $"The item to remove.", _keyValuePair);
var item = new ParameterReference(itemParam);
var signature = GetSignature("Remove", typeof(bool), parameters: new[] { itemParam });
return new CSharpMethod(signature, new MethodBodyStatement[]
Expand All @@ -314,9 +314,9 @@ private CSharpMethod BuildRemovePair()
private CSharpMethod BuildCopyTo()
{
//TODO: This line will not honor the generic type of the array
var arrayParam = new Parameter("array", null, typeof(KeyValuePair<,>).MakeArrayType(), null, ValidationType.None, null);
var arrayParam = new Parameter("array", $"The array to copy.", typeof(KeyValuePair<,>).MakeArrayType());
var array = new ParameterReference(arrayParam);
var indexParam = new Parameter("index", null, typeof(int), null, ValidationType.None, null);
var indexParam = new Parameter("index", $"The index.", typeof(int));
var index = new ParameterReference(indexParam);
var signature = GetSignature("CopyTo", null, parameters: new[] { arrayParam, indexParam });
return new CSharpMethod(signature, new MethodBodyStatement[]
Expand All @@ -331,7 +331,7 @@ private CSharpMethod BuildCopyTo()

private CSharpMethod BuildContains()
{
var itemParam = new Parameter("item", null, _keyValuePair, null, ValidationType.None, null);
var itemParam = new Parameter("item", $"The item to search for.", _keyValuePair);
var item = new ParameterReference(itemParam);
var signature = GetSignature("Contains", typeof(bool), parameters: new[] { itemParam });
return new CSharpMethod(signature, new MethodBodyStatement[]
Expand All @@ -355,7 +355,7 @@ private CSharpMethod BuildClear()

private CSharpMethod BuildAddPair()
{
var itemParam = new Parameter("item", null, _keyValuePair, null, ValidationType.None, null);
var itemParam = new Parameter("item", $"The item to add.", _keyValuePair);
var item = new ParameterReference(itemParam);
var signature = GetSignature("Add", null, parameters: new[] { itemParam });
return new CSharpMethod(signature, new MethodBodyStatement[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private class ChangeTrackingListTemplate<T> { }
private readonly FieldDeclaration _innerListField;
private readonly CSharpType _tArray;
private readonly Parameter _tParam;
private readonly Parameter _indexParam = new Parameter("index", null, typeof(int), null, ValidationType.None, null);
private readonly Parameter _indexParam = new Parameter("index", $"The index.", typeof(int));
private VariableReference _innerList;
private readonly CSharpType _iListOfT;
private readonly CSharpType _iReadOnlyListOfT;
Expand All @@ -42,7 +42,7 @@ private ChangeTrackingListProvider() : base(null)
_innerListField = new FieldDeclaration(FieldModifiers.Private, _iListOfT, "_innerList");
_innerList = new VariableReference(_iListOfT, _innerListField.Declaration);
_tArray = typeof(ChangeTrackingListTemplate<>).GetGenericArguments()[0].MakeArrayType();
_tParam = new Parameter("item", null, _t, null, ValidationType.None, null);
_tParam = new Parameter("item", $"The item.", _t);
EnsureList = This.Invoke(_ensureListSignature);
}

Expand All @@ -55,7 +55,7 @@ protected override TypeSignatureModifiers GetDeclarationModifiers()

protected override CSharpMethod[] BuildConstructors()
{
var iListParam = new Parameter("innerList", null, _iListOfT, null, ValidationType.None, null);
var iListParam = new Parameter("innerList", $"The inner list.", _iListOfT);
var iListSignature = new ConstructorSignature(Type, null, null, MethodSignatureModifiers.Public, new Parameter[] { iListParam });
var iListVariable = new ParameterReference(iListParam);
var iListBody = new MethodBodyStatement[]
Expand All @@ -66,7 +66,7 @@ protected override CSharpMethod[] BuildConstructors()
}
};

var iReadOnlyListParam = new Parameter("innerList", null, _iReadOnlyListOfT, null, ValidationType.None, null);
var iReadOnlyListParam = new Parameter("innerList", $"The inner list.", _iReadOnlyListOfT);
var iReadOnlyListSignature = new ConstructorSignature(Type, null, null, MethodSignatureModifiers.Public, new Parameter[] { iReadOnlyListParam });
var iReadOnlyListVariable = new ParameterReference(iReadOnlyListParam);
var iReadOnlyListBody = new MethodBodyStatement[]
Expand Down Expand Up @@ -111,7 +111,7 @@ protected override PropertyDeclaration[] BuildProperties() =>

private PropertyDeclaration BuildIsReadOnly()
{
return new PropertyDeclaration(null, MethodSignatureModifiers.Public, typeof(bool), "IsReadOnly",
return new PropertyDeclaration($"Gets the IsReadOnly", MethodSignatureModifiers.Public, typeof(bool), "IsReadOnly",
new ExpressionPropertyBody(new TernaryConditionalOperator(
IsUndefined,
False,
Expand All @@ -129,7 +129,7 @@ private PropertyDeclaration BuildCount()

private PropertyDeclaration BuildIndexer()
{
var indexParam = new Parameter("index", null, typeof(int), null, ValidationType.None, null);
var indexParam = new Parameter("index", $"The inner list.", typeof(int));
return new IndexerDeclaration(null, MethodSignatureModifiers.Public, _t, indexParam, new MethodPropertyBody(
new MethodBodyStatement[]
{
Expand Down Expand Up @@ -219,8 +219,8 @@ private CSharpMethod BuildRemove()

private CSharpMethod BuildCopyTo()
{
var arrayParam = new Parameter("array", null, _tArray, null, ValidationType.None, null);
var arrayIndexParam = new Parameter("arrayIndex", null, typeof(int), null, ValidationType.None, null);
var arrayParam = new Parameter("array", $"The array to copy to.", _tArray);
var arrayIndexParam = new Parameter("arrayIndex", $"The array index.", typeof(int));
return new CSharpMethod(new MethodSignature("CopyTo", null, null, MethodSignatureModifiers.Public, null, null, new Parameter[] { arrayParam, arrayIndexParam }), new MethodBodyStatement[]
{
new IfStatement(IsUndefined)
Expand Down Expand Up @@ -254,7 +254,7 @@ private CSharpMethod BuildClear()

private CSharpMethod BuildAdd()
{
var genericParameter = new Parameter("item", null, _t, null, ValidationType.None, null);
var genericParameter = new Parameter("item", $"The item to add.", _t);
return new CSharpMethod(new MethodSignature("Add", null, null, MethodSignatureModifiers.Public, null, null, new Parameter[] { genericParameter }), new MethodBodyStatement[]
{
new InvokeInstanceMethodStatement(EnsureList, "Add", new ParameterReference(genericParameter))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

namespace Microsoft.Generator.CSharp
{
internal record ExpressionPropertyBody(ValueExpression Getter) : PropertyBody;
internal record ExpressionPropertyBody(ValueExpression Getter) : PropertyBody(false);
}
Loading
Loading