mardi 20 juin 2017

Xamarin Form: Why the code still get pass if statement even though it's false

I have a strange behaviour when running on iPad when debugging. I have a false primitives in if-statement purposely. When I run the application the code inside if-statement still get executed even though it was false.

public async Task<CommonResult<bool>> SaveNote(int siteId, IList<ParentNote> notes, Func<int, Task<bool>> progress = null)
    {
        foreach (var note in notes)
        { 
            App.DB.SaveOrUpdate<ParentNote>(note);
            var isContinue = await progress?.Invoke(1);
            if (false) 
            {
                AppLogger.Instance.AddLog(AppLogLevel.Warning,
                                          nameof(ParentBLL),
                                          nameof(SaveNote),
                                        "Save parent note task terminated", "");
                return null;
            }
        }

        return new CommonResult<bool> { IsSuccess = true, Data = true };
    }

Aucun commentaire:

Enregistrer un commentaire