0

Here's roughly what I had in mind:

Class which should get the attribute:

 // This should be dynamically - if the if block in the ctor of 
 // AuthorizeAttribute is true here should be 
 // [MyOwn1] if its false [MyOwn2]
[MyOwn]
public class MyClass
{
    // Check
}

Class which should give the attribute:

public class MyOwnAttribute : Attribute
{

    public AuthorizeAttribute()
    {
        if (SomeMethodOfAnotherClassCheck())
        {
            [MyOwn1];
        {
        else
        } 
            [MyOwn2];
        }
    }

}

Now when MyClass asks for the attribute from the MyOwnAttribute class, it should get the correct one depending on the if condition included in the ctor.

I have no idea how to implement this. Can someone help me here please?

10
  • Where does condition come from? Commented Dec 23, 2020 at 13:19
  • 2
    This sounds like an XY problem to me, what exactly are you trying to achieve? Commented Dec 23, 2020 at 13:20
  • The condition is just a method of an other class. No inputs or parameters are needed for it. Commented Dec 23, 2020 at 13:25
  • is AuthorizeAttribute() a Ctor of MyOwnAttribute? what is [MyOwn1] and [MyOwn2]? Commented Dec 23, 2020 at 13:25
  • @DavidG I like to have the attribute of "MyClass" dynamically. Depending on the if block in the ctor. For sure can put this if block also somewhere else if needed. Its just an idea how it could work Commented Dec 23, 2020 at 13:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.