Tester.Winform codes error

Issue #8 resolved
Kenny Hsu created an issue

The method LoadSourceCaps() in your TestForm class, should the if statement code

if (groupDepth.Enabled = caps.Contains(CapabilityId.ICapPixelType))

be

if (groupDepth.Enabled == caps.Contains(CapabilityId.ICapPixelType))

? Same with other if statements in the same method.

Comments (4)

  1. Eugene Wang repo owner

    No this is by design. It's enabling/disabling the control first and using that result in the if condition next.

    It's the equivalent of these 2 lines

    bool enabled = groupDepth.Enabled = caps.Contains(CapabilityId.ICapPixelType);
    if (enabled) ...
    
  2. Kenny Hsu reporter

    The single equal ("=") means assign, and the double equal ("==") means compare. I think the if statement should use the double equal ("=="), otherwise the project will show compile error. Am I right?

  3. Eugene Wang repo owner

    Assign is correct. The control needs to be enabled/disabled with cap.Contains() check first and then the condition tests for that result. Equality means the groupDepth control somehow already knows the result, which is not the case.

    This is probably clearer than the example before

    groupDepth.Enabled = caps.Contains(CapabilityId.ICapPixelType);
    if (groupDepth.Enabled) ...
    
    // is equivalent to
    if (groupDepth.Enabled = caps.Contains(CapabilityId.ICapPixelType))
    
  4. Log in to comment