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 182257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:54:28+00:00 2026-05-11T14:54:28+00:00

In other words could it be possible to create assembly, which does not even

  • 0

In other words could it be possible to create assembly, which does not even compile (assuming the checking code is not removed ) if each one of the Classes does not have ( ‘must have’ ) custom attributes ( for example Author and Version ) ?

Here is the code I have used for querying during run time :

using System; using System.Reflection; using System.Collections.Generic;    namespace ForceMetaAttributes {      [System.AttributeUsage ( System.AttributeTargets.Method, AllowMultiple = true )]     class TodoAttribute : System.Attribute     {         public TodoAttribute ( string message )         {             Message = message;         }         public readonly string Message;      }      [System.AttributeUsage ( System.AttributeTargets.Class |         System.AttributeTargets.Struct, AllowMultiple = true )]     public class AttributeClass : System.Attribute     {         public string Description { get; set; }         public string MusHaveVersion { get; set; }           public AttributeClass ( string description, string mustHaveVersion )          {             Description = description;              MusHaveVersion = mustHaveVersion ;          }      } //eof class        [AttributeClass('AuthorName' , '1.0.0')]     class ClassToDescribe     {         [Todo ( ' A todo message ' )]         static void Method ()         { }     } //eof class       //how to get this one to fail on compile      class AnotherClassToDescribe     {       } //eof class   class QueryApp {         public static void Main()         {                  Type type = typeof(ClassToDescribe);                 AttributeClass objAttributeClass;                   //Querying Class Attributes                  foreach (Attribute attr in type.GetCustomAttributes(true))                 {                         objAttributeClass = attr as AttributeClass;                         if (null != objAttributeClass)                         {                                 Console.WriteLine('Description of AnyClass:\n{0}',                                                                      objAttributeClass.Description);                         }                 }                    //Querying Class-Method Attributes                    foreach(MethodInfo method in type.GetMethods())                 {                         foreach (Attribute attr in method.GetCustomAttributes(true))                         {                                 objAttributeClass = attr as AttributeClass;                                 if (null != objAttributeClass)                                 {                                         Console.WriteLine('Description of {0}:\n{1}',                                                                              method.Name,                                                                              objAttributeClass.Description);                                 }                         }                 }                 //Querying Class-Field (only public) Attributes                  foreach(FieldInfo field in type.GetFields())                 {                         foreach (Attribute attr in field.GetCustomAttributes(true))                         {                                 objAttributeClass= attr as AttributeClass;                                 if (null != objAttributeClass)                                 {                                         Console.WriteLine('Description of {0}:\n{1}',                                                                             field.Name,objAttributeClass.Description);                                 }                         }                 }                 Console.WriteLine ( 'hit Enter to exit ' );                 Console.ReadLine ();         } //eof Main  } //eof class   } //eof namespace    //uncomment to check whether it works with external namespace  //namespace TestNamespace {  //  class Class1 { } //  class Class2 { }  //} 

Edit: Just to justify my choice for answer. I think casperOne provided the correct answer of the question.

However the reasons for asking the question seemed to be weak. Probably I should start to use some external tool such as : FinalBuilder or create unit tests checking for this ‘requirement’, using Pex , Nunit or other unit testing frameworks …

EDIT I added a small code snippet of a console program at the end of the answers that performs the check … feel free to comment, criticize or suggest improvements
Once more I realized that this ‘requirement’ should be implemented as part of the unit testing just before the ‘check in’

  • 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. 2026-05-11T14:54:29+00:00Added an answer on May 11, 2026 at 2:54 pm

    No, it is not possible to hook into the compilation of the assembly and check if it exists.

    However you can hook into the build process, which is made up of more than just running the compiler. You could create a custom MSBUILD task (or NAnt, if you are using that) which checks the assembly through reflection after it is built and then fail the build if it doesn’t have the required attributes.

    Of course, you should probably still verify this in code as well. What you are trying to do is not a good substitute for a proper runtime check.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 98k
  • Answers 98k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Instead of adding items directly to the Dropdown, I would… May 11, 2026 at 7:37 pm
  • Editorial Team
    Editorial Team added an answer Some of the things I use jQuery for are: simplified… May 11, 2026 at 7:37 pm
  • Editorial Team
    Editorial Team added an answer Well, definitly a bug : http://code.google.com/p/android/issues/detail?id=2516. Hope it will be… May 11, 2026 at 7:37 pm

Related Questions

I need to write a function that takes 4 bytes as input, performs a
My program that I am writing's purpose arose with this issue: There are two
I have a problem in a Windows Forms application with Bitmap.Save failing when I
I have a repository class that defines some basic Get/Save/Delete methods. Inside these, I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.