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

Add update method instead of setters for CSharpType #6035

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

live1206
Copy link
Contributor

@live1206 live1206 commented Feb 18, 2025

  • Remove public setter for CSharpType, add Update method instead
  • Remove constructor of TypeProvider for CSharpType
  • Update Name property of TypeProvider to return Type.Name

These changes are needed for Azure/azure-sdk-for-net#48362

@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 Feb 18, 2025
@live1206 live1206 marked this pull request as ready for review February 20, 2025 02:35
/// <summary>
/// Gets and sets the name of the type.
/// </summary>
public string Name
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we making this one settable? Isn't it enough that CSharpType.Name is settable? I think we should do away with this public property similar to what we did with Namespace.

Copy link
Contributor Author

@live1206 live1206 Feb 20, 2025

Choose a reason for hiding this comment

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

I don't think Name can be simply removed like Namespace, it has been widely used, updated to take _type.Name as preference.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

/// <summary>
/// Gets and sets the declaration modifiers for the type.
/// </summary>
public TypeSignatureModifiers DeclarationModifiers
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need the setter here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed


private string? _relativeFilePath;

public string Name => _name ??= CustomCodeView?.Name ?? BuildName();
public string Name =>
Copy link
Contributor

Choose a reason for hiding this comment

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

We should remove this property since it will be on the CSharpType.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Name has been copied to CSharpType

The source of truth is here, and the Name property has been used everywhere, and the original value comes from BuildName() in TypeProvider, we need _name to hold it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok then we can revert the change here.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's fine to retain the property for usability, but there should only be one source for Name -> Type.Name. It should mirror how it works for namespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But then, we need to update both TypeProvider.Name and CSharpType.Name since the name got copied into CSharpType since we don't hold Implementation in CSharpType.

Copy link
Contributor

Choose a reason for hiding this comment

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

We should do the same thing we do with namespace where we pass it into the internal ctor of CSharpType.

Copy link
Contributor Author

@live1206 live1206 Feb 21, 2025

Choose a reason for hiding this comment

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

OK then, I need to update the constructor of CSharpType to name to break the circular dependency
instead of

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

/// <summary>
/// Gets or sets the name of the type.
/// </summary>
public string Name { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we instead add an Update method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#6035 (comment)
OK. Thought you were saying I can still add the setter, we will use update method later.
But, if we decide to use the update method instead. Sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@live1206 live1206 changed the title Add public setter for TypeProvider Add update method instead of setters for CSharpType Feb 21, 2025
if (name != null)
{
Name = name;
FullyQualifiedName = $"{Namespace}.{name}";
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: we can just make this property be a lambda getter so we don't have to set it all over the place.

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.

2 participants