Skip to content

Instantly share code, notes, and snippets.

View enisn's full-sized avatar

Enis Necipoglu enisn

View GitHub Profile
@enisn
enisn / Range{T}.cs
Created April 16, 2020 20:13
Challenge #1 - Solution 2 - Range{T}.cs
public partial class Range<T> : IRange<T>, IEquatable<string>, IFormattable
where T : struct, IComparable
{
public Range()
{
}
public Range(string value)
{
var parsed = Parse<T>(value);
@enisn
enisn / ProductFilter.cs
Created April 16, 2020 20:22
Challenge #1 - Solution 2 - ProductFilter.cs
public class ProductFilter : FilterBase
{
[StringFilterOptions(StringFilterOption.Contains)]
public string Name { get; set; }
[StringFilterOptions(StringFilterOption.Contains)]
public string Description { get; set; }
public string Code { get; set; }
@enisn
enisn / ProductsController.cs
Created April 16, 2020 20:24
Challenge #1 - Solution 2 - ProductsController
public class ProductsController
{
private readonly MyDbContext context
public ProductsController(MyDbContext context)
{
this.context = context;
}
[HttpGet]
public async Task<IActionResult> GetAsync([FromQuery]ProductFilter filter)
@enisn
enisn / QueryExtensions.cs
Created April 16, 2020 20:27
Challenge #1 - Solution 2 - QueryExtensions.cs
public static class QueryExtensions
{
public static IQueryable<T> ApplyFilter<T>(this IQueryable<T> source, IFilter filter)
{
return filter.ApplyFilterTo(source);
}
public static IQueryable<T> ApplyFilter<T>(this IOrderedQueryable<T> source, IFilter filter)
{
return filter.ApplyFilterTo(source);
@enisn
enisn / ProductsController.cs
Created April 16, 2020 20:31
Challenge #1 - Solution 2 - ProductsController.cs Fluent usage
public class ProductsController
{
private readonly MyDbContext context
public ProductsController(MyDbContext context)
{
this.context = context;
}
[HttpGet]
public async Task<IActionResult> GetAsync([FromQuery]ProductFilter filter)
@enisn
enisn / StringBinding.cs
Last active May 7, 2020 19:50
Challenge #2 - (+) operator - sample 1
var message = "Welcome back " + user.Name + ". You're authenticated as " + user.Email;
@enisn
enisn / StringBinding.cs
Created May 7, 2020 19:50
Challenge #2 - String Interpolation - sample 2
var message = $"Welcome back {user.Email}. You're authenticated as {user.Email}";
@enisn
enisn / StringBinding.cs
Created May 7, 2020 19:53
Challenge #2 - Format- sample 3
var message = string.Format("Welcome back {0}. You're authenticated as {1}", user.Name, user.Email);
@enisn
enisn / StringBinding.cs
Last active May 7, 2020 20:09
Challenge #2 - Problem - 1
// The data which comes from db or something else.
var user = new User { Name = "Enis", Email= "[email protected]" };
// The string template which comes from database or anywhere else:
var template = "Welcome back {Name}. You're authenticated as {Email}."
// Output: Welcome back Enis. You're authenticated as [email protected].
var message = template.Bind(user);
@enisn
enisn / SttringBinding.cs
Last active May 7, 2020 20:13
Challenge #2 - Problem - 2
var data = new User { Name = "Enis", Email = "[email protected]" }
var template = "<h1>Welcome back <strong>{Name}</strong></h1><p>You're authenticated as <a href=\"mailto:{Email}\"></a></p>";
var message = template.Bind(data);