ঠিক আছে, আপনাকে বর্তমান অ্যাপ্লিকেশন ডোমেনে লোড করা সমস্ত অ্যাসেমব্লির সমস্ত শ্রেণীর মধ্য দিয়ে গণনা করতে হবে। যে কাজের জন্য, আপনি কল করবে GetAssembliesপদ্ধতি উপর AppDomainবর্তমান অ্যাপ্লিকেশান ডোমেনের জন্য উদাহরণস্বরূপ।
সেখান থেকে, আপনি সমাবেশ করতে GetExportedTypesচান (যদি আপনি কেবল সর্বজনীন প্রকার চান) বা GetTypesপ্রত্যেকটিতে Assemblyসমাবেশগুলিতে থাকা ধরণেরগুলি পেতে।
তারপরে, আপনি প্রতিটি উদাহরণে GetCustomAttributesএক্সটেনশন পদ্ধতিতে কল করবেন, আপনি Typeযে বৈশিষ্ট্যের সন্ধান করতে চান তার ধরণটি পাস করে।
এটি আপনার জন্য সহজ করার জন্য আপনি লিনকিউ ব্যবহার করতে পারেন:
var typesWithMyAttribute =
from a in AppDomain.CurrentDomain.GetAssemblies()
from t in a.GetTypes()
let attributes = t.GetCustomAttributes(typeof(HelpAttribute), true)
where attributes != null && attributes.Length > 0
select new { Type = t, Attributes = attributes.Cast<HelpAttribute>() };
উপরোক্ত ক্যোয়ারী আপনাকে এতে নির্দিষ্ট করা অ্যাট্রিবিউট (গুলি) এর উদাহরণ সহ আপনার প্রতিটি প্রকারের সাথে এটি প্রয়োগ করা হবে।
মনে রাখবেন যে আপনার অ্যাপ্লিকেশন ডোমেনে প্রচুর সংখ্যক সমাবেশগুলি লোড করা থাকলে সেই অপারেশন ব্যয়বহুল হতে পারে। অপারেশনের সময় কমাতে আপনি সমান্তরাল লাইনকিউ ব্যবহার করতে পারেন , যেমন:
var typesWithMyAttribute =
// Note the AsParallel here, this will parallelize everything after.
from a in AppDomain.CurrentDomain.GetAssemblies().AsParallel()
from t in a.GetTypes()
let attributes = t.GetCustomAttributes(typeof(HelpAttribute), true)
where attributes != null && attributes.Length > 0
select new { Type = t, Attributes = attributes.Cast<HelpAttribute>() };
এটি একটি নির্দিষ্ট উপর ফিল্টারিং Assembly করা সহজ:
Assembly assembly = ...;
var typesWithMyAttribute =
from t in assembly.GetTypes()
let attributes = t.GetCustomAttributes(typeof(HelpAttribute), true)
where attributes != null && attributes.Length > 0
select new { Type = t, Attributes = attributes.Cast<HelpAttribute>() };
এবং যদি সমাবেশে এটির একটি বিশাল সংখ্যক প্রকার থাকে তবে আপনি আবার সমান্তরাল লিনকিউ ব্যবহার করতে পারেন:
Assembly assembly = ...;
var typesWithMyAttribute =
// Partition on the type list initially.
from t in assembly.GetTypes().AsParallel()
let attributes = t.GetCustomAttributes(typeof(HelpAttribute), true)
where attributes != null && attributes.Length > 0
select new { Type = t, Attributes = attributes.Cast<HelpAttribute>() };