Skip to content

Instantly share code, notes, and snippets.

View NDiiong's full-sized avatar
😀
Hi there!

duong.nb NDiiong

😀
Hi there!
View GitHub Profile
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))
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)
{
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);

Some of the Redis best practices content has moved

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.

NOTE: Client specific guidance listed below is still valid and should still be considered. I will update this document once all content has been moved.

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;
using OfficeOpenXml;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
namespace File.Excel.Extensions
{
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;
using Azure;
using Azure.Storage.Files.Shares;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace AzureFileShare
public class AzureBlobFileClient : IFileClient
{
private CloudBlobClient _blobClient;
public AzureBlobFileClient(string connectionString)
{
var account = CloudStorageAccount.Parse(connectionString);
_blobClient = account.CreateCloudBlobClient();
}
@NDiiong
NDiiong / TypeExtension.cs
Created February 4, 2021 10:35
GetAnyElementType
public static class TypeExtension
{
/// <summary>
///
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public static Type GetAnyElementType(this Type type)
{
// Type is Array