asp.net - Dynamic property changing, C# -
so have function replacement looking this:
powerpointeventarg.powerpointdatalist[index].property = powerpointeventarg.powerpointdatalist[index].property.replace("deeperskyblue", "0066cc"); powerpointeventarg.powerpointdatalist[index].property = powerpointeventarg.powerpointdatalist[index].property.replace("deepskyblue", "3366ff"); powerpointeventarg.powerpointdatalist[index].property = powerpointeventarg.powerpointdatalist[index].property.replace("skyblue", "99ccff"); powerpointeventarg.powerpointdatalist[index].property = powerpointeventarg.powerpointdatalist[index].property.replace("yellow", "ffff00"); powerpointeventarg.powerpointdatalist[index].property = powerpointeventarg.powerpointdatalist[index].property.replace("darkturquoise", "0066cc"); powerpointeventarg.powerpointdatalist[index].property = powerpointeventarg.powerpointdatalist[index].property.replace("salmom", "ff8080"); powerpointeventarg.powerpointdatalist[index].property = powerpointeventarg.powerpointdatalist[index].property.replace("lightblue", "3366ff"); powerpointeventarg.powerpointdatalist[index].property = powerpointeventarg.powerpointdatalist[index].property.replace("lightpurple", "cc99ff"); powerpointeventarg.powerpointdatalist[index].property = powerpointeventarg.powerpointdatalist[index].property.replace("darkblue", "000080"); powerpointeventarg.powerpointdatalist[index].property = powerpointeventarg.powerpointdatalist[index].property.replace("darkorange", "ff9900");
in code, see "replacement" performed 9 times, , thing different 9 "property".
i know if there way dynamically change property, write replacement code once, change 9 different properties?
create variables make code shorter , copy/paste assignment:
var eai = eventargs.interfaceinsideeventarg[index]; var eaz = eventargs.interfaceinsideeventarg[z]; eai.propertyinsideinterface = eaz.propertyinsideinterface.replace("deeperskyblue", "0066cc"); eai.{prop2} = eaz.{prop2}.replace("deeperskyblue", "0066cc"); //etc.
you could use reflection getting each property name, looping, , doing assignment, but:
- it won't less code
- it take longer write copy/paste
- you'll have thoroughly test
- it harder debug
- you lose type safety
- if property names (or types) change won't know code broken until run-time.
Comments
Post a Comment