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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:33:58+00:00 2026-05-23T02:33:58+00:00

I have the below code which I’m using to try to apply custom attributes

  • 0

I have the below code which I’m using to try to apply custom attributes to fields in a declared class. I get the error below against the words ‘FileType’ and ‘AllowNulls’ in the declaration (noted below)

Error 3 ‘FieldType’ is not a valid named attribute argument. Named attribute arguments must be fields which are not readonly, static, or const, or read-write properties which are public and not static. F:\Dropbox\Dev_LN Projects\02 Scrap\TestFieldAttributes\TestFieldAttributes\Program.cs 61 34 TestFieldAttributes

I’ve tried various combinations of removing static, readonly etc but no luck. Any thoughts? Thanks

[AttributeUsage(AttributeTargets.Field)]
public class DBDataTypeAttribute : System.Attribute
{
    private string fieldtype;
    public string FieldType
    {
        get { return fieldtype; }
    }

    private string allownulls;
    public string AllowNulls
    {
        get { return allownulls; }
    }

}

public class ExpenseReport
    {
        [FieldQuoted('"', QuoteMode.OptionalForRead, MultilineMode.AllowForRead)]
        [DBDataTypeAttribute(FieldType = "varchar(1000)", AllowNulls = "true")]// errors on this line
        public String UniqueID;
        [FieldQuoted('"', QuoteMode.OptionalForRead, MultilineMode.AllowForRead)]
        public String ERNum;
    }

Thanks!

  • 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-23T02:33:58+00:00Added an answer on May 23, 2026 at 2:33 am

    Your properties are read-only, and named arguments for an attribute must be read/write, so you must add a set method to the properties.

    If you want to use read-only properties, you should use constructor arguments for the attribute rather than named arguments.

    This means you could use either this:

    [AttributeUsage(AttributeTargets.Field)]
    public class DBDataTypeAttribute : System.Attribute
    {
        private readonly string _fieldType;
        private readonly bool _allowNulls;
    
        public DBDataTypeAttribute(string fieldType, bool allowNulls)
        {
            _fieldType = fieldType;
            _allowNulls = allowNulls;
        }
    
        public string FieldType 
        {
            get { return _fieldType; } 
        } 
    
        public bool AllowNulls
        { 
            get { return _allowNulls; }
        } 
    }
    

    Or this:

    [AttributeUsage(AttributeTargets.Field)]
    public class DBDataTypeAttribute : System.Attribute
    {
        public string FieldType { get; set; }
        public bool AllowNulls { get; set; }
    }
    

    Note: I used automatic properties for the latter example, but not the former, because I prefer making the fields readonly too in an attribute (readonly fields cannot be modified except in the constructor). I also changed AllowNulls to a bool since I see no reason for it to be a string.

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

Sidebar

Related Questions

I have the below code, which iterates over a list based on a custom
i have got below code which is working fine: public abstract class Beverage {
I am using JQuery. I have below JQuery Code which working fine in Firefox,
I have the below code for my a Dialog box for a which contains
I have below is the html code for TD which gets appended after matching
So far i have got the code below which works lovely when trying an
I have the code below, which works fine it can be viewed for an
I have the code below, which sends the value of the textarea and either
I have a code like this below, which gives me a $link that equals
I have below code in html. <li class=selected runat=server id=lihome><a href=/ISS/home.aspx title=Home><span>Home</span></a></li> Now I

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.