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
| public static partial class ExtensionMethods | |
| { | |
| public static bool IsNullOrDefault<T>([NotNullWhen(false)] this T? value) where T : struct | |
| { | |
| //return value == null || value.Equals(default(T)); Simpler, but my research online recommended using EqualityComparer<T>.Default instead of value.Equals | |
| return !value.HasValue || EqualityComparer<T>.Default.Equals(value.Value, default); | |
| } | |
| } |
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
| [GeneratedRegex(@"\{(\d+)\}")] | |
| private static partial Regex FormattableStringArgumentRegex(); | |
| /// <summary> | |
| /// Extension method for combining two <see cref="FormattableString"/>, and returning a new <see cref="FormattableString"/> with the combined arguments and format | |
| /// </summary> | |
| /// <remarks>Originally added to facilitate dynamically building up querystrings that EFCore would take and excute</remarks> | |
| public static FormattableString Combine(this FormattableString baseFormattableString, FormattableString addingFormattableString) | |
| { | |
| var regex = FormattableStringArgumentRegex(); |
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
| public static string? EllipsizeString(this string text, int? maxLength, EllipseStyle ellipseStyle) | |
| { | |
| if (string.IsNullOrEmpty(text)) | |
| return null; | |
| const string ellipsis = "..."; | |
| var preferredCharacters = new[] { ' ', ',', '.', ';', ':', '?', '!' }; | |
| string? truncatedString = null; | |
| if (text?.Length > maxLength) { |
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
| /// <summary> | |
| /// Custom ordering logic for <see cref="SelectListItem"/>s that supports pinning certain | |
| /// <see cref="SelectListGroup"/> names to the top of the list, pushing others to the bottom, | |
| /// and sorting everything else alphabetically in between. | |
| /// </summary> | |
| public class GroupedSelectListItemComparer(IList<string>? prioritizedGroupNames, IList<string>? deprioritizedGroupNames, bool fallbackToText) | |
| : Comparer<SelectListItem> | |
| { | |
| private readonly IList<string>? prioritizedGroupNames = prioritizedGroupNames; | |
| private readonly IList<string>? deprioritizedGroupNames = deprioritizedGroupNames; |
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
| # I use the days since Jan 1, 2000 as part of my build number to mimic a behavior found with .NET Full Framework | |
| # that would autoincrement the 4th piece of the version information based on this math. I started using it as a | |
| # way to reverse enginer the build date at runtime. After switching to .NET Core,I lost this, and start using this | |
| # logic to get that behavior back | |
| # Example build numbers resulting from this... | |
| # 7.0.featurebranch.1+7550 | |
| # 7.0.1+7550 | |
| # Inspiration for the versioning differently between branches | |
| # https://medium.com/@ychetankumarsarma/build-versioning-in-azure-devops-pipelines-94b5a79f80a0 |
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
| [HtmlTargetElement("CollectionItem")] | |
| public class CollectionItemTagHelper : TagHelper | |
| { | |
| private readonly IHtmlHelper htmlHelper; | |
| [ViewContext] | |
| [HtmlAttributeNotBound] | |
| public ViewContext ViewContext { get; set; } | |
| public CollectionItemTagHelper(IHtmlHelper htmlHelper) |
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
| public static class CollectionEditingHtmlExtensions | |
| { | |
| /// <summary> | |
| /// Begins a collection item by inserting a hidden field for the index value | |
| /// </summary> | |
| /// <param name="collectionName">The name of the collection property that owns this item</param> | |
| public static IDisposable BeginCollectionItem<TModel>(this IHtmlHelper<TModel> html, string collectionName) | |
| { | |
| return BeginCollectionItem(html, collectionName, Guid.NewGuid()); | |
| } |
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
| Sample of some files I whipped up to try and demonstrate how to provide a | |
| custom RazorPage to list errors recorded in StackExchange's Exceptional |
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
| /* | |
| References (F4 - Additional References - Add...) | |
| ~~~~~~~~~~~~~~~~~~~ | |
| <Your AspNetCore site assembly> | |
| * Check Reference ASP.NET Core | |
| Using (F4 - Additional Namespace Imports) | |
| ~~~~~~~~~~~~~~~~~~~ | |
| Microsoft.AspNetCore.Hosting | |
| Microsoft.Extensions.Configuration |
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
| using System.ComponentModel.DataAnnotations; | |
| using Intellitive.AspNetCore.Validators; | |
| using Microsoft.AspNetCore.Mvc.DataAnnotations; | |
| using Microsoft.Extensions.Localization; | |
| /// <summary> | |
| /// Provider for wiring up support of client side validation for <see cref="RequireNonDefaultAttribute"/> via <see cref="RequireNonDefaultAttributeAdapter"/> | |
| /// </summary> | |
| public class ValidationAttributeAdapterProvider : IValidationAttributeAdapterProvider | |
| { |
NewerOlder