Question

I get from SAP a list with a lot of structures ( [index][structures with items]. My program used a subset from this items. I search for a solution to save this subset of items in a object with public setter and getter. I a kind of mapping

First idea

I can create a big switch an save each items in my specials object but i think this isn't a good idea.

Second idea

The properties names is equals the names from the list. I get with PropertyInfo[] prop = typeof(my object).getProperties() all public setter and getter. Now I check the prop.Name.Equals(item.name) and saved it.

The problem is, my Object has then unreachable properties.

Était-ce utile?

La solution

A switch can be a good idea if you know exactly what properties you want and don't want. This enables easy unit testing and ensures that you program structures are hard coded - this is a good thing!

Another approach would be to use a simple Dictionary:

var myDictionary = new Dictionary<string, string>();

// ...

if (!myDictionary.ContainsKey("Property from SAP"))
{
    myDictionary.Add("Property from SAP", String.Empty);
}

// ...

myDictionary["Property from SAP"] = "Value from SAP";
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top