This document is archived and information here might be outdated.  Recommended version.


Interrogate Object Snippet (ArcObjects .NET 10.4 SDK)
ArcObjects Library Reference

Interrogate Object Snippet

Generic template for determining what Type of Object you are working with.

[C#]
///<summary>Generic template for determining what Type of Object you are working with.</summary>
/// 
///<param name="anyObject">Any variable for input to interrogate what Type it is.</param>
/// 
///<returns>A System.Boolean. True=the object is the right Type, False=the object is not the right Type.</returns>
/// 
///<remarks>
///Supply the 'anyObject' (or variable) as the input. Example: (1) m_application, (2) myString, etc...
///Replace the 'System.Object' WITHIN the procedure with a Type you want to check against. Example: (1) ESRI.ArcGIS.Framework.IApplication, (2) System.String, etc...
/// 
///Note:
///Do not change the input Type parameter of System.Object, leave it as is.
///That way you can interrogate any input type of object. 
///Just change the 'System.Object' WITHIN the procedure to test for what type of Object you have.
///</remarks>
public System.Boolean InterrogateObject(object anyObject)
{

  if (anyObject is System.Object) // Replace the 'System.Object' argument on this line with a Type you want to check. Example: (1) ESRI.ArcGIS.Framework.IApplication, (2) System.String, etc...
  {

        return true;

  }
  else
  {

        return false;

  }

}
[Visual Basic .NET]
'''<summary>Generic template for determining what Type of Object you are working with.</summary>
''' 
'''<param name="anyObject">Any variable for input to interrogate what Type it is.</param>
''' 
'''<returns>A System.Boolean. True=the object is the right Type, False=the object is not the right Type.</returns>
''' 
'''<remarks>
'''Supply the 'anyObject' (or variable) as the input. Example: (1) m_application, (2) myString, etc...
'''Replace the 'System.Object' WITHIN the procedure with a Type you want to check against. Example: (1) ESRI.ArcGIS.Framework.IApplication, (2) System.String, etc...
''' 
'''Note:
'''Do not change the input Type parameter of System.Object, leave it as is.
'''That way you can interrogate any input type of object. 
'''Just change the 'System.Object' WITHIN the procedure to test for what type of Object you have.
'''</remarks>
Public Function InterrogateObject(ByVal anyObject As System.Object) As System.Boolean

  If TypeOf anyObject Is System.Object Then ' Replace the 'System.Object' argument on this line with a Type you want to check. Example: (1) ESRI.ArcGIS.Framework.IApplication, (2) System.String, etc...

    Return True

  Else

    Return False

  End If

End Function

Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • System