It's a dirty job but someone has to do it

Well here is just more of the same, Stephen posted about querying an item to see whether it's "dirty" or not.  Here is the .NET equivalent. I didn't actually test these this time so your feedback is welcome.

Visual Basic

 Public Function IsItemDirty(ByVal itm As Object) As Boolean
  Dim typeDispatch As Type = itm.GetType()
  Dim dispidIsDirtyMemberName As String = String.Format("[DispID={0}]", _ 
 &HF024)
  Dim retVal As Boolean = False
  Try
    retVal = typeDispatch.InvokeMember(dispidIsDirtyMemberName, _ 
        System.Reflection.BindingFlags.InvokeMethod _ 
        Or System.Reflection.BindingFlags.GetProperty, _
        Nothing, _
        itm, _
        Nothing)
  Catch comEx As System.Runtime.InteropServices.COMException

  End Try
End Sub

 

C#

 public bool IsItemDirty(object itm)
{
  Type typeDispatch = itm.GetType();
  string dispidIsItemDirtyMemberName = String.Format("[DispID={0}]", 0xF024);
  bool retVal = false;

  try
  {
    retVal = (bool)typeDispatch.InvokeMember(dispidIsItemDirtyMemberName, 
        System.Reflection.BindingFlags.InvokeMethod |
        System.Reflection.BindingFlags.GetProperty,
        null,
        itm,
        null);
  }
  catch(System.Runtime.InteropServices.COMException comEx)
  {

  }
  return retVal;
}