Skip to content

Instantly share code, notes, and snippets.

public class EnumDescriptionAttribute : Attribute
{
public Type ResourceType { get; set; }
public EnumDescriptionAttribute(Type resourceType)
{
ResourceType = resourceType;
}
}
@danielplawgo
danielplawgo / Program1.cs
Created July 9, 2018 05:42
Używanie napisów w aplikacji
//użycie bezpośrednie napisu
var applicationName = ConfigurationManager.AppSettings["ApplicationName"];
//skorzystanie z stałej
var applicationName = ConfigurationManager.AppSettings[SettingsNames.ApplicationName];
@danielplawgo
danielplawgo / EnumExtensions1.cs
Created July 21, 2018 04:30
Jak zmierzyć wydajność kodu .NET? BenchmarkDotNet
public static string ToDisplayString(this Enum value)
{
if (value == null)
{
throw new ArgumentNullException("value");
}
string description = value.ToString();
EnumDescriptionAttribute[] attributes = (EnumDescriptionAttribute[])value.GetType().GetCustomAttributes(typeof(EnumDescriptionAttribute), false);
@danielplawgo
danielplawgo / Benchmarks1.cs
Created July 26, 2018 04:14
Jeden czy wiele plików resource, a wydajność
public class Benchmarks
{
[Benchmark]
public void UsingResources()
{
var test = Resources.One;
}
}
public class BaseModel
{
public BaseModel()
{
IsActive = true;
}
public int Id { get; set; }
public bool IsActive { get; set; }
@danielplawgo
danielplawgo / Products1Controller.cs
Created August 12, 2018 08:56
Jak zmienić generowanie kodu w ASP.NET MVC?
public class Products1Controller : Controller
{
private DataContext db = new DataContext();
// GET: /Products1/
public ActionResult Index()
{
return View(db.Products.ToList());
}
@danielplawgo
danielplawgo / DateService.cs
Last active August 21, 2018 04:58
Jak automatycznie zmieniać czas lokalny na UTC w ASP.NET MVC?
public class DateService : IDateService
{
public DateTime ConvertToUtc(DateTime dateTime)
{
TimeZoneInfo timeZone = TimeZoneInfo.FindSystemTimeZoneById(GetTimezone());
var date = DateTime.SpecifyKind(dateTime, DateTimeKind.Unspecified);
return TimeZoneInfo.ConvertTimeToUtc(date, timeZone);
}
public DateTime ConvertToLocal(DateTime dateTime)
@danielplawgo
danielplawgo / CacheService.cs
Created August 27, 2018 13:01
Jak cachować dane w .NET? Kilka słów o CacheManager oraz Redis
public class CacheService : ICacheService
{
private ICacheManager<object> _cache;
private const string _defaultCacheName = "defaultCache";
public CacheService()
{
var builder = ConfigurationBuilder.LoadConfiguration(_defaultCacheName).Builder;
builder.WithMicrosoftLogging(s => s.AddNLog());
@danielplawgo
danielplawgo / Program.cs
Created September 2, 2018 04:16
Jak ponawiać operacje w .NET z wykorzystaniem Polly?
class Program
{
private static NLog.Logger _logger = NLog.LogManager.GetCurrentClassLogger();
static void Main(string[] args)
{
_logger.Info("Start");
try
{
var content = Download("http://plawgo.pl");
public class CategoriesController : Controller
{
private Lazy<ICategoryRepository> _categoryRepository;
protected ICategoryRepository CategoryRepository
{
get { return _categoryRepository.Value; }
}
private Lazy<IMapper> _mapper;