Change TagLib tag depending on string

117 Views Asked by At

I'm working on an audio tagger and one of its features is basically detecting if the checkbox with the tag name is checked and if the value in the textbox is changed.

This is the code I used so far:

if (chbAlbum.Checked == true && tbAlbum.Text != musFileTag.Album) { 
    fileStatus(3);
    tsbCloseFile.Enabled = false; 
} 
else {
    fileStatus(2); 
    tsbCloseFile.Enabled = true; 
}

now I'm switching to custom void:

void Checker(CheckBox chBox, TextBox tBox, String stringTag) {
    var musFileTag = TagLib.File.Create(musFileName).Tag;
    if (chBox.Checked == true && tBox.Text != musFileTag) { 
        return;
    }
}

how can I determine what tag it will be using from a string?

Normally to get an album tag I would use musFileTag.Album and for artist musFileTag.Performers but I need to determine the tag type from the string (something like musFileTag.{stringTag})

1

There are 1 best solutions below

0
Písek Pískovec On BEST ANSWER

In the end, I used a switch:

Boolean Checker(String stringTag) {
       var musFileTag = TagLib.File.Create(musFileName).Tag;
       bool returningValue = false;

       switch (stringTag)
       {
           case "album":
               if(chbAlbum.Checked == true && tbAlbum.Text != musFileTag.Album) {returningValue = true; }
               break;
       }
}