-
Notifications
You must be signed in to change notification settings - Fork 458
[dev-v5] Pull in v4 PRs (part 2) #4218
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f76ba2e
Implement #4036
vnbaaij df08371
Implement #4070
vnbaaij 734bd5e
Implement #4112
vnbaaij f928a1c
Implement #4116
vnbaaij 5e76a6c
Add extra test. Brings back code coverage to 100% for Row and Cell
vnbaaij be46fe0
Implement #4172
vnbaaij 89d2472
Implement #4177
vnbaaij 43d5170
Merge branch 'dev-v5' into users/vnbaaij.dev-v5/sync-with-v4-part2
vnbaaij 0dc3ede
- Remove NoTabbing parameter (not being used)
vnbaaij 0f01e2a
Implement #4178
vnbaaij 8d4a54e
Add CustomIcon and IconsExtensions + tests
vnbaaij 6f4285b
Merge branch 'dev-v5' into users/vnbaaij/dev-v5/sync-with-v4-part2
dvoituron File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // ------------------------------------------------------------------------ | ||
| // This file is licensed to you under the MIT License. | ||
| // ------------------------------------------------------------------------ | ||
|
|
||
| namespace Microsoft.FluentUI.AspNetCore.Components; | ||
|
|
||
| /// <summary> | ||
| /// Custom icon loaded from <see cref="IconsExtensions.GetInstance(IconInfo, bool?)"/> | ||
| /// </summary> | ||
| public class CustomIcon : Icon | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="CustomIcon"/> class. | ||
| /// </summary> | ||
| public CustomIcon() | ||
| : base(string.Empty, IconVariant.Regular, IconSize.Size24, string.Empty) | ||
| { } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="CustomIcon"/> class. | ||
| /// </summary> | ||
| /// <param name="icon"></param> | ||
| public CustomIcon(Icon icon) | ||
| : base(icon.Name, icon.Variant, icon.Size, icon.Content) | ||
| { } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| // ------------------------------------------------------------------------ | ||
| // This file is licensed to you under the MIT License. | ||
| // ------------------------------------------------------------------------ | ||
|
|
||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.Reflection; | ||
|
|
||
| namespace Microsoft.FluentUI.AspNetCore.Components; | ||
|
|
||
| /// <summary /> | ||
| public static partial class IconsExtensions | ||
| { | ||
| private const string Namespace = "Microsoft.FluentUI.AspNetCore.Components"; | ||
| private const string LibraryName = "Microsoft.FluentUI.AspNetCore.Components.Icons.{0}"; // {0} must be replaced with the "Variant": Regular, Filled, etc. | ||
|
|
||
| /// <summary> | ||
| /// Returns a new instance of the icon. | ||
| /// </summary> | ||
| /// <param name="icon">The <see cref="IconInfo"/> to instantiate.</param> | ||
| /// <param name="throwOnError">true to throw an exception if the type is not found (default); false to return null.</param> | ||
| /// <remarks> | ||
| /// This method requires dynamic access to code. This code may be removed by the trimmer. | ||
| /// If the assembly is not yet loaded, it will be loaded by the method `Assembly.Load`. | ||
| /// To avoid any issues, the assembly must be loaded before calling this method (e.g. adding an icon in your code). | ||
| /// </remarks> | ||
| /// <returns></returns> | ||
| /// <exception cref="ArgumentException">Raised when the <see cref="IconInfo.Name"/> is not found in predefined icons.</exception> | ||
| [ExcludeFromCodeCoverage(Justification = "We can't test the Icon.* DLLs here")] | ||
| [RequiresUnreferencedCode("This method requires dynamic access to code. This code may be removed by the trimmer.")] | ||
| public static CustomIcon GetInstance(this IconInfo icon, bool? throwOnError = true) | ||
| { | ||
| var assemblyName = string.Format(System.Globalization.CultureInfo.InvariantCulture, LibraryName, icon.Variant); | ||
| var assembly = GetAssembly(assemblyName); | ||
|
|
||
| if (assembly != null) | ||
| { | ||
| var allIcons = assembly.GetTypes().Where(i => i.BaseType == typeof(Icon)); | ||
|
|
||
| // Ex. Microsoft.FluentUI.AspNetCore.Components.Icons.Filled.Size10+PresenceAvailable | ||
| var iconFullName = $"{Namespace}.Icons.{icon.Variant}.Size{(int)icon.Size}+{icon.Name}"; | ||
| var iconType = allIcons.FirstOrDefault(i => string.Equals(i.FullName, iconFullName, StringComparison.InvariantCultureIgnoreCase)); | ||
|
|
||
| if (iconType != null) | ||
| { | ||
| var newIcon = Activator.CreateInstance(iconType); | ||
| if (newIcon != null) | ||
| { | ||
| return new CustomIcon((Icon)newIcon); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (throwOnError == true || throwOnError == null) | ||
| { | ||
| throw new ArgumentException( | ||
| string.Format( | ||
| System.Globalization.CultureInfo.InvariantCulture, | ||
| "Icon 'Icons.{0}.Size{1}.{2}' not found.", | ||
| icon.Variant.ToString(), | ||
| ((int)icon.Size).ToString(System.Globalization.CultureInfo.InvariantCulture), | ||
| icon.Name), | ||
| nameof(icon)); | ||
| } | ||
|
|
||
| return default!; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Tries to return a new instance of the icon. | ||
| /// </summary> | ||
| /// <param name="icon">The <see cref="IconInfo"/> to instantiate.</param> | ||
| /// <param name="result">When this method returns, contains the <see cref="CustomIcon"/> value if the conversion succeeded, or null if the conversion failed. This parameter is passed uninitialized; any value originally supplied in result will be overwritten.</param> | ||
| /// <remarks> | ||
| /// This method requires dynamic access to code. This code may be removed by the trimmer. | ||
| /// If the assembly is not yet loaded, it will be loaded by the method `Assembly.Load`. | ||
| /// To avoid any issues, the assembly must be loaded before calling this method (e.g. adding an icon in your code). | ||
| /// </remarks> | ||
| /// <returns>True if the icon was found and created; otherwise, false.</returns> | ||
| [RequiresUnreferencedCode("This method requires dynamic access to code. This code may be removed by the trimmer.")] | ||
| public static bool TryGetInstance(this IconInfo icon, out CustomIcon? result) | ||
| { | ||
| result = GetInstance(icon, throwOnError: false); | ||
| return result != null; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Returns a new instance of the icon. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This method requires dynamic access to code. This code may be removed by the trimmer. | ||
| /// </remarks> | ||
| /// <returns></returns> | ||
| /// <exception cref="ArgumentException">Raised when the <see cref="IconInfo.Name"/> is not found in predefined icons.</exception> | ||
| [ExcludeFromCodeCoverage(Justification = "We can't test the Icon.* DLLs here.")] | ||
| [RequiresUnreferencedCode("This method requires dynamic access to code. This code may be removed by the trimmer.")] | ||
| public static IEnumerable<IconInfo> GetAllIcons() | ||
| { | ||
| var allIcons = new List<IconInfo>(); | ||
|
|
||
| foreach (var variant in Enum.GetValues(typeof(IconVariant)).Cast<IconVariant>()) | ||
| { | ||
| var assemblyName = string.Format(System.Globalization.CultureInfo.InvariantCulture, LibraryName, variant); | ||
| var assembly = GetAssembly(assemblyName); | ||
|
|
||
| if (assembly != null) | ||
| { | ||
| var allTypes = assembly.GetTypes().Where(i => i.BaseType == typeof(Icon) && !string.Equals(i.Name, nameof(CustomIcon), StringComparison.OrdinalIgnoreCase)); | ||
|
|
||
| allIcons.AddRange(allTypes.Select(type => Activator.CreateInstance(type) as IconInfo ?? new IconInfo())); | ||
| } | ||
| } | ||
|
|
||
| return allIcons; | ||
| } | ||
|
|
||
| /// <summary /> | ||
| public static IEnumerable<IconInfo> AllIcons | ||
| { | ||
| [RequiresUnreferencedCode("This method requires dynamic access to code. This code may be removed by the trimmer.")] | ||
| get | ||
| { | ||
| return GetAllIcons(); | ||
| } | ||
| } | ||
|
|
||
| /// <summary /> | ||
| private static Assembly? GetAssembly(string assemblyName) | ||
| { | ||
| try | ||
| { | ||
| return AppDomain.CurrentDomain | ||
| .GetAssemblies() | ||
| .FirstOrDefault(i => string.Equals(i.ManifestModule.Name, assemblyName + ".dll", StringComparison.OrdinalIgnoreCase)) | ||
| ?? Assembly.Load(assemblyName); | ||
|
|
||
| } | ||
| catch (Exception) | ||
| { | ||
| return null; | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.