Repository: microsoft/PowerToys
File: src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/Main.cs (C#)

Code before:
                    Title = result.ToString(null),
                    IcoPath = _icon_path,
                    Score = 300,
                    SubTitle = string.Format(CultureInfo.CurrentCulture, ConvertFromOunce, ounceName) + " - " + string.Format(CultureInfo.CurrentCulture, CopyToClipboard, result.QuantityInfo.Name),
                    Action = c =>
                    {
                        var ret = false;
                        var thread = new Thread(() =>
                        {
                            try
                            {
                                Clipboard.SetText(result.ConvertedValue.ToString(UnitConversionResult.Format, CultureInfo.CurrentCulture));
                                ret = true;
                            }
                            catch (ExternalException)
                            {
                                MessageBox.Show(Properties.Resources.copy_failed);
                            }
                        });
                        thread.SetApartmentState(ApartmentState.STA);
                        thread.Start();
                        thread.Join();
                        return ret;
                    },
                };
            }

            return new Result
            {
                ContextData = result,
                Title = result.ToString(null),
                IcoPath = _icon_path,
                Score = 300,
                SubTitle = string.Format(CultureInfo.CurrentCulture, CopyToClipboard, result.QuantityInfo.Name),
                Action = c =>
                {
                    var ret = false;
                    var thread = new Thread(() =>
                    {
                        try
                        {
                            Clipboard.SetText(result.ConvertedValue.ToString(UnitConversionResult.Format, CultureInfo.CurrentCulture));
                            ret = true;
                        }
                        catch (ExternalException)
                        {
                            MessageBox.Show(Properties.Resources.copy_failed);
                        }
                    });
                    thread.SetApartmentState(ApartmentState.STA);
                    thread.Start();

Review comment (refactor):
Too have less duplicated code:

Then we need only one `Result` definition where we use the subTitleText variable.

```suggestion
            string unitFromName = GetFromUnitNameString(result);
            if (!string.IsNullOrEmpty(unitFromName))
            {
                    subTitleText = string.Format(CultureInfo.CurrentCulture, ConvertFromOunce, ounceName) + " - " + string.Format(CultureInfo.CurrentCulture, CopyToClipboard, result.QuantityInfo.Name);
            }
            else
            {
                    subTitleText = string.Format(CultureInfo.CurrentCulture, CopyToClipboard, result.QuantityInfo.Name);
            }
```


Code after:
                        catch (ExternalException)
                        {
                            MessageBox.Show(Properties.Resources.copy_failed);
                        }
                    });
                    thread.SetApartmentState(ApartmentState.STA);
                    thread.Start();
                    thread.Join();
                    return ret;
                },
            };
        }

        private ContextMenuResult CreateContextMenuEntry(UnitConversionResult result)
        {
            return new ContextMenuResult
            {
                PluginName = Name,
                Title = Properties.Resources.context_menu_copy,
                Glyph = "\xE8C8",
                FontFamily = "Segoe Fluent Icons,Segoe MDL2 Assets",
                AcceleratorKey = Key.Enter,
                Action = _ =>
                {
                    bool ret = false;
                    var thread = new Thread(() =>
                    {
                        try
                        {
                            Clipboard.SetText(result.ConvertedValue.ToString(UnitConversionResult.Format, CultureInfo.CurrentCulture));
                            ret = true;
                        }
                        catch (ExternalException)
                        {
                            MessageBox.Show(Properties.Resources.copy_failed);
                        }
                    });
                    thread.SetApartmentState(ApartmentState.STA);
                    thread.Start();
                    thread.Join();
                    return ret;
                },
            };
        }

        public List<ContextMenuResult> LoadContextMenus(Result selectedResult)
        {
            if (!(selectedResult?.ContextData is UnitConversionResult))
            {
                return new List<ContextMenuResult>();
            }