Coder Social home page Coder Social logo

Comments (5)

picrap avatar picrap commented on September 21, 2024 1

If your NotEmpty and FileExist are advices, it means they are classes. If you apply Priority to them, you don’t need to do anything else. Each time those two will be applied somewhere (class, parameter…), they will be sorted so NotEmpty will be processed first. If not, that’s a bug 😉

from mradvice.

picrap avatar picrap commented on September 21, 2024

Hi. Unfortunately .NET does not guarantee attributes order, this is why Mr. Advice has the [Priority] attribute you’ve always dreamed of 😎.
Apply it to your advices, specify a value (higher value means higher priority). See https://github.com/ArxOne/MrAdvice/wiki/ImplementingAdvices#markers-for-advices for a few more details.

from mradvice.

Vandmand42 avatar Vandmand42 commented on September 21, 2024

Many thanks for your answer which explains the behavior of .NET. I just had a look into it and noticed that it is only applicable on class and structs. Is there a way to support the priority of attributes on parameters?

from mradvice.

picrap avatar picrap commented on September 21, 2024

Priority is on advices, so apply it on advices, and apply advices to your parameters.

from mradvice.

Vandmand42 avatar Vandmand42 commented on September 21, 2024

I am aware that the priority is on advices, but as I mentioned before is that the usage is limited to only classes and structs, which is also stated in the PriorityAttribute.cs Code:

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)]
public class PriorityAttribute : Attribute

With the example from beginning: DoSomethingWithAFile([NotEmpty(2)][FileExist(1)] string filepath) (Now with the priority)
I have implemented the priority attribute via inheritance, with the change of the target to AttributeTargets.Parameter without any different results, except the removal of the error message and the same behavior in random order.

Therefore it gives an error if applied on parameter scope. The limited target must be there for some reason and I don't know if I am missing something here.

Many thanks for your reply in advance and sorry for the inconvenience.

from mradvice.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.