System.Type.IsInstanceOfType C# (CSharp) Method

IsInstanceOfType() public method

Determines whether the specified object is an instance of the current T:System.Type.
public IsInstanceOfType ( object o ) : bool
o object The object to compare with the current type.
return bool
        public bool IsInstanceOfType(object o)
        {
            if (o == null)
                return false;
            if (o.As<JsObject>().member("GetType") == null)
                return false;
            else
                return IsAssignableFrom(o.GetType());
        }

Usage Example

 ///////////////////////////////////////////////////////////////////////
 /// <summary>Replaces or adds an extension of the given type
 /// to the list.
 ///
 /// This method looks for the first element on the list of the
 /// given type and replaces it with the new value. If there are
 /// no element of this type yet, a new element is added at the
 /// end of the list.
 /// </summary>
 /// <param name="extensionElements">list of IExtensionElement</param>
 /// <param name="type">type of the element to be added, removed
 /// or replaced</param>
 /// <param name="newValue">new value for this element, null to
 /// remove it</param>
 ///////////////////////////////////////////////////////////////////////
 public static void SetExtension(IList<IExtensionElementFactory> extensionElements,
                                 Type type,
                                 IExtensionElementFactory newValue)
 {
     int count = extensionElements.Count;
     for (int i = 0; i < count; i++)
     {
         object element = extensionElements[i];
         if (type.IsInstanceOfType(element))
         {
             if (newValue == null)
             {
                 extensionElements.RemoveAt(i);
             }
             else
             {
                 extensionElements[i] = newValue;
             }
             return;
         }
     }
     if (newValue != null)
     {
         extensionElements.Add(newValue);
     }
 }
All Usage Examples Of System.Type::IsInstanceOfType