PortableExtensions
Extensions for ensuring code portability.
using System;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
namespace AngleSharp.Extensions
{
internal static class PortableExtensions
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string ConvertFromUtf32(this int utf32)
{
return char.ConvertFromUtf32(utf32);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int ConvertToUtf32(this string s, int index)
{
return char.ConvertToUtf32(s, index);
}
public static Task Delay(this CancellationToken token, int timeout)
{
return Task.Delay(Math.Max(timeout, 4), token);
}
public static bool Implements<T>(this Type type)
{
return type.GetTypeInfo().ImplementedInterfaces.Contains(typeof(T));
}
public static PropertyInfo[] GetProperties(this Type type)
{
return type.GetRuntimeProperties().ToArray();
}
public static ConstructorInfo[] GetConstructors(this Type type)
{
return type.GetTypeInfo().DeclaredConstructors.Where(delegate(ConstructorInfo c) {
if (c.IsPublic)
return !c.IsStatic;
return false;
}).ToArray();
}
public static PropertyInfo GetProperty(this Type type, string name)
{
return type.GetTypeInfo().GetDeclaredProperty(name);
}
public static bool IsAbstractClass(this Type type)
{
return type.GetTypeInfo().get_IsAbstract();
}
public static Type[] GetTypes(this Assembly assembly)
{
return (from t in assembly.DefinedTypes
select t.AsType()).ToArray();
}
public static Assembly GetAssembly(this Type type)
{
return type.GetTypeInfo().get_Assembly();
}
}
}