using UnityEngine;
using System;
using System.Reflection;

public static class WP8Extensions 
{
#if UNITY_METRO && !UNITY_EDITOR
    public static ConstructorInfo GetConstructor(this Type type, Type[] paramTypes)
    {
        return type.GetTypeInfo().GetConstructor(paramTypes);
    }

    public static System.Object[] GetCustomAttributes(this Type type, bool inherit)
    {
        return type.GetTypeInfo().GetCustomAttributes(inherit);
    }
    
    public static System.Object[] GetCustomAttributes(this Type type, Type attributeType, bool inherit)
    {
        return type.GetTypeInfo().GetCustomAttributes(attributeType, inherit);
    }
  
    public static FieldInfo GetField(this Type type, string name)
    {
        return type.GetTypeInfo().GetField(name);
    }
    
    public static FieldInfo GetField(this Type type, string name, BindingFlags bindingAttr)
    {
        return type.GetTypeInfo().GetField(name, bindingAttr);
    }
    
    public static Type[] GetGenericArguments(this Type type)
    {
        return type.GetTypeInfo().GetGenericArguments();
    }

    public static int GetHashCode(this Type type)
    {
        return type.GetTypeInfo().GetHashCode();
    }

    public static PropertyInfo[] GetProperties(this Type type)
    {
        return type.GetTypeInfo().GetProperties();
    }

    public static PropertyInfo[] GetProperties(this Type type, BindingFlags bindingAttr)
    {
        return type.GetTypeInfo().GetProperties(bindingAttr);
    }

    public static PropertyInfo GetProperty(this Type type, string name)
    {
        return type.GetTypeInfo().GetProperty(name);
    }

    public static PropertyInfo GetProperty(this Type type, string name, BindingFlags bindingAttr)
    {
        return type.GetTypeInfo().GetProperty(name, bindingAttr);
    }

    public static PropertyInfo GetProperty(this Type type, string name, Type returnType)
    {
        return type.GetTypeInfo().GetProperty(name, returnType);
    }

    public static PropertyInfo GetProperty(this Type type, string name, Type[] types)
    {
        return type.GetTypeInfo().GetProperty(name, types);
    }

    public static PropertyInfo GetProperty(this Type type, string name, Type returnType, Type[] types)
    {
        return type.GetTypeInfo().GetProperty(name, returnType, types);
    }

    public static PropertyInfo GetProperty(this Type type, string name, Type returnType, Type[] types,	ParameterModifier[] modifiers)
    {
        return type.GetTypeInfo().GetProperty(name, returnType, types, modifiers);
    }

    public static PropertyInfo GetProperty(this Type type, string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
    {
        return type.GetTypeInfo().GetProperty(name, bindingAttr, binder, returnType, types, modifiers);
    }

    public static bool IsSubclassOf(this Type type, Type c)
    {
        return type.GetTypeInfo().IsSubclassOf(c);
    }

    public static bool IsAssignableFrom(this Type type, Type other)
	{
		return type.GetTypeInfo().IsAssignableFrom(other.GetTypeInfo());
	}    
#endif

    public static Type BaseType(Type type)
    {
#if UNITY_METRO && !UNITY_EDITOR  
        return type.GetTypeInfo().BaseType;
#else
        return type.BaseType;
#endif
    }

    public static bool IsAbstract(Type type)
    {
#if UNITY_METRO && !UNITY_EDITOR  
        return type.GetTypeInfo().IsAbstract;
#else
        return type.IsAbstract;
#endif
    }

    public static bool IsClass(Type type)
    {
#if UNITY_METRO && !UNITY_EDITOR  
        return type.GetTypeInfo().IsClass;
#else
        return type.IsClass;
#endif
    }

    public static bool IsEnum(Type type)
    {
#if UNITY_METRO && !UNITY_EDITOR  
        return type.GetTypeInfo().IsEnum;
#else
        return type.IsEnum;
#endif
    }

    public static bool IsInterface(Type type)
    {
#if UNITY_METRO && !UNITY_EDITOR  
        return type.GetTypeInfo().IsInterface;
#else
        return type.IsInterface;
#endif
    }

    public static bool IsValueType(Type type)
    {
#if UNITY_METRO && !UNITY_EDITOR  
        return type.GetTypeInfo().IsValueType;
#else
        return type.IsValueType;
#endif
    }

    public static char Parse(string str)
    {
        char parsedChar;
        if (!char.TryParse(str, out parsedChar))
        {
            char.TryParse("", out parsedChar);
        }
        return parsedChar;
    }
}