履歴: プログラミング/C#/型のプロパティ

各行は、その日時に書かれた内容です。追加・削除は、1 つ前の版との行数の差です (全 5 版)。「差分」は比較する版、「基準」は比べる相手の版を選びます

日時タイトル文字数追加削除内容差分基準
2013/1/4 10:05:38プログラミング/C#/型のプロパティ 最新版3,532+1 -1表示差分—
2013/1/4 10:05:38プログラミング/C#/型のプロパティ 3,538+0 -9表示差分選択
2013/1/3 17:01:42プログラミング/C#/型のプロパティ 3,680+9 -0表示差分選択
2009/8/30 11:02:41プログラミング/C#/型のプロパティ 3,538+97 -15表示中差分選択
2009/8/30 10:17:45プログラミング/C#/型のプロパティ 888— —表示—選択

2009/8/30 11:02:41 に書かれた内容

プログラミング/C#/型のプロパティ


公開メモ

typeof(XXX).Is???? の結果†

Array Int32 IntPtr Void* Decimal Test1 Enum Test2 String Array Int32[] Test3
Abstract × × × × × ○ × × ○ × ×
Array × × × × × × × × × ○ ×
AutoLayout × × ○ × × ○ ○ ○ ○ ○ ○
Class × × ○ × × × × ○ ○ ○ ○
Enum × × × × × × ○ × × × ×
LayoutSequential ○ ○ × ○ ○ × × × × × ×
Nested × × × × ○ × ○ × × × ○
NestedPublic × × × × ○ × ○ × × × ○
NotPublic × × ○ × × × × × × × ×
Pointer × × ○ × × × × × × × ×
Primitive ○ ○ × × × × × × × × ×
Public ○ ○ × ○ × ○ × ○ ○ ○ ×
Sealed ○ ○ × ○ ○ × ○ ○ × ○ ×
Serializable ○ ○ × ○ × ○ ○ ○ ○ ○ ×
ValueType ○ ○ × ○ ○ × ○ × × × ×
SubclassOf(typeof(ValueType)) ○ ○ × ○ ○ ○ ○ × × × ×

ちなみに、

namespace TestNameSpace
{
    class Test
    {
        public struct Test1 { }
        public enum Test2 { abc }
        public class Test3 { }
    }
}

とした。

覚え書き†

まず、

bool
char
数値型(sbyte, byte, short, ushort, int, uint, long, ulong, float, double)
IntPtr

は Primitive として、同じ扱いを受ける。

IntPtr が Primitive, !IsPointer, ValueType, Serializable であるのは想像しづらい。

void* は !Primitive, IsPointer, !ValueType, !Serializable である。

さらに void* は IsClass なので、class のみを扱いたければ IsPointer を見て先に除かないといけない。

string, int[] にも IsClass がついているので、これらも特別扱いが必要。

IsPublic は普通に思い浮かべる public かどうかではない。

IsPublic などについて†

Nested Nested Assembly Nested FamANDAssem Nested Family Nested FamORAssem Nested Private Nested Public NotPublic Public
Public × × × × × × × × ○
Public+Public_ ○ × × × × × ○ × ×
Public+Private ○ × × × × ○ × × ×
Public+Private+Public ○ × × × × × ○ × ×
Public+Protected ○ × × ○ × × × × ×
Public+Internal ○ ○ × × × × × × ×
Public+ProtectedInternal ○ × × × ○ × × × ×
Internal × × × × × × × ○ ×
Internal+Public ○ × × × × × ○ × ×
Internal+Private ○ × × × × ○ × × ×
Internal+Private+Public ○ × × × × × ○ × ×
Internal+Protected ○ × × ○ × × × × ×
Internal+Internal_ ○ ○ × × × × × × ×
Internal+ProtectedInternal ○ × × × ○ × × × ×

各クラスの定義は以下の通り。

   public class Public
   {
       public static Type GetPrivate() { return typeof(Private); }
       public static Type GetPrivatePublic() { return typeof(Private.Public); }
       public static Type GetProtected() { return typeof(Protected); }
       public class Public_ { }
       private class Private { public class Public { } }
       protected class Protected { }
       internal class Internal { }
       protected internal class ProtectedInternal { }
   }
   internal class Internal
   {
       public static Type GetPrivate() { return typeof(Private); }
       public static Type GetProtected() { return typeof(Protected); }
       public static Type GetPrivatePublic() { return typeof(Private.Public); }
       public class Public { }
       private class Private { public class Public { } }
       protected class Protected { }
       internal class Internal_ { }
       protected internal class ProtectedInternal { }
   }

IsNested なクラスについては、IsNestedXXX を見ることで、自身に付けられた修飾子を得ることができる。

!IsNested なクラスについては、NotPublic か Public を見ることで、internal か public かが分かる。 何も付けなければ internal になる。

コメント†