Search code examples
c#tostringsealed

Change "ToString" for a sealed class


I have a class I am working with:

public sealed class WorkItemType

It's ToString is weak (Just shows Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemType).

Is there any way to override this to show the name of the WorkItemType?

Normally I would just aggregate the value in a new class, but I am using this for bindings in WPF (I want to have a list of WorkItemTypes in a combo box and assign the selected value to a bound WorkItemType variable.)

I think I am out of luck here, but I thought I would ask.


Solution

  • Do you need to override ToString? If you are in control of the code where the object is displayed, you can always provide a FormatWorkItemType method, or something to that effect.