1

I've found a code that does exactly what I like: View/edit ID3 data for MP3 files

...

class a{
   public ? getContent(){

      string Title = Encoding.Default.GetString(tag.Title);
      string Artist = Encoding.Default.GetString(tag.Artist);
      string Album = Encoding.Default.GetString(tag.Album);
   }
}

class form1{
    button1.click()
    {
        ? = a.getContent
        text1.text = ?.Title;
        text2.Text = ?.Artist;
    }
}

Simucal print the result to the console but I'd like to have a winform that gets this input and puts it in some textboxes. I guess I can do it with arrays but I guess there are better ways to do it in the mvvm way (I know that my question may make no sense but I like to do it the right way)...

Please help :)

Community
  • 1
  • 1
Asaf
  • 3,067
  • 11
  • 35
  • 54

3 Answers3

1

In this situation, you would simply return a result object containing that data:

public ContentData getContent()
{
     return new ContentData
     {
        Title = "Hello World",
        Artist = "Some Other String"
     };
}

ContentData data = someobject.getContent();

text1.Text = data.Title; 
// etc

You would just make your own type.

Tejs
  • 40,736
  • 10
  • 68
  • 86
1

Is there some reason you can't use a class to encapsulate that data?

class TagData
{
    public string Title {get; set; }
    public string Artist {get; set; }
    public string Album {get; set; }
}

class a{
   public TagData getContent(){
      return new TagData
      {
          Title = Encoding.Default.GetString(tag.Title),
          Artist = Encoding.Default.GetString(tag.Artist),
          Album = Encoding.Default.GetString(tag.Album)
      };
   }
}

class form1{
    button1.click()
    {
        var tagData = a.getContent
        text1.text = tagData.Title;
        text2.Text = tagData.Artist;
    }
}

Alternatively, if you want to be less 'safe' about it, you could just pack it all into a Dictionary:

class a{
   public Dictionary<string, string> getContent(){
      var tagData = new Dictionary<string, string>();
      tagData["Title"] = Encoding.Default.GetString(tag.Title);
      tagData["Artist"] = Encoding.Default.GetString(tag.Artist);
      tagData["Album"] = Encoding.Default.GetString(tag.Album);
      return tagData;
   }
}

class form1{
    button1.click()
    {
        var tagData = a.getContent();
        text1.Text = tagData["Title"];
        text2.Text = tagData["Artist"];
    }
}
IAbstract
  • 19,551
  • 15
  • 98
  • 146
CodingWithSpike
  • 42,906
  • 18
  • 101
  • 138
  • Also, if you are using .NET4, then you could use a Tuple or an ExpandoObject or a dynamic... It would save you the trouble of explicitely defining a `TagData` type. – CodingWithSpike Jun 03 '11 at 17:55
0

Create a class called Tags or something similar with the properties you want. Return an instance of that with the properties set. Winforms doesn't do MVVM very well.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445