using Cobilas.Collections;
namespace System {
#pragma warning disable CS1591 // O comentário XML ausente não foi encontrado para o tipo ou membro visível publicamente
public static class Object_CB_Extension {
#pragma warning restore CS1591 // O comentário XML ausente não foi encontrado para o tipo ou membro visível publicamente
///
/// Compares the object's type to a specified type.
///
/// The target object of comparison.
/// The specified comparison type.
public static bool CompareType(this object O, Type type)
=> (O is Type tres ? tres : O.GetType()) == type;
///
/// Compares the object's type to a specified list of types.
///
/// The target object of comparison.
/// The specified comparison types.
public static bool CompareType(this object O, params Type[] types) {
for (int I = 0; I < ArrayManipulation.ArrayLength(types); I++)
if (CompareType(O, types[I]))
return true;
return false;
}
///
/// Compares the object's type with a specified generic type.
///
/// The target object of comparison.
/// The generic comparison type specified.
public static bool CompareType(this object O)
=> CompareType(O, typeof(T));
/// Compares class type and the class it inherits.
public static bool CompareTypeAndSubType(this object O, Type type, bool IncludeInterface)
=> CompareType(O, type) || IsSubclassOf(O, type) ||
(IncludeInterface && IsAssignableFrom(O, type));
/// Compares class type and the class it inherits.
public static bool CompareTypeAndSubType(this object O, Type type)
=> CompareTypeAndSubType(O, type, false);
/// Compares class type and the class it inherits.
public static bool CompareTypeAndSubType(this object O, bool IncludeInterface)
=> CompareTypeAndSubType(O, typeof(T), IncludeInterface);
/// Compares class type and the class it inherits.
public static bool CompareTypeAndSubType(this object O)
=> CompareTypeAndSubType(O, false);
private static bool IsSubclassOf(object O, Type type)
=> (O is Type tp ? tp : O.GetType()).IsSubclassOf(type);
private static bool IsAssignableFrom(object O, Type type)
=> (O is Type tp ? tp : O.GetType()).IsAssignableFrom(type);
}
}