DotNext by Roman Sakno

<PackageReference Include="DotNext" Version="3.1.0" />

.NET API 362,496 bytes

 ObjectExtensions

public static class ObjectExtensions
Various extension methods for reference types.
using DotNext.Runtime; using System; using System.Collections.Generic; using System.Runtime.CompilerServices; namespace DotNext { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] public static class ObjectExtensions { [System.Runtime.CompilerServices.NullableContext(2)] internal static bool IsNull(object obj) { return obj == null; } [System.Runtime.CompilerServices.NullableContext(2)] internal static bool IsNotNull(object obj) { return obj != null; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static UserDataStorage GetUserData<T>(this T obj) where T : class { return new UserDataStorage(obj); } public static bool IsOneOf<T>(this T value, [System.Runtime.CompilerServices.Nullable(new byte[] { 1, 2 })] IEnumerable<T> values) where T : class { foreach (T value2 in values) { if (object.Equals(value, value2)) return true; } return false; } public unsafe static bool IsOneOf<T>(this T value, [System.Runtime.CompilerServices.Nullable(new byte[] { 1, 2 })] params T[] values) where T : class { for (IntPtr intPtr = (IntPtr)0; (long)intPtr < (long)Intrinsics.GetLength(values); intPtr = (IntPtr)(void*)((long)intPtr + 1)) { if (object.Equals(values[(long)intPtr], value)) return true; } return false; } internal static bool IsContravariant([System.Runtime.CompilerServices.Nullable(2)] object obj, Type type) { return obj?.GetType().IsAssignableFrom(type) ?? false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T As<T>(this T obj) where T : class { return obj; } } }