ArtemisComm.Utility.DisposeProperties C# (CSharp) Method

DisposeProperties() public static method

public static DisposeProperties ( this disposableObject ) : void
disposableObject this
return void
        public static void DisposeProperties(this IDisposable disposableObject)
        {
            if (disposableObject != null)
            {
                foreach (PropertyInfo prop in disposableObject.GetType().GetProperties())
                {
                    if (prop.PropertyType.GetInterface("IDisposable") != null)
                    {
                        IDisposable dispose = prop.GetValue(disposableObject, null) as IDisposable;
                        if (dispose != null)
                        {
                            dispose.Dispose();
                        }
                        ICollection<IDisposable> collection = prop.GetValue(disposableObject, null) as ICollection<IDisposable>;
                        if (collection != null)
                        {
                            foreach (IDisposable disposer in collection)
                            {
                                if (disposer != null)
                                {
                                    disposer.Dispose();
                                }
                            }
                        }
                    }
                }
            }
        }
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]