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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:09:49+00:00 2026-05-28T16:09:49+00:00

I’m coding custom attributes instead marker interfaces public class FooAssignableAttribute : Attribute { …

  • 0

I’m coding custom attributes instead marker interfaces

public class FooAssignableAttribute : Attribute  
{ 
    ... 
} 

[FooAssignable] 
public class Foo  
{     
   ... 
} 

Can’t I code a dictionary like this?

Dictionary<string, FooAssignable> dictionary;

Avoiding marker interfaces, I’m trying to use custom attrutes. Why can’t I write the above code?

  • 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-05-28T16:09:50+00:00Added an answer on May 28, 2026 at 4:09 pm

    No, this doesn’t work. The parametric types of a generic collection (or other generic) in C# must be declarable types, and attributes exist only as metadata.

    You cannot have an object of type FooAssignable. You can have an object that has the attribute FooAssignable, but this isn’t the same as having it as a supertype. FooAssignable is not a class or interface, and isn’t a valid type specifier. FooAssignableAttribute is, but that is the type that refers to the attribute itself, not items tagged with that attribute.

    Consider that in a Dictionary, the out type for the indexer is the out type you’ve provided. But you can’t have a variable of type FooAssignable- you can have a variable of a type that has been tagged with FooAssignable, but there is no single base class that all those types fit. Since that type declaration is illegal, this Dictionary would have an illegal, nonexistent type as the return type for the getter from its indexer, among many other places. A C# type check cannot be spontaneously replaced via generic mechanisms with an attribute presence check.

    Anything you want the type system to check for you has to be part of the type system. Attribute evaluation does not define types, so the type system can’t do this for you; meanwhile, generics are the part of the language that most directly interacts with the type system. You’ll have to actually go through the type system to perform a check like this, and that does mean promoting FooAssignableAttribute to an interface (IFooAssignable?) instead.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
Does anyone know how can I replace this 2 symbol below from the string
I'm making a simple page using Google Maps API 3. My first. One marker
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

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.