what the hell is going on here

This commit is contained in:
Mike Griese
2025-08-19 11:00:19 -05:00
parent 13b7ff1315
commit 29e13df9cb
2 changed files with 86 additions and 3 deletions

View File

@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions;
using Microsoft.CommandPalette.Extensions.Toolkit; using Microsoft.CommandPalette.Extensions.Toolkit;
using Windows.Foundation; using Windows.Foundation;
@@ -180,14 +181,19 @@ internal sealed partial class SampleListPage : ListPage
{ {
Title = "I also have properties", Title = "I also have properties",
}, },
// new ListItem(new NoOpCommand() { Icon = new(new OneFontIconData("\u0027", "Wingdings")), Name = "one" }) { Title = "OneFontIconData", Tags = [new Tag("DynamicallyAccessedMembers"), new Tag("internal sealed"), new Tag("in samples")] },
// new ListItem(new NoOpCommand() { Icon = new(new TwoFontIconData("\u0028", "Wingdings")), Name = "two" }) { Title = "TwoFontIconData", Tags = [new Tag(" "), new Tag("internal sealed"), new Tag("in samples")] },
// new ListItem(new NoOpCommand() { Icon = new(new ThreeFontIconData("\u0029", "Wingdings")), Name = "three" }) { Title = "ThreeFontIconData", Tags = [new Tag("DynamicallyAccessedMembers"), new Tag("PUBLIC sealed"), new Tag("in samples")] },
]; ];
} }
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
internal sealed partial class CommandWithProperties : InvokableCommand, IExtendedAttributesProvider internal sealed partial class CommandWithProperties : InvokableCommand, IExtendedAttributesProvider
{ {
private FontIconData _icon = new("\u0026", "Wingdings"); private FontIconData _icon = new("\u0026", "Wingdings");
public override IconInfo Icon => new IconInfo(_icon, _icon); public override IconInfo Icon => new(_icon, _icon);
public override string Name => "Whatever"; public override string Name => "Whatever";
@@ -197,6 +203,18 @@ internal sealed partial class SampleListPage : ListPage
{ "Secret", 42 }, { "Secret", 42 },
{ "hmm?", null }, { "hmm?", null },
}; };
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(Microsoft.CommandPalette.Extensions.Toolkit.FontIconData))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(IDictionary<string, object>))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(Dictionary<string, object>))]
public static void PreserveTypes()
{
}
public CommandWithProperties()
{
PreserveTypes();
}
} }
internal sealed partial class OtherCommandWithProperties : IExtendedAttributesProvider, IInvokableCommand internal sealed partial class OtherCommandWithProperties : IExtendedAttributesProvider, IInvokableCommand
@@ -222,4 +240,63 @@ internal sealed partial class SampleListPage : ListPage
{ "hmm?", null }, { "hmm?", null },
}; };
} }
// [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
// internal sealed partial class OneFontIconData : IconData, IExtendedAttributesProvider
// {
// private string FontFamily { get; set; }
// private readonly IDictionary<string, object> _properties;
// public IDictionary<string, object> GetProperties() => _properties;
// public OneFontIconData(string glyph, string fontFamily)
// : base(glyph)
// {
// FontFamily = fontFamily;
// _properties = new Dictionary<string, object>()
// {
// { "FontFamily", FontFamily },
// };
// }
// }
// internal sealed partial class TwoFontIconData : IconData, IExtendedAttributesProvider
// {
// private string FontFamily { get; set; }
// private readonly IDictionary<string, object> _properties;
// public IDictionary<string, object> GetProperties() => _properties;
// public TwoFontIconData(string glyph, string fontFamily)
// : base(glyph)
// {
// FontFamily = fontFamily;
// _properties = new Dictionary<string, object>()
// {
// { "FontFamily", FontFamily },
// };
// }
// }
// [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
// public sealed partial class ThreeFontIconData : IconData, IExtendedAttributesProvider
// {
// private string FontFamily { get; set; }
// private readonly IDictionary<string, object> _properties;
// public IDictionary<string, object> GetProperties() => _properties;
// public ThreeFontIconData(string glyph, string fontFamily)
// : base(glyph)
// {
// FontFamily = fontFamily;
// _properties = new Dictionary<string, object>()
// {
// { "FontFamily", FontFamily },
// };
// }
// }
} }

View File

@@ -2,6 +2,8 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System.Diagnostics.CodeAnalysis;
namespace Microsoft.CommandPalette.Extensions.Toolkit; namespace Microsoft.CommandPalette.Extensions.Toolkit;
/// <summary> /// <summary>
@@ -14,12 +16,15 @@ namespace Microsoft.CommandPalette.Extensions.Toolkit;
/// UI for any other glyphs. This class is only needed if you want a non-Segoe /// UI for any other glyphs. This class is only needed if you want a non-Segoe
/// font icon. /// font icon.
/// </summary> /// </summary>
///
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
public partial class FontIconData : IconData, IExtendedAttributesProvider public partial class FontIconData : IconData, IExtendedAttributesProvider
{ {
private string FontFamily { get; set; } private string FontFamily { get; set; }
private readonly Dictionary<string, object> _properties; private readonly IDictionary<string, object> _properties;
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(Dictionary<string, object>))]
public IDictionary<string, object>? GetProperties() => _properties; public IDictionary<string, object>? GetProperties() => _properties;
public FontIconData(string glyph, string fontFamily) public FontIconData(string glyph, string fontFamily)
@@ -30,4 +35,5 @@ public partial class FontIconData : IconData, IExtendedAttributesProvider
{ {
{ "FontFamily", FontFamily }, { "FontFamily", FontFamily },
}; };
}
} }