クラス名から文字列としてカスタム属性を取得することは可能ですか?
このようなもの(これは機能しません)
Type myType = Type.GetType("MyClass");
MemberInfo info = myType // typeof(myType);
object[] atts = info.GetCustomAttributes(true);
クラス名から文字列としてカスタム属性を取得することは可能ですか?
このようなもの(これは機能しません)
Type myType = Type.GetType("MyClass");
MemberInfo info = myType // typeof(myType);
object[] atts = info.GetCustomAttributes(true);
あなたはほとんどそこにいます。名前空間がありませんでした。
Type myType = Type.GetType("System.String");
object[] atts = myType.GetCustomAttributes(true);
あなたの場合
Type myType = Type.GetType("YourNameSpace.MyClass");//this should work
詳細については、 Type.GetTypeを参照してください
var asnames = Assembly.GetExecutingAssembly().GetReferencedAssemblies();
var asmname = asnames.FirstOrDefault(x => x.Name == assemName);
Assembly.Load(asmname);
上記のコードを使用して、アセンブリをプリロードします (参照アセンブリに存在する場合)。
もうすぐそこにいるようです。
使用する object[] atts = Type.GetType("MyNamesapce.MyClass").GetCustomAttributes(true);
私のために完璧に働いた
名前空間について言及し忘れたのではないでしょうか?
http://msdn.microsoft.com/en-us/library/system.attribute.getcustomattributes.aspx を確認してください