public static string GetEisppRuleElement(this Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata model, string fieldPrefix) { if (!fieldPrefix.StartsWith("Data.Events[0].")) { fieldPrefix = "Data.Events[0]." + fieldPrefix.Replace("NewEventObj.", ""); } fieldPrefix = model.GetEisppRulePath(fieldPrefix + "."); if (fieldPrefix.EndsWith(".")) { fieldPrefix = fieldPrefix.Substring(0, fieldPrefix.Length - 1); } return(fieldPrefix); }
public static string GetEisppRuleFullName(this Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata model, string fieldPrefix, bool isVM) { try { if (model.ContainerType != null) { if (!fieldPrefix.StartsWith("Data.Events[0].")) { fieldPrefix = "Data.Events[0]." + fieldPrefix.Replace("NewEventObj.", ""); } fieldPrefix = model.GetEisppRulePath(fieldPrefix); string propertyName = model.PropertyName; if (isVM && propertyName.EndsWith("VM")) { propertyName = propertyName.Substring(0, propertyName.Length - 2); } var Member = model.ContainerType.GetMember(propertyName); object[] attribs = Member[0].GetCustomAttributes(typeof(System.Xml.Serialization.XmlAttributeAttribute), false); bool doesPropertyHaveAttrib = attribs.Length > 0; if (doesPropertyHaveAttrib) { string name = ((System.Xml.Serialization.XmlAttributeAttribute)attribs[0]).AttributeName; if (fieldPrefix.Contains(".")) { fieldPrefix = fieldPrefix.Replace("." + model.PropertyName, "." + name, StringComparison.InvariantCulture); } else { fieldPrefix = fieldPrefix.Replace(model.PropertyName, name, StringComparison.InvariantCulture); } return(fieldPrefix); } } } catch (Exception ex) { } return(""); }