[API Request] Add Question to TaskDialogIcon.
- Dominant language
- C#
- Stars
- 4.9k
- Forks
- 1.1k
- Avg merge
- 20h 23m
- Merged PRs (30d)
- 103
Description
### Background and motivation
I find it a problem that ``TaskDialogIcon`` is missing ``Question`` with no direct *out-of-box* migration path for MessageBox's which use ``MessageBoxIcon.Question``.
**Why not just embed the icon myself?**
I feel like having to do something like this to get a 1:1 migration path away from the MessageBox API's *could* be simplified further if ``Question`` was added as a property to ``TaskDialogIcon``:
```cs
internal static class MessageBoxIconExtensions
{
internal static TaskDialogIcon ToTaskDialogIcon(this MessageBoxIcon icon)
=> icon switch
{
MessageBoxIcon.Question => new(SystemIcons.Question),
MessageBoxIcon.Information => TaskDialogIcon.Information,
MessageBoxIcon.Warning => TaskDialogIcon.Warning,
MessageBoxIcon.Error => TaskDialogIcon.Error,
MessageBoxIcon.None => TaskDialogIcon.None,
_ => throw new NotSupportedException("bug!!!"),
};
}
```
### API Proposal
```csharp
namespace System.Windows.Forms;
public class TaskDialogIcon : IDisposable
{
// snipped existing properties for the icons.
public static readonly TaskDialogIcon Question = new(SystemIcons.Question); // added
// snipped existing code.
}
```
### API Usage
```csharp
internal static class MessageBoxIconExtensions
{
internal static TaskDialogIcon ToTaskDialogIcon(this MessageBoxIcon icon)
=> icon switch
{
MessageBoxIcon.Question => TaskDialogIcon.Question, // <-- new API used here.
MessageBoxIcon.Information => TaskDialogIcon.Information,
MessageBoxIcon.Warning => TaskDialogIcon.Warning,
MessageBoxIcon.Error => TaskDialogIcon.Error,
MessageBoxIcon.None => TaskDialogIcon.None,
_ => throw new NotSupportedException("bug!!!"),
};
}
```
And yes I actually use code similar to this in one of my programs and would love to eventually be able to share this piece of code inside of more of them to migrate them to ``TaskDialog`` as a free and cheap upgrade path.
### Alternative Designs
I have not thought of any other alternative API's as I feel that this member to TaskDialogIcon would be the best idea as having a 1:1 migration path for 100% of all use cases for ``MessageBox`` -> ``TaskDialog`` *should* be worth investing in.
### Risks
Minimal as this would help people migrate 100% away from ``MessageBox`` and into ``TaskDialog`` which can be customized much better than ``MessageBox``. Also existing code that uses ``new TaskDialogIcon(SystemIcons.Question)`` can also be detected by the Windows Forms analyzer when used outside of the Windows Forms codebase to then suggest the change to use ``TaskDialogIcon.Question`` instead. Also with this it *could* become possible to then add ``[Obsolete]`` to the ``MessageBox`` class and possibly also remove it from winforms in a future version of .NET in favor of ``TaskDialog`` (on the reference assembly side with the runtime implementation being stubs to ``TaskDialog`` instead to not break existing applications).
### Will this feature affect UI controls?
I do not think this feature would affect any of the UI controls, would need to be localized, or even impact accessibility.
Contributor guide
Assessment
This issue has not been assessed yet.