I wrote a method to get the attribute value by property:
public string GetAttributeValueByNameAttributeAndProperty(CodeClass cc, string nameAttribute, string nameProperty) { var value = ""; foreach(CodeAttribute ca in cc.Attributes) { if(ca.Name.Contains(nameAttribute) && ca.Value.Contains(nameProperty)) { value = ca.Value.Remove(0,ca.Value.IndexOf(nameProperty)); value = value.Replace(" ",""); if(value.Contains(",")) value = value.Remove(ca.Value.IndexOf(",")); } } return value; }
Example: I have the attribute [Map(Name = "MenuItem, Availability" )]
I call GetAttributeValueByNameAttributeAndProperty (codecs, "Card", "Name") After this method, get CodeAttribute.Value and the returned string: Name = "MenuItem, Availability" After deleting "Name =" and additional characters and "Divide by", "
But my senior programmer told me that this method is not flexible, and I need to find a more convenient way to get the internal data in CodeAttribute.Value.
Do you have any ideas / examples?
source share