C# Custom Attribute Alternatives -
Currently, I have created a square with 30 properties to be set. This is done to create a URL request later (i.e., ").
The problem I am experiencing is that of the property name, not necessarily the query matches the variables name (this is different). For example, I might have a variable named "BillErce", whereas the query variable should be "as_billaddress".
I have no control over the query variable naming scheme because it is set to an external source.
A potential solution I've used is creating a custom attribute and decorating the properties with their respective counterparts: [customQueryAttribute ("as_billaddress") ] String Bill Address However, to retrieve this attribute, a slight reflection is required and due to the large number of properties, I was curious that if there is a systematic way to accomplish this functionality without reflection System characteristics so as to achieve the set / resume, but is also able to tie optional string variable for the property.
I also thought of setting each variable as a KeyValuePair with each key represents the key to the query, but I did not find that much in the idea.
To summarize / explain my above backups, what would you do to associate the string with the property (
possibly with a custom attribute, But the other possible option would be to do something like keep a static dictionary with string and property information (or property name) so that you can get the property directly through it.
Something like this:
Static Words Sosh & lt; String, property info & gt; PropertyMap = new dictionary & lt; string, property info & gt; (); static MyClass () {type myClass = typeof (MyClass); // for each property that you support You want to: propertyMap.Add ("as_billaddress", MyClass.GetProperty ("BillAddress"); // ...}
Instead of using reflection in each call, You can search a dictionary ... Using this configuration can be quite easy, so that you can reconfigure the runtime Mapping.
Comments
Post a Comment