/// <summary>
        /// Gets the derived <see cref="GenericTypeParameterData"/> instance representing the specified type.
        /// </summary>
        /// <returns>The derived <see cref="GenericTypeParameterData"/> instance.</returns>
        public new static GenericTypeParameterData FromType(Type t)
        {
            if (t.IsGenericParameter == false)
            {
                throw new ArgumentException("The specified type is not a valid generic type parameter.", "t");
            }

            var module        = t.Assembly.ToAssemblyDefinition().MainModule;
            var declaringType = module.GetType(t.DeclaringType.FullName, runtimeName: true);

            if (t.DeclaringMethod != null)
            {
                var methods = declaringType.Resolve().Methods.Where(
                    m => m.Name == t.DeclaringMethod.Name &&
                    m.Parameters.Count == t.DeclaringMethod.GetParameters().Length&&
                    m.GenericParameters.Count == t.DeclaringMethod.GetGenericArguments().Length);

                // TODO: Test this with various cases (ref and out parameters, parameters types being nested types
                foreach (var method in methods)
                {
                    var isMatch = true;

                    int parameterIndex = 0;
                    foreach (var parameter in t.DeclaringMethod.GetParameters())
                    {
                        if (method.Parameters[parameterIndex++].ParameterType.EqualsType(parameter.ParameterType) == false)
                        {
                            isMatch = false;
                            break;
                        }
                    }

                    if (isMatch)
                    {
                        return(GenericTypeParameterData.FromType(method.GenericParameters[t.GenericParameterPosition]));
                    }
                }

                Debug.Fail("Cannot find matching method");
                return(null);
            }
            else
            {
                return(GenericTypeParameterData.FromType(declaringType.GenericParameters[t.GenericParameterPosition]));
            }
        }
 /// <summary>
 /// Gets the derived <see cref="GenericTypeParameterData"/> instance representing the specified type.
 /// </summary>
 /// <typeparam name="T">The type for which to get the <see cref="GenericTypeParameterData"/>.</typeparam>
 /// <returns>The derived <see cref="GenericTypeParameterData"/> instance.</returns>
 public new static GenericTypeParameterData FromType <T>()
 {
     return(GenericTypeParameterData.FromType(typeof(T)));
 }
 /// <summary>
 /// The visit implementation for <see cref="GenericTypeParameterData"/> instances.
 /// </summary>
 public virtual void VisitGenericTypeParameterData(GenericTypeParameterData item)
 {
     this.DefaultVisit(item);
 }