6

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.

Maxim V. Pavlov
  • 10,303
  • 17
  • 74
  • 174
  • Can you not use the fully qualified type name in your cast? `e.OriginElement as MS.Internal.FrameworkElement == null` – Chris Jan 11 '12 at 00:14

2 Answers2

14

You can inspect the Type.Namespace property.

e.OriginElement.GetType().Namespace

Igby Largeman
  • 16,495
  • 3
  • 60
  • 86
  • Sorry, correct you were. Good thing I have commented yesterday, so my decision reason was brought up, and now everything is fair =) – Maxim V. Pavlov Jan 11 '12 at 08:34
4
e.OriginElement.GetType().Namespace

should give you the information you need.

Kendall Frey
  • 43,130
  • 20
  • 110
  • 148