Skip to content

Commit

Permalink
Refine customized code in preparation for public serialization (#39753)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArcturusZhang authored Nov 7, 2023
1 parent 5347b5c commit 1efa389
Show file tree
Hide file tree
Showing 17 changed files with 296 additions and 219 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#nullable disable

using System.Runtime.CompilerServices;
using System.Text.Json;
using Azure.Core;

namespace Azure.ResourceManager.Compute.Models
Expand All @@ -12,6 +14,23 @@ public partial class ComputeResourceSkuLocationInfo
{
/// <summary> The type of the extended location. </summary>
[CodeGenMember("ExtendedLocationType")]
[CodeGenMemberSerializationHooks(SerializationValueHook = nameof(WriteExtendedLocationType), DeserializationValueHook = nameof(ReadExtendedLocationType))]
public Azure.ResourceManager.Resources.Models.ExtendedLocationType? ExtendedLocationType { get; }

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void WriteExtendedLocationType(Utf8JsonWriter writer)
{
writer.WriteStringValue(ExtendedLocationType.Value.ToString());
}

// deserialization hook for required property
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void ReadExtendedLocationType(JsonProperty property, ref Optional<Azure.ResourceManager.Resources.Models.ExtendedLocationType> type)
{
if (property.Value.ValueKind == JsonValueKind.Null)
return;

type = new Azure.ResourceManager.Resources.Models.ExtendedLocationType(property.Value.GetString());
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Runtime.CompilerServices;
using System.Text.Json;
using Azure.Core;

namespace Azure.ResourceManager.DataBox.Models
{
public partial class MitigateJobContent
{
// This is used to represent default null for breaking change of CustomerResolutionCode changed from requried to optional
internal CustomerResolutionCode? _customerResolutionCode;
// This is used to represent default null for breaking change of CustomerResolutionCode changed from required to optional
private CustomerResolutionCode? _customerResolutionCode;

/// <summary> Initializes a new instance of MitigateJobContent. </summary>
public MitigateJobContent()
Expand All @@ -20,10 +22,20 @@ public MitigateJobContent()
/// <param name="customerResolutionCode"> Resolution code for the job. </param>
public MitigateJobContent(CustomerResolutionCode customerResolutionCode) : this()
{
_customerResolutionCode = customerResolutionCode;
CustomerResolutionCode = customerResolutionCode;
}

/// <summary> Resolution code for the job. </summary>
public CustomerResolutionCode CustomerResolutionCode => _customerResolutionCode ?? default;
public CustomerResolutionCode CustomerResolutionCode
{
get
{
return _customerResolutionCode ?? default;
}
private set
{
_customerResolutionCode = value;
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions sdk/openai/Azure.AI.OpenAI/src/Custom/ImageGenerations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,25 @@ public partial class ImageGenerations
/// <summary>
/// Gets a list of generated image items in the format specified for the request.
/// </summary>
[CodeGenMemberSerializationHooks(DeserializationValueHook = nameof(DeserializeDataProperty))]
[CodeGenMemberSerializationHooks(SerializationValueHook = nameof(SerializeDataProperty), DeserializationValueHook = nameof(DeserializeDataProperty))]
public IReadOnlyList<ImageLocation> Data { get; }

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void SerializeDataProperty(Utf8JsonWriter writer)
{
// CUSTOM CODE NOTE: we always need to specify the serialization code explicitly when we change the type of a property
writer.WriteStartArray();
foreach (var item in Data)
{
writer.WriteObjectValue(item);
}
writer.WriteEndArray();
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void DeserializeDataProperty(JsonProperty property, ref IReadOnlyList<ImageLocation> data)
{
// CUSTOM CODE NOTE: this hook for Data is needed pending improved codegen support for union types; it
// otherwise generates with "property.Value.()"
// CUSTOM CODE NOTE: we always need to specify the serialization code explicitly when we change the type of a property
List<ImageLocation> array = new List<ImageLocation>();
foreach (var item in property.Value.EnumerateArray())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ public static partial class ResourceManagerModelFactory
public static Azure.ResourceManager.Resources.GenericResourceData GenericResourceData(Azure.Core.ResourceIdentifier id = null, string name = null, Azure.Core.ResourceType resourceType = default(Azure.Core.ResourceType), Azure.ResourceManager.Models.SystemData systemData = null, System.Collections.Generic.IDictionary<string, string> tags = null, Azure.Core.AzureLocation location = default(Azure.Core.AzureLocation), Azure.ResourceManager.Resources.Models.ExtendedLocation extendedLocation = null, Azure.ResourceManager.Models.ArmPlan plan = null, System.BinaryData properties = null, string kind = null, string managedBy = null, Azure.ResourceManager.Resources.Models.ResourcesSku sku = null, Azure.ResourceManager.Models.ManagedServiceIdentity identity = null, System.DateTimeOffset? createdOn = default(System.DateTimeOffset?), System.DateTimeOffset? changedOn = default(System.DateTimeOffset?), string provisioningState = null) { throw null; }
public static Azure.ResourceManager.Resources.Models.LocationExpanded LocationExpanded(string id, string subscriptionId, string name, Azure.ResourceManager.Resources.Models.LocationType? locationType, string displayName, string regionalDisplayName, Azure.ResourceManager.Resources.Models.LocationMetadata metadata) { throw null; }
public static Azure.ResourceManager.Resources.Models.LocationExpanded LocationExpanded(string id = null, string subscriptionId = null, string name = null, Azure.ResourceManager.Resources.Models.LocationType? locationType = default(Azure.ResourceManager.Resources.Models.LocationType?), string displayName = null, string regionalDisplayName = null, Azure.ResourceManager.Resources.Models.LocationMetadata metadata = null, System.Collections.Generic.IEnumerable<Azure.ResourceManager.Resources.Models.AvailabilityZoneMappings> availabilityZoneMappings = null) { throw null; }
public static Azure.ResourceManager.Resources.Models.LocationMetadata LocationMetadata(Azure.ResourceManager.Resources.Models.RegionType? regionType = default(Azure.ResourceManager.Resources.Models.RegionType?), Azure.ResourceManager.Resources.Models.RegionCategory? regionCategory = default(Azure.ResourceManager.Resources.Models.RegionCategory?), string geography = null, string geographyGroup = null, double? longitude = default(double?), double? latitude = default(double?), string physicalLocation = null, System.Collections.Generic.IEnumerable<Azure.ResourceManager.Resources.Models.PairedRegion> pairedRegions = null, string homeLocation = null) { throw null; }
public static Azure.ResourceManager.Resources.Models.ManagedByTenant ManagedByTenant(System.Guid? tenantId = default(System.Guid?)) { throw null; }
public static Azure.ResourceManager.ManagementGroups.Models.ManagementGroupChildInfo ManagementGroupChildInfo(Azure.ResourceManager.ManagementGroups.Models.ManagementGroupChildType? childType = default(Azure.ResourceManager.ManagementGroups.Models.ManagementGroupChildType?), string id = null, string name = null, string displayName = null, System.Collections.Generic.IEnumerable<Azure.ResourceManager.ManagementGroups.Models.ManagementGroupChildInfo> children = null) { throw null; }
public static Azure.ResourceManager.ManagementGroups.ManagementGroupData ManagementGroupData(Azure.Core.ResourceIdentifier id = null, string name = null, Azure.Core.ResourceType resourceType = default(Azure.Core.ResourceType), Azure.ResourceManager.Models.SystemData systemData = null, System.Guid? tenantId = default(System.Guid?), string displayName = null, Azure.ResourceManager.ManagementGroups.Models.ManagementGroupInfo details = null, System.Collections.Generic.IEnumerable<Azure.ResourceManager.ManagementGroups.Models.ManagementGroupChildInfo> children = null) { throw null; }
Expand Down Expand Up @@ -1375,6 +1376,7 @@ internal LocationExpanded() { }
public partial class LocationMetadata
{
internal LocationMetadata() { }
public string Geography { get { throw null; } }
public string GeographyGroup { get { throw null; } }
public string HomeLocation { get { throw null; } }
public double? Latitude { get { throw null; } }
Expand Down
Loading

0 comments on commit 1efa389

Please sign in to comment.