Skip to content

Instantly share code, notes, and snippets.

@ichiroku11
ichiroku11 / gist:3858020
Created October 9, 2012 11:11
HashSet<T>のメソッドの使い方
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp {
class Program {
static void Main( string[] args ) {
var items = new HashSet<int> { 0, 1, 2, 3, 4, };
// otherが同じ要素を含んでいるかどうか
@ichiroku11
ichiroku11 / gist:3992735
Created November 1, 2012 09:37
指定DBを指定フォルダにバックアップするクエリ
/*
指定DBを指定フォルダにバックアップ
バックアップファイル名には日付の文字列が含まれる
*/
declare @dbName sysname = N'DB名';
declare @folder nvarchar( max ) = N'バックアップフォルダ(\で終わる必要あり)';
declare @date datetime = getdate();
declare @ymd char( 8 ) = convert( char( 8 ), @date, 112 ); -- yymmdd
declare @hms char( 6 ) = replace( convert( char( 8 ), @date, 108 ), ':', '' ); -- hh:mm:ss -> hhmmss
@ichiroku11
ichiroku11 / Program.cs
Created November 29, 2012 14:55
enumに適用されている属性を取得
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
namespace ConsoleApp {
public static class EnumExtensions {
// enumに適用されている属性を取得
public static IEnumerable<TAttribute> GetApplied<TAttribute>(this Enum value) where TAttribute : Attribute {
@ichiroku11
ichiroku11 / gist:4750015
Last active December 12, 2015 09:18
dapper dot net を試す
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dapper;
namespace ConsoleApp {
@ichiroku11
ichiroku11 / gist:4986739
Created February 19, 2013 15:13
SQL Serverデータ型からCLRデータ型へのマッピングを試す http://msdn.microsoft.com/ja-jp/library/ms131092.aspx
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace ConsoleApp {
class Program {
private static SqlConnection Connect() {
@ichiroku11
ichiroku11 / Test.cs
Last active December 14, 2015 07:09
case式を使って条件分岐するupdate文を試す (ドラッグ&ドロップで並び替えする際のデータの更新を1つのupdate文で)
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Dapper;
namespace UnitTest {
public static class AssertHelper {
public static void IsSequenceEqualTo<T>(this IEnumerable<T> first, IEnumerable<T> second) {
@ichiroku11
ichiroku11 / SampleHttpHandler.cs
Created March 19, 2013 13:14
カスタムHTTPハンドラーとカスタムHTTPモジュールの作成・登録
using System;
using System.Web;
namespace WebApp.App_Code {
public class SampleHttpHandler : IHttpHandler {
public bool IsReusable {
get { return false; }
}
public void ProcessRequest(HttpContext context) {
@ichiroku11
ichiroku11 / gist:5254660
Created March 27, 2013 14:37
Json.NETでプロパティ名を変更してシリアライズ・デシリアライズ(JsonPropertyAttribute)
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
namespace ConsoleApp {
class User {
[JsonProperty("first_name")]
@ichiroku11
ichiroku11 / gist:5254747
Created March 27, 2013 14:47
Json.NETでプロパティ名をCamel形式にしてシリアライズ(CamelCasePropertyNamesContractResolver)
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
namespace ConsoleApp {
class User {
@ichiroku11
ichiroku11 / gist:5326534
Created April 6, 2013 15:41
トリガーで時間帯の重なりを防ぐ (独自の制約のようなものを作る)
using System;
using System.Data.SqlClient;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Dapper;
namespace UnitTest {
[TestClass]
public class Test {
private readonly string _connectionString =