Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[API Proposal]: CurrencyInfo #115322

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

Closed
hishamco opened this issue May 6, 2025 · 9 comments
Closed

[API Proposal]: CurrencyInfo #115322

hishamco opened this issue May 6, 2025 · 9 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Globalization

Comments

@hishamco
Copy link
Member

hishamco commented May 6, 2025

Background and motivation

Simplify the process for accessing currency information. The intent is to introduce a new class CurrencyInfo, something similar to CultureInfo and RegionInfo, that encapsulates the currency metadata that's currently available in RegionInfo

If you find this a good idea, I can submit a PR

API Proposal

namespace System.Globalization;

public class CurrencyInfo
{
    public string EnglishName { get; set;}

    public string ISOSymbol { get; set;}

    public string Symbol { get; set;}

    public CurrencyInfo GetCurrencyInfo(string cultureName);
}

API Usage

// Fancy the value
var yrCurrency = new CurrencyInfo.CurrencyInfo("ar-YE");

Console.WriteLine(yrCurrency.Symbol);

### Alternative Designs

_No response_

### Risks

_No response_
@hishamco hishamco added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label May 6, 2025
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label May 6, 2025
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label May 6, 2025
@huoyaoyuan huoyaoyuan added area-System.Globalization and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels May 6, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-globalization
See info in area-owners.md if you want to be subscribed.

@tarekgh
Copy link
Member

tarekgh commented May 6, 2025

Thanks for your suggestion.

I don't see how this simplifies anything. You're essentially suggesting replacing new RegionInfo("ar-YE") with CurrencyInfo.CurrencyInfo("ar-YE"). Let's wait and see if a real use case arises that demands this approach—then we can revisit the idea.

@tarekgh tarekgh closed this as not planned Won't fix, can't repro, duplicate, stale May 6, 2025
@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label May 6, 2025
@hishamco
Copy link
Member Author

hishamco commented May 6, 2025

I don't see how this simplifies anything. You're essentially suggesting replacing new RegionInfo("ar-YE") with CurrencyInfo.CurrencyInfo("ar-YE")

It's an accessor, nowadays if someone needs to get the currency info he/she needs to go through RegionalInfo

@tarekgh
Copy link
Member

tarekgh commented May 6, 2025

if someone needs to get the currency info he/she needs to go through RegionalInfo

What's wrong with that? Currency is always associated with a region, so it makes sense to retrieve it through the region. It's similar to how date formats work—they're tied to a culture, so you obtain them through the culture. and not having something like DateFromat.DateFormatInfo("ar-YE") this will look very weird.

@hishamco
Copy link
Member Author

hishamco commented May 6, 2025

Also we already have NumberFormatInfo if I recall

@tarekgh
Copy link
Member

tarekgh commented May 6, 2025

You only get the NumberFormatInfo from the culture object. So, you need to have a CultureInfo object to access the number formats. Similarly, you need to have RegionInfo to access the currency information. make sense?

@hishamco
Copy link
Member Author

hishamco commented May 6, 2025

Again I find DateTimeFormatInfo, at least we need a type that encapsulate currency meta data, which is useful IMHO

@tarekgh
Copy link
Member

tarekgh commented May 7, 2025

I’d agree with you if RegionInfo didn’t already expose individual currency properties. Introducing something like RegionInfo.CurrencyInfo now would be confusing, since it would duplicate the same properties already available in RegionInfo. And for compatibility reasons, we can’t remove those existing properties. I hope this helps clarify why I'm hesitant to accept the suggestion.

@hishamco
Copy link
Member Author

hishamco commented May 7, 2025

I'm not saying to remove the previous properties, we could keep them for compatibility, we could introduce a property on CultureInfo if we do so

CurrencyInfo currencyInfo = CultureInfo.GetCultureInfo("en-US").Currency;

Console.WriteLine(currencyInfo.Code);

This will be similar to what we have today, so we can deprecate the previous properties if they don't fit in the proper place. We could got a feedback from the team and community

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Globalization
Projects
None yet
Development

No branches or pull requests

3 participants