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

  • Home
  • SEARCH
  • 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 9255483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:43:40+00:00 2026-06-18T11:43:40+00:00

Is there any way to call the CallCommonCode() attribute constructor automatically when CodedMethod() is

  • 0

Is there any way to call the CallCommonCode() attribute constructor automatically when CodedMethod() is called?

using System;

[AttributeUsage(AttributeTargets.Method|AttributeTargets.Struct,
                   AllowMultiple=false,Inherited=false)]
public class CallCommonCode : Attribute
{
    public CallCommonCode() { Console.WriteLine("Common code is not called!"); }
}

public class ConcreteClass {

  [CallCommonCode]
  protected void CodedMethod(){
     Console.WriteLine("Hey, this stuff does not work :-(");
  }
  public static void Main(string[] args)
  {
     new ConcreteClass().CodedMethod();
  }
}
  • 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-18T11:43:41+00:00Added an answer on June 18, 2026 at 11:43 am

    No, because the attribute exists independently of the function. You can scan for the attribute or you can execute the function, but you can’t do both at the same time.

    The point of an attribute is just to tag stuff with extra metadata, but it’s not strictly speaking actually part of the code itself.

    What you would normally do in this situation is scan for the tag on the function, and if it goes against your business logic, you would throw some sort of exception. But in general, an attribute is just a ‘tag’.

    class Program
    {
        [Obsolete]
        public void SomeFunction()
        {
    
        }
    
        public static void Main()
        {
            // To read an attribute, you just need the type metadata, 
            // which we can get one of two ways.
            Type typedata1 = typeof(Program);       // This is determined at compile time.
            Type typedata2 = new Program().GetType(); // This is determined at runtime
    
    
            // Now we just scan for attributes (this gets attributes on the class 'Program')
            IEnumerable<Attribute> attributesOnProgram = typedata1.GetCustomAttributes();
    
            // To get attributes on a method we do (This gets attributes on the function 'SomeFunction')
            IEnumerable<Attribute> methodAttributes = typedata1.GetMethod("SomeFunction").GetCustomAttributes();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way of finding the signature of a called method through call
Is there any way to call canvas functions using apply() or a similar method,
Is there any way to call method by name and specify arguments without using
Opah! Is there any way I can call a method in the controller through
Is there any way to tell db4o to call class default constructor while activating
Is there any way to call the init () method of a class only
I'm using VBScript and I am wondering if is there any way to call
std::vector::erase() does not accept reverse iterator. Is there any way to call this method
Is there any way that you can call a function after its getView method
Is there any way to call from javascript to actionscript, not using JSON object.

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.