/// <summary> /// Create the attribute of a entity-validator from XML definitions. /// </summary> /// <param name="entityType">The entity class where associate the attribute.</param> /// <param name="attributename">The attribute name in the mapping.</param> /// <returns>The <see cref="Attribute"/> instance.</returns> /// <remarks> /// We are using the conventions: /// - The attribute must be defined in the same namespace of the <paramref name="entityType"/>. /// - The attribute class may have the postfix "Attribute" without need to use it in the mapping. /// </remarks> public static Attribute CreateAttributeFromClass(System.Type entityType, NhvmClassAttributename attributename) { // public Only for test scope Assembly assembly = entityType.Assembly; System.Type type = assembly.GetType(entityType.Namespace + "." + GetText(attributename) + "Attribute"); if (type == null) { type = assembly.GetType(entityType.Namespace + "." + GetText(attributename)); } if (type == null) { type = System.Type.GetType(GetText(attributename), false); } if (type == null) { throw new InvalidAttributeNameException(GetText(attributename), entityType); } Attribute attribute = (Attribute)Activator.CreateInstance(type); if (attribute is IRuleArgs && attributename.message != null) { ((IRuleArgs)attribute).Message = attributename.message; } return attribute; }
/// <summary> /// Create the attribute of a entity-validator from XML definitions. /// </summary> /// <param name="entityType">The entity class where associate the attribute.</param> /// <param name="attributename">The attribute name in the mapping.</param> /// <returns>The <see cref="Attribute"/> instance.</returns> /// <remarks> /// We are using the conventions: /// - The attribute must be defined in the same namespace of the <paramref name="entityType"/>. /// - The attribute class may have the postfix "Attribute" without need to use it in the mapping. /// </remarks> public static Attribute CreateAttributeFromClass(System.Type entityType, NhvmClassAttributename attributename) { // public Only for test scope Assembly assembly = entityType.Assembly; System.Type type = assembly.GetType(entityType.Namespace + "." + GetText(attributename) + "Attribute"); if (type == null) { type = assembly.GetType(entityType.Namespace + "." + GetText(attributename)); } if (type == null) { type = System.Type.GetType(GetText(attributename), false); } if (type == null) { throw new InvalidAttributeNameException(GetText(attributename), entityType); } Attribute attribute = (Attribute)Activator.CreateInstance(type); if (attribute is IRuleArgs && attributename.message != null) { ((IRuleArgs)attribute).Message = attributename.message; } return(attribute); }
private static string GetText(NhvmClassAttributename attributename) { string[] text = attributename.Text; if (text != null) { string result = string.Join(System.Environment.NewLine, text).Trim(); return(result.Length == 0 ? null : result); } else { return(null); } }
private static string GetText(NhvmClassAttributename attributename) { string[] text = attributename.Text; if (text != null) { string result = string.Join(System.Environment.NewLine, text).Trim(); return result.Length == 0 ? null : result; } else return null; }