Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if an object's type is from a particular namespace

Is it possible to check if the object's type is a part of a particular namespace from C# code? If yes, how?

I need to check if e.OriginElement as FrameworkElement is one of the MS.Internal controls.

like image 899
Maxim V. Pavlov Avatar asked Jan 11 '12 00:01

Maxim V. Pavlov


People also ask

How do you check if an object is a specific type?

To determine whether an object is a specific type, you can use your language's type comparison keyword or construct.

What is GetType() C#?

GetType Method is used to find the type of the current instance. This method returns the instances of the Type class that are used for consideration.

What is a namespace type?

A namespace is a logical design-time naming convenience, used mainly to define scope in an application and organize classes and other types in a single hierarchical structure. From the viewpoint of the runtime, there are no namespaces.


2 Answers

You can inspect the Type.Namespace property.

e.OriginElement.GetType().Namespace

like image 73
Igby Largeman Avatar answered Oct 01 '22 09:10

Igby Largeman


e.OriginElement.GetType().Namespace

should give you the information you need.

like image 32
Kendall Frey Avatar answered Oct 01 '22 09:10

Kendall Frey