mercredi 8 novembre 2017

Assign value to object based on condition

I am using the below method to assign value to my object(Team.Driver/Team.Codriver). This works fine but jut wanted to know if I could improve this code via LINQ or other options.

public void MoveDriverCodriver(
    Team source, string sourceType, Team target, string targetType) 
{
    if (sourceType == "Driver")
    {
        if (targetType == "Driver")
        {
            target.Driver = source.Driver;
        }
        else
        {
            target.Codriver = source.Driver;
        }
    }
    else
    {
        if (targetType == "Driver")
        {
            target.Driver = source.Codriver;
        }
        else
        {
            target.Codriver = source.Codriver;
        }
    } 
}

Aucun commentaire:

Enregistrer un commentaire