2015-01-01から1年間の記事一覧

Equals()のオーバーライド

public class Foo : IEquatable<Foo> { public override bool Equals(object other) { // nullチェック if (object.ReferenceEquals.(other, null)) { return false; } if (object.ReferenceEquals(this, other)) { return true; } if (this.GetType() != other.G</foo>…

プロパティ名を取得する

C#

/// <summary> /// プロパティからプロパティ名を取得する /// 例)public string Name {...} /// というプロパティの場合、"Name"という文字列を返す /// 使い方)下記の様にラムダ式を渡す /// ThisType.GetName(() => (new SameType()).Name); /// </summary> /// <typeparam name="T"></typeparam> /// <param name="e">プ</param>…