-
-
Save sonoichi60/ed87db93b5c91a0c847505aa4e57f6d0 to your computer and use it in GitHub Desktop.
example ConstructorInfo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 引数なしコンストラクタの取得 | |
var constructor = typeof(TestClass).GetConstructor(new Type[0]); | |
// int のみ引数に取るコンストラクタの取得 | |
var constructor1 = typeof(TestClass).GetConstructor(new Type[] { typeof(int) }); | |
// コンストラクタの全取得 | |
var constructers = typeof(TestClass).GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); | |
var parametors = constructor.GetParameters(); // 引数情報 | |
// 引数なしコンストラクタを呼び、インスタンスを作成 | |
var instance = (TestClass)constructor.Invoke(new Type[0]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment