This content from this markdown file has moved a new, happier home where it can serve more people. Please check it out : https://docs.microsoft.com/azure/azure-cache-for-redis/cache-best-practices.
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
public static T To<T>(this object obj) | |
where T : struct | |
{ | |
if (typeof(T) == typeof(Guid) || typeof(T) == typeof(TimeSpan)) | |
{ | |
return (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFromInvariantString(obj.ToString()); | |
} | |
if (typeof(T).IsEnum) | |
{ | |
if (Enum.IsDefined(typeof(T), obj)) |
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
public static void AddAny(this IServiceCollection collection, Assembly assembly, Func<Type, bool> implementFactory, ServiceLifetime serviceLifetime) | |
{ | |
var serviceTypes = assembly.GetTypes() | |
.Where(x => !x.IsAbstract && x.GetInterfaces().Any(IsAnyServiceInterface)) | |
.ToList(); | |
serviceTypes.ForEach(x => AddService(collection, x)); | |
bool IsAnyServiceInterface(Type type) | |
{ |
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
public static class ParseExtension | |
{ | |
private static CultureInfo _cultureInfo = CultureInfo.CurrentCulture; | |
public static T As<T>(this object value) | |
{ | |
var toType = typeof(T); | |
if (value == null) return default(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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Runtime.InteropServices; | |
using System.Runtime.InteropServices.ComTypes; | |
using System.Threading; | |
using System.Threading.Tasks; | |
using EnvDTE80; | |
using EnvDTE90a; |
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
using OfficeOpenXml; | |
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Reflection; | |
namespace File.Excel.Extensions | |
{ |
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
public class DbContextHealthCheck : IHealthCheck | |
{ | |
private readonly Func<string, DataContext> _dbContext; | |
private readonly List<ConsolidatorSettings> _consolidatorSettings; | |
public DbContextHealthCheck(Func<string, DataContext> dbContext, IOptions<List<ConsolidatorSettings>> consolidatorSettings) | |
{ | |
_dbContext = dbContext; | |
_consolidatorSettings = consolidatorSettings.Value; |
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
public class AzureBlobFileClient : IFileClient | |
{ | |
private CloudBlobClient _blobClient; | |
public AzureBlobFileClient(string connectionString) | |
{ | |
var account = CloudStorageAccount.Parse(connectionString); | |
_blobClient = account.CreateCloudBlobClient(); | |
} | |
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
public static class TypeExtension | |
{ | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="type"></param> | |
/// <returns></returns> | |
public static Type GetAnyElementType(this Type type) | |
{ | |
// Type is Array |