diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/MrwSerializationTypeDefinitions/ModelCustomizationTests.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/MrwSerializationTypeDefinitions/ModelCustomizationTests.cs
index f0c8b2758e..67bbdcc005 100644
--- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/MrwSerializationTypeDefinitions/ModelCustomizationTests.cs
+++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/MrwSerializationTypeDefinitions/ModelCustomizationTests.cs
@@ -174,5 +174,59 @@ public async Task CanCustomizeNullableStringToFixedEnum()
var file = writer.Write();
Assert.AreEqual(Helpers.GetExpectedFromFile(), file.Content);
}
+
+ [Test]
+ public async Task CanCustomizeEnumToFrameworkType()
+ {
+ await MockHelpers.LoadMockPluginAsync(compilation: async () => await Helpers.GetCompilationFromDirectoryAsync());
+
+ var props = new[] {
+ InputFactory.EnumMember.String("one", "val1"),
+ InputFactory.EnumMember.String("two", "val2"),
+ InputFactory.EnumMember.String("three", "val3")
+ };
+
+ var inputEnum = InputFactory.Enum("mockInputEnum", underlyingType: InputPrimitiveType.String, values: props, isExtensible: true);
+ var modelProp = InputFactory.Property("prop1", inputEnum);
+ var inputModel = InputFactory.Model("mockInputModel", properties: [modelProp], usage: InputModelTypeUsage.Json);
+
+ var plugin = await MockHelpers.LoadMockPluginAsync(
+ inputModels: () => [inputModel],
+ compilation: async () => await Helpers.GetCompilationFromDirectoryAsync());
+
+ var modelProvider = plugin.Object.OutputLibrary.TypeProviders.Single(t => t is ModelProvider);
+ var serializationProvider = modelProvider.SerializationProviders.Single(t => t is MrwSerializationTypeDefinition);
+ Assert.IsNotNull(serializationProvider);
+ var writer = new TypeProviderWriter(serializationProvider);
+ var file = writer.Write();
+ Assert.AreEqual(Helpers.GetExpectedFromFile(), file.Content);
+ }
+
+ [Test]
+ public async Task CanCustomizeEnumToFieldFrameworkType()
+ {
+ await MockHelpers.LoadMockPluginAsync(compilation: async () => await Helpers.GetCompilationFromDirectoryAsync());
+
+ var props = new[] {
+ InputFactory.EnumMember.String("one", "val1"),
+ InputFactory.EnumMember.String("two", "val2"),
+ InputFactory.EnumMember.String("three", "val3")
+ };
+
+ var inputEnum = InputFactory.Enum("mockInputEnum", underlyingType: InputPrimitiveType.String, values: props, isExtensible: true);
+ var modelProp = InputFactory.Property("prop1", inputEnum);
+ var inputModel = InputFactory.Model("mockInputModel", properties: [modelProp], usage: InputModelTypeUsage.Json);
+
+ var plugin = await MockHelpers.LoadMockPluginAsync(
+ inputModels: () => [inputModel],
+ compilation: async () => await Helpers.GetCompilationFromDirectoryAsync());
+
+ var modelProvider = plugin.Object.OutputLibrary.TypeProviders.Single(t => t is ModelProvider);
+ var serializationProvider = modelProvider.SerializationProviders.Single(t => t is MrwSerializationTypeDefinition);
+ Assert.IsNotNull(serializationProvider);
+ var writer = new TypeProviderWriter(serializationProvider);
+ var file = writer.Write();
+ Assert.AreEqual(Helpers.GetExpectedFromFile(), file.Content);
+ }
}
}
diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/ModelCustomizationTests/CanCustomizeEnumToFieldFrameworkType.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/ModelCustomizationTests/CanCustomizeEnumToFieldFrameworkType.cs
new file mode 100644
index 0000000000..56004ee5a1
--- /dev/null
+++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/ModelCustomizationTests/CanCustomizeEnumToFieldFrameworkType.cs
@@ -0,0 +1,148 @@
+//
+
+#nullable disable
+
+using System;
+using System.ClientModel;
+using System.ClientModel.Primitives;
+using System.Collections.Generic;
+using System.Text.Json;
+using Sample;
+
+namespace Sample.Models
+{
+ ///
+ public partial class MockInputModel : global::System.ClientModel.Primitives.IJsonModel
+ {
+ void global::System.ClientModel.Primitives.IJsonModel.Write(global::System.Text.Json.Utf8JsonWriter writer, global::System.ClientModel.Primitives.ModelReaderWriterOptions options)
+ {
+ writer.WriteStartObject();
+ this.JsonModelWriteCore(writer, options);
+ writer.WriteEndObject();
+ }
+
+ /// The JSON writer.
+ /// The client options for reading and writing models.
+ protected virtual void JsonModelWriteCore(global::System.Text.Json.Utf8JsonWriter writer, global::System.ClientModel.Primitives.ModelReaderWriterOptions options)
+ {
+ string format = (options.Format == "W") ? ((global::System.ClientModel.Primitives.IPersistableModel)this).GetFormatFromOptions(options) : options.Format;
+ if ((format != "J"))
+ {
+ throw new global::System.FormatException($"The model {nameof(global::Sample.Models.MockInputModel)} does not support writing '{format}' format.");
+ }
+ if (global::Sample.Optional.IsDefined(_prop1))
+ {
+ writer.WritePropertyName("prop1"u8);
+ writer.WriteObjectValue