Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameter for Parameter Advice #168

Closed
Sago92 opened this issue Nov 10, 2020 · 2 comments
Closed

Parameter for Parameter Advice #168

Sago92 opened this issue Nov 10, 2020 · 2 comments

Comments

@Sago92
Copy link

Sago92 commented Nov 10, 2020

Hello,

we want to integrate Mr. Advise into our company Framework. Our goal is it to reduce the parameter validation with a simple advice before a paramter.

Example before Mr. Advice:
public static int GetNumberOfPages(string sourceFilePath)
{
// Validation
if (String.IsNullOrEmpty(sourceFilePath))
throw new ArgumentNullException(nameof(sourceFilePath));
if (!File.Exists(sourceFilePath))
throw new FileNotFoundException(nameof(sourceFilePath));
...

Exmaple after Mr. Advid:
public static int GetNumberOfPages([PathNull][FileExist]string sourceFilePath) { ...

In some of our validations we, for example, check an integer for a range (like 1-100 or 1 - 65535). To realize that we have to create an advice for each range.

Is there a way to pass values into the adivce?

For exmaple like that?

public static int CreatePort([Range(1, 65535)]int port)
{
...

@picrap
Copy link
Member

picrap commented Nov 11, 2020

Hi, did you try? Advices are attribute, so adding parameters to a constructor or in public properties should work.

@Sago92
Copy link
Author

Sago92 commented Nov 12, 2020

Coulnd't see the wood for the trees ... I am sorry for opening this issue. Adding a constructor to the Advice works perfectly fine to pass parameters.

@Sago92 Sago92 closed this as completed Nov 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants