Skip to content

Instantly share code, notes, and snippets.

View cz75hiro's full-sized avatar

cz75hiro cz75hiro

  • Personal
  • Fukuoka, Japan
View GitHub Profile
@cz75hiro
cz75hiro / GetAttributes.cs
Last active December 13, 2015 21:18
ラムダ式で指定したプロパティの属性を取得するサンプル
static class Program
{
static void Main(string[] args)
{
var test = new Test();
Console.WriteLine(test.GetFugaString(x => x.TestProperty));
Console.Read();
}
public static string GetFugaString<TSource, TSelector>(this TSource source, Expression<Func<TSource, TSelector>> propertyExpression) where TSource : class
@cz75hiro
cz75hiro / gist:805336
Created February 1, 2011 02:58
インデクサにデリゲート
using System;
using System.Collections.ObjectModel;
using System.Linq;
namespace インデクサにデリゲート {
class Program {
static void Main(string[] args) {
SampleCollection sample = SampleCollection.My;
sample.Add(new Hoge() { ID = 1, Name = "A" });
sample.Add(new Hoge() { ID = 2, Name = "B" });
@cz75hiro
cz75hiro / gist:787734
Created January 20, 2011 11:00
Selectで実行時エラー
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Linqメソッドで遊ぶ
{
class Program
{
static void Main(string[] args)
@cz75hiro
cz75hiro / IEnumerable<>.Union
Created January 20, 2011 10:12
Linqメソッドで遊ぶ 例外
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Linqメソッドで遊ぶ
{
class Program
{
static void Main(string[] args)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Linqメソッドで遊ぶ
{
class Program
{
static void Main(string[] args)
@cz75hiro
cz75hiro / gist:735906
Created December 10, 2010 07:25
Enumに柔軟な拡張を追加する試み
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
namespace Enumに柔軟な拡張を追加する試み {
class Program {
enum tesyEnum {
[Obsolete]
@cz75hiro
cz75hiro / gist:722954
Created December 1, 2010 04:34
参照型のパラメータの渡し方の違い
class Program{
static void Main(string[] args){
//参照型の値渡し
TestClass t1 = new TestClass();
TestClass t2 = ValMethod(t1);
Console.WriteLine(t1 == t2);//false
//参照型の参照渡し
TestClass t3 = new TestClass();
@cz75hiro
cz75hiro / gist:593478
Created September 23, 2010 11:08
Genericの間違えた使い方
interface IData //データインターフェース
{
}
public abstract class SchemaBase//DBスキーマ抽象クラス
{
public SchemaBase() { }
}
public abstract class DAOBase<TSchema, TData>//DAOパターン抽象クラス
interface IData //データインターフェース
{
}
public abstract class SchemaBase//DBスキーマ抽象クラス
{
public SchemaBase() { }
}
public abstract class DAOBase<TSchema, TData>//DAOパターン抽象クラス
class Program
{
[STAThread]
static void Main(string[] args)
{
TestFlag f = TestFlag.b | TestFlag.d; //bとdにフラグを立てる
Console.WriteLine("{0}", f.HasFlag(TestFlag.a));
Console.WriteLine("{0}", f.HasFlag(TestFlag.b));
Console.WriteLine("{0}", f.HasFlag(TestFlag.c));