# EnabledIf Attribute in Mixins

**URL:** <https://forum.opentap.io/t/enabledif-attribute-in-mixins/1333>\
**Category:** Technical\
**Created:** [December 22, 2023, 12:18pm UTC](https://forum.opentap.io/t/enabledif-attribute-in-mixins/1333 "2023-12-22T12:18:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![btyilmaz](https://avatars.discourse-cdn.com/v4/letter/b/a3d4f5/32.png) [@btyilmaz](https://forum.opentap.io/u/btyilmaz)\
**Post date:** [December 22, 2023, 12:18pm UTC](https://forum.opentap.io/t/enabledif-attribute-in-mixins/1333/1 "2023-12-22T12:18:18Z")

</div>

Hi everyone,

I wanted to develop a mixin that has multiple properties with EnabledIf attributes such as:

```csharp
public class TestMixin : ITestStepPostRunMixin
{
    [Browsable(false)]
    public bool IsEnabled { get; set; }

    [EnabledIf(nameof(IsEnabled), true, HideIfDisabled = true)]
    public string String1 { get; set; }

    [EnabledIf(nameof(IsEnabled), false, HideIfDisabled = true)]
    public string String2 { get; set; }

    public TestMixin(bool isEnabled)
    {
        IsEnabled = isEnabled;
    }

    public void OnPostRun(TestStepPostRunEventArgs eventArgs)
    {
        
    }
}

[MixinBuilder(typeof(ITestStepParent))]
public class TestMixinBuilder : IMixinBuilder
{
    public bool IsEnabled{ get; set; }
    public void Initialize(ITypeData targetType)
    {

    }

    public MixinMemberData ToDynamicMember(ITypeData targetType)
    {
        return new MixinMemberData(this, () => new TestMixin(IsEnabled))
        {
            TypeDescriptor = TypeData.FromType(typeof(TestMixin)),
            Attributes = GetAttributes(),
            Writable = true,
            Readable = true,
            DeclaringType = targetType,
            Name = "TestMixin"
        };
    }

    IEnumerable<Attribute> GetAttributes()
    {
        yield return new EmbedPropertiesAttribute();
        yield return new DisplayAttribute("Repeat Mixin", Order: 20000);
    }
}

```

Problem with this mixin is that when I **modify** the mixin from the menu command, EnabledIf attribute does not work, visibility of the properties are not changed.

This mixin works fine when it is directly embedded to a test step using [EmbedAttribute].

**Edit:**  
This issue also exists for Basic Mixins plugin. When you modify a mixin, property on the Test Step Settings panel is not updated.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/opentap/original/1X/318bbe30dd07036c2d15dce538fcfdb76a2b04fe.png)

---

<div class="post-metadata">

**Author:** ![rolf\_madsen](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@rolf\_madsen](https://forum.opentap.io/u/rolf_madsen)\
**Post date:** [January 3, 2024, 4:26pm UTC](https://forum.opentap.io/t/enabledif-attribute-in-mixins/1333/2 "2024-01-03T16:26:08Z")

</div>

hi @btyilmaz,

Thanks for highlighting this!

Can you open an issue on [github](https://github.com/opentap/opentap). That way we can track it and make sure it gets fixed in a future version.

---

<div class="post-metadata">

**Author:** ![btyilmaz](https://avatars.discourse-cdn.com/v4/letter/b/a3d4f5/32.png) [@btyilmaz](https://forum.opentap.io/u/btyilmaz)\
**Post date:** [January 4, 2024, 5:31am UTC](https://forum.opentap.io/t/enabledif-attribute-in-mixins/1333/3 "2024-01-04T05:31:05Z")

</div>

Hi @rolf_madsen ,

I opened an issue. Issue number is [1372](https://github.com/opentap/opentap/issues/1372)

---

<div class="post-metadata">

**Author:** ![rolf\_madsen](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@rolf\_madsen](https://forum.opentap.io/u/rolf_madsen)\
**Post date:** [January 4, 2024, 3:06pm UTC](https://forum.opentap.io/t/enabledif-attribute-in-mixins/1333/4 "2024-01-04T15:06:27Z")

</div>

Thanks, @btyilmaz! ⭐ ⭐ ⭐
