-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Updated LoggerWebApplicationBuilderExtensions.cs: Modified the configureApplicationInsightsLoggerOptions method. - Updated Dgmjr.System.Extensions.csproj: Added a package reference to system.ComponentModel.Annotations. - Updated EnumExtensions.cs: Added new methods for getting field info, custom attribute, short name, display name, and order. - Added Enums.cs: Added a new file with methods for getting enum values and parsing enum strings. - Added ObjectExtensions.cs: Added new extension methods for working with assembly resources and getting property values.
- Loading branch information
Showing
5 changed files
with
74 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,15 @@ | ||
namespace System; | ||
|
||
public static class Enums | ||
{ | ||
public static T[] GetValues<T>() | ||
where T : Enum | ||
{ | ||
return Enum.GetValues(typeof(T)).OfType<T>().ToArray(); | ||
} | ||
public static T Parse<T>(string s) | ||
where T : Enum | ||
{ | ||
return Enum.Parse(typeof(T), s, true).To<T>(); | ||
} | ||
} |
This file contains 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,27 @@ | ||
namespace System; | ||
|
||
public static class ObjectExtensions | ||
{ | ||
public static Stream GetManifestResourceStream<T>(this T _, string resourceName) | ||
=> typeof(T).Assembly.GetManifestResourceStream(resourceName); | ||
public static byte[] GetManifestResourceBytes<T>(this T _, string resourceName) | ||
=> typeof(T).Assembly.GetManifestResourceStream(resourceName).ReadAllBytes(); | ||
public static async Task<byte[]> GetManifestResourceBytesAsync<T>(this T _, string resourceName) | ||
=> await typeof(T).Assembly.GetManifestResourceStream(resourceName).ReadAllBytesAsync(); | ||
public static string ReadAssemblyResourceAllText<T>(this T _, string resourceName) | ||
=> Extensions.ReadAssemblyResourceAllText(typeof(T).Assembly, resourceName); | ||
public static async Task<string> ReadAssemblyResourceAllTextAsync<T>(this T _, string resourceName) | ||
=> await Extensions.ReadAssemblyResourceAllTextAsync(typeof(T).Assembly, resourceName); | ||
|
||
public static T To<T>(this object value) | ||
=> (T)Convert.ChangeType(value, typeof(T)); | ||
|
||
public static object? GetPropertyValue(this object obj, string propertyName) | ||
{ | ||
return obj.GetType().GetRuntimeProperties().FirstOrDefault(pi => pi.Name.Equals(propertyName, OrdinalIgnoreCase))?.GetValue(obj); | ||
} | ||
public static T? GetPropertyValue<T>(this object obj, string propertyName) | ||
{ | ||
return (T?)obj.GetType().GetRuntimeProperties().FirstOrDefault(pi => pi.Name.Equals(propertyName, OrdinalIgnoreCase))?.GetValue(obj); | ||
} | ||
} |