Skip to content

Commit

Permalink
Update name transformer (#1978)
Browse files Browse the repository at this point in the history
* now we also transforms the values of enums

* regenerate

* refactor

* resolve comments
  • Loading branch information
ArcturusZhang authored Feb 17, 2022
1 parent 8700f23 commit b974274
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
23 changes: 17 additions & 6 deletions src/AutoRest.CSharp/Mgmt/Decorator/CodeModelExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ private static void TransformSchema(Schema schema, NameTransformer transformer,
{
switch (schema)
{
case ChoiceSchema:
case SealedChoiceSchema:
TransformBasicSchema(schema, transformer, wordCache);
case ChoiceSchema choiceSchema:
TransformChoiceSchema(choiceSchema.Language, choiceSchema.Choices, transformer, wordCache);
break;
case SealedChoiceSchema sealedChoiceSchema:
TransformChoiceSchema(sealedChoiceSchema.Language, sealedChoiceSchema.Choices, transformer, wordCache);
break;
case ObjectSchema objSchema: // GroupSchema inherits ObjectSchema, therefore we do not need to handle that
TransformObjectSchema(objSchema, transformer, wordCache);
Expand All @@ -87,9 +89,18 @@ private static void TransformSchema(Schema schema, NameTransformer transformer,
}
}

private static void TransformBasicSchema(Schema schema, NameTransformer transformer, ConcurrentDictionary<string, string> wordCache)
private static void TransformChoiceSchema(Languages languages, ICollection<ChoiceValue> choiceValues, NameTransformer transformer, ConcurrentDictionary<string, string> wordCache)
{
TransformLanguage(languages, transformer, wordCache);
TransformChoices(choiceValues, transformer, wordCache);
}

private static void TransformChoices(ICollection<ChoiceValue> choiceValues, NameTransformer transformer, ConcurrentDictionary<string, string> wordCache)
{
TransformLanguage(schema.Language, transformer, wordCache);
foreach (var choiceValue in choiceValues)
{
TransformLanguage(choiceValue.Language, transformer, wordCache);
}
}

private static void TransformLanguage(Languages languages, NameTransformer transformer, ConcurrentDictionary<string, string> wordCache)
Expand All @@ -108,7 +119,7 @@ private static void TransformLanguage(Languages languages, NameTransformer trans
private static void TransformObjectSchema(ObjectSchema objSchema, NameTransformer transformer, ConcurrentDictionary<string, string> wordCache)
{
// transform the name of this schema
TransformBasicSchema(objSchema, transformer, wordCache);
TransformLanguage(objSchema.Language, transformer, wordCache);
foreach (var property in objSchema.Properties)
{
TransformLanguage(property.Language, transformer, wordCache);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ public VirtualMachineScaleSetScaleInRules(string value)
}

private const string DefaultValue = "Default";
private const string OldestVMValue = "OldestVM";
private const string NewestVMValue = "NewestVM";
private const string OldestVmValue = "OldestVM";
private const string NewestVmValue = "NewestVM";

/// <summary> Default. </summary>
public static VirtualMachineScaleSetScaleInRules Default { get; } = new VirtualMachineScaleSetScaleInRules(DefaultValue);
/// <summary> OldestVM. </summary>
public static VirtualMachineScaleSetScaleInRules OldestVM { get; } = new VirtualMachineScaleSetScaleInRules(OldestVMValue);
public static VirtualMachineScaleSetScaleInRules OldestVm { get; } = new VirtualMachineScaleSetScaleInRules(OldestVmValue);
/// <summary> NewestVM. </summary>
public static VirtualMachineScaleSetScaleInRules NewestVM { get; } = new VirtualMachineScaleSetScaleInRules(NewestVMValue);
public static VirtualMachineScaleSetScaleInRules NewestVm { get; } = new VirtualMachineScaleSetScaleInRules(NewestVmValue);
/// <summary> Determines if two <see cref="VirtualMachineScaleSetScaleInRules"/> values are the same. </summary>
public static bool operator ==(VirtualMachineScaleSetScaleInRules left, VirtualMachineScaleSetScaleInRules right) => left.Equals(right);
/// <summary> Determines if two <see cref="VirtualMachineScaleSetScaleInRules"/> values are not the same. </summary>
Expand Down

0 comments on commit b974274

Please sign in to comment.