Skip to content

Conversation

@live1206
Copy link
Contributor

@live1206 live1206 commented Apr 16, 2025

Resolves #5480

@microsoft-github-policy-service microsoft-github-policy-service bot added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label Apr 16, 2025
@github-actions
Copy link
Contributor

No changes needing a change description found.

@live1206 live1206 changed the title Add SystemObjectTypeProvider Implement SystemObjectTypeProvider Apr 24, 2025
@live1206 live1206 marked this pull request as ready for review April 24, 2025 10:14
: MethodSignatureModifiers.Protected | MethodSignatureModifiers.Virtual;

if (_shouldOverrideMethods)
if (_shouldOverrideMethods && _model.BaseModelProvider is not SystemObjectTypeProvider)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we generate Azure.ResourceManager with autorest.csharp, it only implements JsonModelWriteCore.
Once we generate it with MTG, we can remove this check for SystemObjectTypeProvider

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please file an issue and reference it in a TODO comment.


if (baseSystemProperties.TryGetValue(property.Name, out var baseSystemProperty))
{
if (DomainEqual(baseSystemProperty, property, isBaseSystemProperty: true))
Copy link
Contributor Author

@live1206 live1206 Apr 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BaseType from Azure.ResourceManager is not handling the property generation same as MTG, i.e. adding backing field and virtual for the derived property in BaseType.
So, we need to handle it differently.

Once we generate Azure.ResourceManager with MTG, we can remove this special handling.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

/// <summary>
/// Represent a type that already exists in dependencies
/// </summary>
public class SystemObjectTypeProvider : ModelProvider
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we specify that this type already exists in the tsp?

: MethodSignatureModifiers.Protected | MethodSignatureModifiers.Virtual;

if (_shouldOverrideMethods)
if (_shouldOverrideMethods && _model.BaseModelProvider is not SystemObjectTypeProvider)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this logic go into _shouldOverrideMethods?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it can't, details is in #7008 (comment)

var models = new List<TypeProvider>(input.Models.Count);
foreach (var inputModel in input.Models)
{
var outputModel = CodeModelGenerator.Instance.TypeFactory.CreateModel(inputModel);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the model just be null if we shouldn't be generating it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need the property and constructor signature from it while build the derived types.
If we return null here, we will need to use reflection to get the above information.
For current implementation, we don't use reflection like we did in autorest.csharp.

@live1206
Copy link
Contributor Author

SystemObjectTypeProvider is only needed in MPG generator for now, implement it in MPG generator instead in Azure/azure-sdk-for-net#49653

@live1206 live1206 closed this Apr 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement SystemObjectProvider for MTG

2 participants