Skip to content

Instantly share code, notes, and snippets.

View bezzad's full-sized avatar
:octocat:
Hi

Behzad Khosravifar bezzad

:octocat:
Hi
View GitHub Profile
@bezzad
bezzad / VersionUpdater.tt
Created July 18, 2016 13:06
Auto .net project version updater by TextTemplete (.tt)
<#@ template language="C#" hostspecific="true" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Text.RegularExpressions" #>
<#@ output extension=".txt" #>
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
@bezzad
bezzad / NumericTextBox.cs
Last active August 30, 2016 08:08
C#.Net Numeric TextBox by thousand separator like: 123,456,789
public class NumericTextBox : TextBox
{
private const char Delete = (char)8;
private const char Backspace = '\b';
public bool IsNumeric { get; set; } = false;
public new string Text
{
get { return IsNumeric ? base.Text?.Replace(",", "") : base.Text; }
@bezzad
bezzad / Bundle Extension
Last active December 29, 2016 05:46 — forked from deanhume/Bundle Extension
An ASP.NET MVC bundle extension file to handle optional HTML attributes such as async, defer, and media for CSS links.
namespace Optimization.Custom
{
using System.Collections.Generic;
using System.Web;
using System.Text;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
/// <summary>
@bezzad
bezzad / VSSolutionInspection.tt
Created January 9, 2017 12:30 — forked from cairey/VSSolutionInspection.tt
Inspect the Visual Studio solution and project settings using T4 template code gen.
<#@ template language="C#" debug="true" hostSpecific="true" #>
<#@ output extension=".cs" #>
<#@ Assembly Name="System.Core.dll" #>
<#@ assembly name="EnvDTE" #>
<#@ Assembly Name="System.Windows.Forms.dll" #>
<#@ Assembly name="System.Configuration"#>
<#@ import namespace="System" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Diagnostics" #>
<#@ import namespace="System.Linq" #>
@bezzad
bezzad / DataTableExtensions.cs
Last active April 23, 2017 12:56
Extension methods for convert `DataTable` to any other types like: Generic Type `T` , dynamic object
public static class Extension
{
public static IList<T> ToList<T>(this DataTable dt, bool isFirstRowColumnsHeader = false) where T : new()
{
var results = new List<T>();
if (dt != null && dt.Rows.Count > 0)
{
var columns = dt.Columns.Cast<DataColumn>().ToList();
var rows = dt.Rows.Cast<DataRow>().ToList();
@bezzad
bezzad / AsyncHelper.cs
Last active May 30, 2018 10:03
Run an async Task<T> method synchronously
public static class AsyncHelper
{
/// <summary>
/// Execute's an async Task method which has a void return value synchronously
/// </summary>
/// <param name="task">Task method to execute</param>
public static void RunSync(this Func<Task> task)
{
var oldContext = SynchronizationContext.Current;
var synch = new ExclusiveSynchronizationContext();
@bezzad
bezzad / ObservableConcurrentDictionary.cs
Last active July 22, 2018 10:30
Provides a thread-safe dictionary for use with data binding.
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Threading;
namespace System.Collections.Generic
{
/// <summary>
@bezzad
bezzad / StartIIS.cs
Created July 22, 2018 10:32
Programmatically start IIS Express from code.
public static class IISExpress
{
private static readonly List<string> sites = new List<string>();
private static readonly List<string> paths = new List<string>();
public static void StartIISExpress(string site, int port = 7329)
{
if(!sites.Contains(site.ToLower()))
sites.Add(site.ToLower());
else return;
@bezzad
bezzad / animation-using-angularjs-ui-router-and-nganimate.markdown
Last active November 10, 2018 08:16
Animation using AngularJS ui-router and ngAnimate

Animation using AngularJS ui-router and ngAnimate

Feel free to use this code if you are using AngularJS Framework in your application. This will help you easily create beautiful animated wizards or cover other UI scenarios that require a step-by-step interactions. Better used for single-page apps.

A Pen by Behzad Khosravifar on CodePen.

License.

@bezzad
bezzad / AspMvcCamelCaseJson
Created October 22, 2019 06:32
Return JSON data in a camelCase format from an ASP.NET WebAPI controller.
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);