user7586639
user7586639

Reputation:

Working with Attributes

How can I mark that MyClass is not possible to be reviewed but has a test suit.

public class MyClass
{

}

public class MyAttribute : System.Attribute
{
    bool Reviewed { get; set; }
    bool HasTestSuit { get; set; }
}

Upvotes: 0

Views: 81

Answers (2)

Pavan Chandaka
Pavan Chandaka

Reputation: 12731

try this.

Declare a constructor in MyAttribute class.

public class MyAttribute : System.Attribute
{
    bool Reviewed { get; set; }
    bool HasTestSuit { get; set; }

    public MyAttribute(bool hasReviewed,bool hasTestSuite)
    {
            this.Reviewed = hasReviewed;
            this.HasTestSuit  = hasTestSuite;
    }   
}

Now set the attribute as shown below.

[MyAttribute(false, true)]
public class MyClass
{

}

You can understand more on custom attributes by walking through the below link.

https://msdn.microsoft.com/en-us/library/84c42s56(v=vs.110).aspx

Upvotes: 1

CharithJ
CharithJ

Reputation: 47510

[MyAttribute(false, true)]
public class MyClass
{

}

public class MyAttribute : System.Attribute
{
    public MyAttribute(bool reviewed, bool hasTestSuit)
    {
        this.Reviewed = reviewed;
        this.HasTestSuit = hasTestSuit;
    }

    bool Reviewed { get; set; }
    bool HasTestSuit { get; set; }
}

Upvotes: 0

Related Questions