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
// Implementation | |
private const int DEFAULT_RETENTION = 60; | |
public static T Eval<T>(this IMemoryCache cache, string key, Func<T> expression) | |
=> Eval(cache, key, DEFAULT_RETENTION, expression); | |
public static T Eval<T>(this IMemoryCache cache, string key, int retentionMinutes, Func<T> expression) | |
{ | |
T val; | |
if (!cache.TryGetValue<T>(key, out val)) |
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 MergeEntityListToDB<T>(List<T> list) where T : class | |
{ | |
if (list.Count == 0) | |
throw new Exception("No records to update in list."); | |
var db = new DataBaseEntities(); // Whatever you named your EF DB context in ADO.NET | |
// Get Property Info of Entity Type | |
var propertyInfo = db.GetType().GetProperties().Where(x => x.PropertyType == typeof(DbSet<T>)).FirstOrDefault(); | |
if (propertyInfo == null) |
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 ExecuteMethod(string MethodName, Type ClassType = null) | |
{ | |
if (string.IsNullOrWhiteSpace(MethodName)) | |
throw new Exception("First argument must contain the target method name."); | |
if (ClassType == null) | |
ClassType = new StackFrame().GetMethod().DeclaringType; | |
var methodInfo = ClassType.GetMethods().Where(x => x.Name.ToLower() == MethodName.ToLower()).FirstOrDefault(); | |
if (methodInfo == null) |
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 List<T> DataTableToEntityList<T>(DataTable dt) | |
{ | |
Logging.Info("Converting datatable to entity list"); | |
foreach (DataColumn column in dt.Columns) | |
{ | |
dt.Columns[column.ColumnName].ColumnName = column.ColumnName.Replace(" ", "").Replace("-", "").ToLower(); | |
} | |
var list = new List<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
public static DataTable ExcelToDataTable(string FileName) | |
{ | |
Logging.Info("Reading Excel file to datatable: " + FileName); | |
var ds = new DataSet(); | |
using (var stream = File.Open(FileName, FileMode.Open, FileAccess.Read)) | |
{ | |
using (var reader = ExcelReaderFactory.CreateReader(stream)) | |
{ |