プログラミング/C#/型のプロパティ のバックアップ差分(No.3)

更新


  • 追加された行はこの色です。
  • 削除された行はこの色です。
[[公開メモ]]

* typeof(XXX).Is???? の結果 [#b2ac63c3]

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

ちなみに、

 LANGUAGE:C#
 namespace TestNameSpace
 {
     class Test
     {
         public struct Test1 { }
         public enum Test2 { abc }
         public class Test3 { }
     }
 }

とした。

* 覚え書き [#d2b22d19]

まず、

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 などについて [#l4849f3d]

|	|	|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 になる。


* コメント [#x238ba0e]

#article_kcaptcha
**kSEhNsmYIJP [#r4d308ef]
>[Misa] (2013-01-04 (金) 02:01:42)~
~
Alright alirhgt alright that's exactly what I needed!~

//

#comment_kcaptcha



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