Extensions
Contains extension methods that do not require a special using directive.
using System;
using System.Collections;
using System.Linq;
using System.Reflection;
namespace NUnit.Framework
{
internal static class Extensions
{
public static bool IsStatic(this Type type)
{
if (type.GetTypeInfo().get_IsAbstract())
return type.GetTypeInfo().get_IsSealed();
return false;
}
public static bool HasAttribute<T>(this MemberInfo attributeProvider, bool inherit) where T : class
{
return CustomAttributeExtensions.GetCustomAttributes(attributeProvider, inherit).OfType<T>().Any();
}
public static bool HasAttribute<T>(this ParameterInfo attributeProvider, bool inherit) where T : class
{
return CustomAttributeExtensions.GetCustomAttributes(attributeProvider, inherit).OfType<T>().Any();
}
public static bool HasAttribute<T>(this Type attributeProvider, bool inherit) where T : class
{
return CustomAttributeExtensions.GetCustomAttributes(attributeProvider.GetTypeInfo(), inherit).OfType<T>().Any();
}
public static bool HasAttribute<T>(this Assembly attributeProvider) where T : class
{
return attributeProvider.GetCustomAttributes().OfType<T>().Any();
}
public static T[] GetAttributes<T>(this MemberInfo attributeProvider, bool inherit) where T : class
{
return CustomAttributeExtensions.GetCustomAttributes(attributeProvider, inherit).OfType<T>().ToArray();
}
public static T[] GetAttributes<T>(this ParameterInfo attributeProvider, bool inherit) where T : class
{
return CustomAttributeExtensions.GetCustomAttributes(attributeProvider, inherit).OfType<T>().ToArray();
}
public static T[] GetAttributes<T>(this Type attributeProvider, bool inherit) where T : class
{
return CustomAttributeExtensions.GetCustomAttributes(attributeProvider.GetTypeInfo(), inherit).OfType<T>().ToArray();
}
public static T[] GetAttributes<T>(this Assembly attributeProvider) where T : class
{
return attributeProvider.GetCustomAttributes().OfType<T>().ToArray();
}
public static IEnumerable Skip(this IEnumerable enumerable, long skip)
{
IEnumerator iterator = enumerable.GetEnumerator();
using (iterator as IDisposable) {
while (true) {
long num = skip;
skip = num - 1;
if (num <= 0)
break;
if (!iterator.MoveNext())
yield break;
}
while (iterator.MoveNext()) {
yield return iterator.Current;
}
}
}
}
}