2

Powershell offers a ValidateScript parameter attribute to check given attributes. Example:

function foo{
    Param(
       [ValidateScript({Test-Path $_ -PathType Leaf})] 
       [string]
       $FilePath,
    ....

Is there an equivalent available in C#, to validate parameters of a method? So that I can define a method in c# like:

...
public static string Foo (
   [Validate(p => p <1)]
   int p) {
   ...
}
4
  • Please share some more light on what this param does for PS. Commented Feb 24, 2017 at 15:09
  • Yes, of cause. Here is a link. Powershell is built on .NET Framework, so it can access all classes of standart library. Also, check this answer, maybe it can help you. Commented Feb 24, 2017 at 15:10
  • The closest thing in c# are Code Contracts. Commented Feb 24, 2017 at 15:13
  • @Igor: I`ve update my question. I'm interested at parameter checking "just in general". Commented Feb 24, 2017 at 15:14

1 Answer 1

0

Check namespace Dataannotation namespace in c# this will validate property with the help of attribute.

Sign up to request clarification or add additional context in comments.

Comments

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.