/* * GetCompatibleDataObjectType */ /// <summary> /// Returns the <see cref="T:Type"/> of the data associated with the specified <see cref="T:IDataObject"/> /// if it is compatible with the specified <see cref="T:Type"/>; otherwise, <see langword="null"/>. /// </summary> /// /// <param name="dataObject"> /// Specifies the <see cref="T:IDataObject"/> that contains the data to check for compatability. /// </param> /// /// <param name="compatibleType"> /// Specifies the <see cref="T:Type"/> the data associated with the <see cref="T:IDataObject"/> /// should be compatible with. /// </param> /// /// <returns> /// If the data associated with the specified <see cref="T:IDataObject"/> is compatible with /// the specified <see cref="T:Type"/>, returns the data type; otherwise, <see langword="null"/>. /// </returns> public static Type GetCompatibleDataObjectType(IDataObject dataObject, Type compatibleType) { if (dataObject == null) { throw new ArgumentNullException("dataObject"); } if (compatibleType == null) { throw new ArgumentNullException("compatibleType"); } string[] formats = dataObject.GetFormats(false); for (int i = 0; i < formats.Length; i++) { Type type = NuGenTypeFinder.GetType(formats[i]); if (NuGenArgument.IsCompatibleType(type, compatibleType)) { return(type); } } return(null); }
/* * IsCompatibleType */ /// <summary> /// Indicates whether the type of the <paramref name="argument"/> is compatible with the /// <paramref name="expectedType"/>. If <paramref name="argument"/> is <see langword="null"/>, /// <see langword="false"/> is returned despite the type specified by <paramref name="expectedType"/>. /// But if <paramref name="expectedType"/> is <see langword="null"/> an /// <see cref="T:System.ArgumentNullException"/> is thrown. /// </summary> /// /// <param name="argument">Specifies the argument to check.</param> /// <param name="expectedType">Specifies the type that the passed <paramref name="argument"/> should /// be compatible with.</param> /// /// <returns><see langword="true"/> if the type of the specified <paramref name="argument"/> is /// compatible with <paramref name="expectedType"/>; otherwise, <see langword="false"/>.</returns> /// /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="expectedType"/> is <see langword="null"/>. /// </exception> public static bool IsCompatibleType(object argument, Type expectedType) { if (expectedType == null) { throw new ArgumentNullException("expectedType"); } if (argument != null) { if (NuGenArgument.IsCompatibleType(argument.GetType(), expectedType)) { return(true); } } return(false); }