I have a string and I want to check if it represents a proper namespace, eg. System.IO is ok, but System.Lol is not.
I guess some reflection should be used, but I can’t figure this out.
Any thoughts?
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.
Your question “How to check if string is a namespace” is only valid when you consider where you are checking for namespaces.
Namespaces are prefixes to class names, and classes are scoped to an assembly. To check whether a namespace exists, you need to decide which assemblies you are prepared to look through to find the existence of the namespace.
Once you have decided which assemblies you are prepared to look through, you can iterate through them for the existence of a particular namespace like so: