Convert string to model

后端 未结 1 1831
心在旅途
心在旅途 2021-01-29 06:53

Let\'s say I have this object:

public struct Line
{
    public string Name { get; set; }
    public int Value { get; set; }
    public string Alias { get; set; }         


        
1条回答
  •  孤街浪徒
    2021-01-29 07:22

    In my opinion, there are a couple of questions that needs to be asked here.

    1. Can you change the file format?
    2. Is there no way, you can specify a separate delimiter for key/value pairs? {value:garbage,alias:someotherGarbage},{value:secondGarbage....}
    3. Are the lines (Environment.NewLine) the only way packets are separated?

    If the answer to 1 is true, then you can use XmlSerializer and Serialize and Deserialize your objects to and fro.

    If the answer for 2 is true, then you could look at parsing the file manually using regex or reading line by line and just looking for Value: and then assume that the next item is the value of "Value"

    if the answer for 3 is true, Possibly the same answer as 2.

    I hope this helps.

    0 讨论(0)
提交回复
热议问题