Sarav
Sarav

Reputation: 149

Is it possible to set compiler warning where a specific value is passed to method?

I tried searching through internet , but not able to get anything.

I have a method with a Boolean default parameter , i want to find places where they are specifically sending value other than the default value with a compiler warning.

public example(SomeObject value , IsChecked = false )

How to find places , where they send IsChecked as true without giving find all references.

Cannot specify the whole method as obsolete , Need to find way to specify parameter value as obsolete ( only primitive parameter and static values , not using any run time evaluated variables also ).

Upvotes: 1

Views: 172

Answers (1)

Hans Kilian
Hans Kilian

Reputation: 25144

You can create a second method without the IsChecked parameter and then mark the old method as obsolete, like this:

[Obsolete("Using IsChecked is obsolete")]
public example(SomeObject value , IsChecked = false )
{
}

public example(SomeObject value )
{
}

then if you use the old method, you'll get a warning that it's obsolete.

Upvotes: 2

Related Questions