Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8745757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:05:12+00:00 2026-06-13T12:05:12+00:00

I created a custom attribute class that will check the system security and throws

  • 0

I created a custom attribute class that will check the system security and throws an authentication exception if there is a security error.

public class EntityChecker: System.Attribute
{
    public EntityChecker(int entityId)
    {
        // doing some logic to check if the entityId is allowed to be inserted
    }
}

I want to use this custom attribute as a declaration to an entity addition function and I want to pass a variable from the function to the attribute constructor. can something like this be done?

[EntityChecker(entityId)]
public int AddNewEntity(entityId)
{
 // logic of entity addition
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:05:13+00:00Added an answer on June 13, 2026 at 12:05 pm

    Can something like this be done ?!

    No. Constructor parameters in attributes must be resolved at compile time. They are intended as metadata on the type or method itself, not something that would be used per call or per instance.

    Given your description, an attribute is likely not an appropriate way to handle this. Since you want to run extra code that happens per call, you will need a different technique. For example, you could pass a delegate, ie:

    public int CheckedAddEntity(int entityId, Func<int, int> funcToAdd)
    {
        // Perform your checking on entityId here
        return funcToAdd();
    }
    

    This would let you then call via something like:

    int result = CheckedAddEntity(entityId, AddNewEntity);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to create a custom attribute that will make EF CodeFirst
I've created a custom UITypeEditor. Can I possibly insert an attribute that also attaches
I have created a custom Attribute to decorate a number of classes that I
I have created the following custom ValidationAttribute: public class DateRangeAttribute : ValidationAttribute, IClientValidatable {
I created a simple custom attribute on the sales/order entity. Now, for new orders,
(Magento Version 1.6) I'm trying to display a custom category attribute I created to
I have created custom cell in which there are n number of image views.
I want to create a custom attribute that can be used on a property
I have created a custom validation attribute by subclassing ValidationAttribute. The attribute is applied
I'm trying to make a simple link that will toggle my status attribute in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.