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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:12:49+00:00 2026-05-11T02:12:49+00:00

I wish to set an attribute on a public property in .NET, however I

  • 0

I wish to set an attribute on a public property in .NET, however I do not have access to the explicit property itself, as this has been code generated in another file.

I have this field:

public virtual string Name { get; set; } 

I wish to set this:

[ValidateNonEmpty('Name is required', ExecutionOrder = 1)] public virtual string Name { get; set; } 

My class is marked as partial, but you cannot have partial properties. I thought I was on to something with the MetadataType class which is a new feature of Dynamic Data and DataAnnotations, but alas I feel it can only be used with Dynamic Data, is this true?

Citations: http://blogs.oosterkamp.nl/blogs/jowen/archive/2008/10/16/metadatatype-attribute.aspx http://blogs.msdn.com/davidebb/archive/2008/06/16/dynamic-data-and-the-associated-metadata-class.aspx

Is there any way I can set this attributes (even through web.config!) without touching the code generated class?

Thanks in advance, Graham

  • 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-11T02:12:50+00:00Added an answer on May 11, 2026 at 2:12 am

    This is a known nuisance; you simply can’t add metadata to the generated members.

    There are 6 options here (in order of increasing effort):

    • if you own the attribute, make it possible to declare it against the class, for example: [ValidateNonEmpty('Name', 'Name is required', ExecutionOrder = 1)] – then add multiple attributes to the partial class definition
    • use a virtual / interface / etc method to query this, rather than via attributes
    • sublass the generated type; override or re-declare the member, adding the metadata (really messy)
    • use a custom TypeDescriptionProvider to provide dynamic metadata (lots and lots of work) – assuming that the consumer respects TypeDescriptor; most binding-related consumers do, but for example, Expression (used by many LINQ providers) doesn’t
    • change the code-generator / write your own
    • try to extend something like PostSharp to do the work (I haven’t found a way to do this, but I’ve love to hear if you find a way!)

    I usually have success with the first option, unless it is a system-defined attribute ([DisplayName], etc). If [ValidateNonEmpty] is defined by dynamic data, then you might not be able to do this.

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

Sidebar

Ask A Question

Stats

  • Questions 73k
  • Answers 74k
  • 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
  • added an answer I think I've found the cause, but I'll post it… May 11, 2026 at 2:12 pm
  • added an answer try this: int stateID = getTheStateIDToLookup(); State state = dc.States.SingleOrDefault(s… May 11, 2026 at 2:12 pm
  • added an answer You can do this in SubSonic 3.0 (not yet released,… May 11, 2026 at 2:12 pm

Related Questions

I wish to set a usererror string before leaving a function, depending on the
I wish to know all the pros and cons about using these two methods.
I wish to implement a 2d bit map class in Python. The class would
I wish to implement my software on a shareware basis, so that the user
I am essentially trying to create a version of the figure element (upcoming in
In a .NET 1.0 C# application, I wish to display a list of files
I would like to evaluate an environment variable and set the result to a
I have a table that I need to extract data from, and wish to

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.