プログラミング/C#/型のプロパティ の履歴(No.3)
更新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)) | ○ | ○ | × | ○ | ○ | ○ | ○ | × | × | × | × |
ちなみに、
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 などについて†
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 | ○ | × | × | × | ○ | × | × | × | × |
各クラスの定義は以下の通り。
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 になる。
コメント†
kSEhNsmYIJP†
[Misa] (2013-01-04 (金) 02:01:42)
Alright alirhgt alright that's exactly what I needed!
Counter: 5409 (from 2010/06/03),
today: 1,
yesterday: 0