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

更新


公開メモ

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

ArrayInt32IntPtrVoid*DecimalTest1EnumTest2StringArrayInt32[]Test3
Abstract×××××○××○××
Array×××××××××○×
AutoLayout××○××○○○○○○
Class××○××××○○○○
Enum××××××○××××
LayoutSequential○○×○○××××××
Nested××××○×○×××○
NestedPublic××××○×○×××○
NotPublic××○××××××××
Pointer××○××××××××
Primitive○○×××××××××
Public○○×○×○×○○○×
Sealed○○×○○×○○×○×
Serializable○○×○×○○○○○×
ValueType○○×○○×○××××
SubclassOf(typeof(ValueType))○○×○○○○××××

ちなみに、

LANGUAGE:C#
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 などについて†

NestedNested AssemblyNested FamANDAssemNested FamilyNested FamORAssemNested PrivateNested PublicNotPublicPublic
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○×××○××××

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

LANGUAGE:C#
   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 になる。

コメント†





Counter: 5819 (from 2010/06/03), today: 1, yesterday: 1