tags:

views:

66

answers:

2

I have a Method which Takes Int as Input

public void GetMonth(int Month) { }

Now when I call this method I want to make sure that Compiler generates and Error Message when someone enters number which does not fall between 1-12.

e.g

obj.GetMonth(14)--Here it should give error and does not compile

Is it possible ?

+3  A: 

That will be a feature in 4.0, thanks to code-contracts, which allow you to declare exactly that. But not yet. You'll need to have validation code at runtime:

if(month < 1 || month > 12) throw new ArgumentOutOfRangeException("month");
Marc Gravell
A: 

Maybe by using Microsoft.Build.Utilities.Task but it sounds like hard tasks.
This class can help to generate build time errors.
But the really hard part, is to make code analysis to decide when you need to stop the build.

Avram