Skip to content

Instantly share code, notes, and snippets.

@foyzulkarim
Created February 4, 2018 18:15
Show Gist options
  • Save foyzulkarim/e9fff4a589b9ef1dfaab49ee31bfe343 to your computer and use it in GitHub Desktop.
Save foyzulkarim/e9fff4a589b9ef1dfaab49ee31bfe343 to your computer and use it in GitHub Desktop.
Create default instance of the provided type
public class BaseReportService
{
protected T CreateDefault<T>(Type t, string shopId) where T : BaseReport
{
var report = Activator.CreateInstance(t) as BaseReport;
report.Id = Guid.NewGuid().ToString();
report.Created = DateTime.Now;
report.Modified = DateTime.Now;
report.CreatedBy = "System";
report.ModifiedBy = "System";
report.CreatedFrom = "System";
report.IsActive = true;
report.Value = report.Created.Date.ToString("dd/MM/yyyy");
report.Date = report.Created.Date;
report.RowsCount = 0;
report.ShopId = shopId;
return report as T;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment