के लिए सभी वर्गों और विधियों को स्कैन करने के लिए सर्वोत्तम प्रथाएं पहली बार मुझे वास्तव में मैन्युअल रूप से स्कैनिंग करने की आवश्यकता होती है। मैं जो मुझेकस्टम विशेषता
var typesWithMyAttribute =
(from assembly in AppDomain.CurrentDomain.GetAssemblies()
from type in assembly.GetTypes()
let attributes = type.GetCustomAttributes(typeof(SomeAttribute), true)
where attributes != null && attributes.Length > 0
select new { Type = type, Attributes = attributes.Cast<SomeAttribute>() })
.ToList();
कौन सा काफी सरल विधि के स्तर के लिए बाहर का विस्तार करने के लिए था के साथ सेट अप
var methodsWithAttributes =
(from assembly in AppDomain.CurrentDomain.GetAssemblies()
from type in assembly.GetTypes()
from method in type.GetMethods()
let attributes = method.GetCustomAttributes(typeof(SomeAttribute), true)
where attributes != null && attributes.Length > 0
select new { Type = type, Method = method,
Attributes = attributes.Cast<SomeAttribute>() })
.ToList();
मैं एक ही स्कैन में इन 2 गठबंधन करने के लिए यह करने के लिए कोशिश करना चाहिए, या C# - how enumerate all classes with custom class attribute? में आए क्या यह सिर्फ शुरुआती अनुकूलन में पड़ रहा है? (स्कैनिंग केवल ऐप स्टार्ट पर निष्पादित होगी)
क्या कुछ अलग है जो तरीकों की स्कैनिंग के लिए अधिक अनुकूल होगा क्योंकि असेंबली में प्रकारों की तुलना में कहीं अधिक तरीके हैं?
मैं शर्त लगा सकता है कि विधानसभाओं और प्रकार की गणना खोजने और अपनी विशेषताओं instantiating, ऐसी है कि है विधानसभाओं और प्रकार कैशिंग की तुलना में बहुत तेजी से होने जा रहा है जा रहा हूँ व्यर्थ होने जा रहा है। – Gabe