arrays - Mapping string values to properties' values in c# -


i'm newbie in c# , have 1 question

i have class model this:

 public class sdview     {         public int viewpk { get; set; }         public string code { get; set; }         public string name { get; set; }         public string conceptorder { get; set; }      } 

the last property, conceptorder contains string of numbers, each number needs mapped different property value...

example:

being conceptorder = "1,2,3,5,4"

  public class item         {             public string warehouse { get; set; } //concept 1             public string commodity { get; set; } //concept 2             public string variety { get; set; }   //concept 3             public string packstyle { get; set; } //concept 4             public string size { get; set; }      //concept 5         } 

what need write method or function returns (based on above example)

"warehouse01 bellpepper green jumbo 7x1"

conceptorder can in order, every number mapped property (1 warehouse... 2 commodity)

obviously example simplified

i can't head around this

any appreciated!

edit:

exactly i'm trying do, is, have class model properties:

the property conceptorder on sdview class contains order in these properties have shown in string property

so need function/method in can pass conceptorder ("2, 3, 1, 4, 5") , returns formatted string...

public class item         {             public string warehouse { get; set; } //concept 1             public string commodity { get; set; } //concept 2             public string variety { get; set; }   //concept 3             public string packstyle { get; set; } //concept 4             public string size { get; set; }      //concept 5              public string getproductfromview(string conceptorder)            {             ...            return "commoditypropvalue varietypropvalue warehousepropvalue.. etc" 

}}

conceptvalue handles each different property , conceptvalues conceptvalue each value in conceptorder , put them in string space between each.

public string conceptvalues(string conceptorder) {     var split = conceptorder.split(new[] { "," }, stringsplitoptions.removeemptyentries);      var nums = split.select(s => int32.parse(s.trim()));      return nums.select(n => conceptvalue(n))         .aggregate((acc, s) => string.format("{0} {1}", acc, s)); }  public string conceptvalue(int concept) {     switch (conceptorder)     {         case 1:             return warehouse;         case 2:             return commodity;         // etc...         default:             throw new argumentexception("unhandled concept", "concept");     } } 

tested using...

class program {     private static string str1 { get; set; }     private static string str2 { get; set; }     private static string str3 { get; set; }     private static string conceptorder { get; set; }      static void main(string[] args)     {         str1 = "string1";         str2 = "string2";         str3 = "string3";         conceptorder = "2, 3, 1";         console.writeline(conceptvalues(conceptorder));         // output: string2 string3 string1         console.readkey(true);     } } 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -