/// <summary> /// Returns the type info for the member with the specified name of the specified type. /// </summary> /// <param name="type">Type to get member info from.</param> /// <param name="name">Name of member to get info for.</param> /// <returns>Type info for the member with the specified name of the specified type.</returns> public static NodeTypeInfo GetNodeTypeInfo(Type type, string name) { // Get item if collection. var typeInterfaces = TypeInfoUtils.GetInterfaces(type); if (typeInterfaces.Contains(typeof(IEnumerable))) { // Check if index provided. int itemIndex; if (int.TryParse(name, out itemIndex)) { // Get item type. var itemType = type.GetElementType(); if (itemType == null) { if (TypeInfoUtils.IsGenericType(type)) { var genericArguments = TypeInfoUtils.GetGenericArguments(type); itemType = genericArguments.Length > 0 ? genericArguments[0] : typeof(object); } else { itemType = typeof(object); } } // Return item. return(new EnumerableNode { Type = itemType, Index = itemIndex }); } } // Get property. var reflectionProperty = TypeInfoUtils.GetPublicProperty(type, name); if (reflectionProperty != null) { return(new PropertyNode { Type = reflectionProperty.PropertyType, Property = reflectionProperty }); } // Get field. var reflectionField = TypeInfoUtils.GetPublicField(type, name); if (reflectionField != null) { return(new FieldNode { Type = reflectionField.FieldType, Field = reflectionField }); } // Get method. var reflectionMethod = TypeInfoUtils.GetPublicMethod(type, name); if (reflectionMethod != null) { return(new MethodNode { Type = reflectionMethod.ReturnType, Method = reflectionMethod }); } return(null); }
/// <summary> /// Returns the full name of the specified type without any assembly version info. /// The reason why this method is needed is that a generic type's FullName contains /// the full AssemblyQualifiedName of its item type. /// </summary> /// <param name="type">Type to get full name for.</param> /// <returns>Full name of specified type without additional info of the assembly.</returns> public static string FullNameWithoutAssemblyInfo(this Type type) { return(!TypeInfoUtils.IsGenericType(type) ? type.FullName : RemoveAssemblyInfo(type.FullName)); }