How can I determine by reflection if the type of an object is defined by a class in my own assembly or by the .NET Framework?
I dont want to supply the name of my own assembly in code, because it should work with any assembly and namespace.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Where would third-party types come in? You might want to differentiate between types which claim to be provided by Microsoft and types which don’t.
Of course, any type could claim to be a Microsoft one given this scheme, but if you’re actually only going to call it on your own types and framework ones, I suspect this should work fine.
Alternatively, you could use the assembly’s public key token. This is likely to be harder to fake. It relies on Microsoft using a common public key for all their assemblies, which they don’t (according to Mehrdad’s comment below). However, you could easily adapt this solution for a set of accepted “this is from Microsoft” public keys. Perhaps combine the two approaches somehow and report any differences for further inspection…