Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BindingContext tests and fix validation #577

Open
wants to merge 2 commits into
base: master
from

Conversation

Projects
None yet
1 participant
@hughbe
Copy link
Contributor

hughbe commented Mar 12, 2019

Fixes #576

@hughbe hughbe requested a review from dotnet/dotnet-winforms as a code owner Mar 12, 2019

@hughbe

This comment has been minimized.

Copy link
Contributor Author

hughbe commented Mar 12, 2019

Is the following dead code?

public static void UpdateBinding(BindingContext newBindingContext, Binding binding)
{
    if (binding == null)
    {
        throw new ArgumentNullException(nameof(binding));
    }

    BindingManagerBase oldManager = binding.BindingManagerBase;
    if (oldManager != null)
    {
        oldManager.Bindings.Remove(binding);
    }

    if (newBindingContext != null)
    {
        // we need to first check for cycles before adding this binding to the collection
        // of bindings.
        if (binding.BindToObject.BindingManagerBase is PropertyManager) // <-- HERE
        {
            CheckPropertyBindingCycles(newBindingContext, binding);
        }

        BindToObject bindTo = binding.BindToObject;
        BindingManagerBase newManager = newBindingContext.EnsureListManager(bindTo.DataSource, bindTo.BindingMemberInfo.BindingPath);
        newManager.Bindings.Add(binding);
    }
}

Its my understanding that calling oldManager.Bindings.Remove(binding) would set the BindingManagerBase to null, so binding.BindToObject.BindingManagerBase is PropertyManager is always false?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.