I wrote a method to get 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;
}
For Example:
I have Attribute [Map(Name = "MenuItem, Availability" )]
I call GetAttributeValueByNameAttributeAndProperty( codeclass, "Map" , "Name") After that method get CodeAttribute.Value and return string: Name = "MenuItem, Availability" After I remove "Name = " and extra characters and Split by ","
But my Senior Programmer told me that this method is inflexible and I need to find a more convenient way get inner data in CodeAttribute.Value.
Do you have any ideas / examples?