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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:33:57+00:00 2026-06-09T11:33:57+00:00

I have a ConfigElement with decorated property indicating if it is required or a

  • 0

I have a ConfigElement with decorated property indicating if it is required or a key. I would like to make this a key, but how do I generate a key so I don’t have to depend on the user to come up a unique key? I tried putting Guid.NewGuid(), but it gave an error saying the default value has to be a constant:

An attribute argument must be a constant expression, 
typeof expression or array creation expression of an attribute parameter type

Here is what my class looks like:

public class MyEntryElement : ConfigElement
{
    #region Constructor

    public MyEntryElement(ConfigElement parent)
        : base(parent)
    {
    }

    #endregion

    #region Properties

    [ConfigurationProperty("id", DefaultValue = Guid.NewGuid(), IsRequired = true, IsKey = true)]
    [ObjectInfo(Title = "ID", Description = "Defines the id of the entry.")]
    public string ID
    {
        get
        {
            return (string)this["id"];
        }
        set
        {
            this["id"] = value;
        }
    }

    [ConfigurationProperty("note", DefaultValue = "", IsRequired = true)]
    [ObjectInfo(Title = "Note", Description = "Defines the note of the entry.")]
    public string Note
    {
        get
        {
            return (string)this["note"];
        }
        set
        {
            this["note"] = value;
        }
    }
  • 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-09T11:33:58+00:00Added an answer on June 9, 2026 at 11:33 am

    How about setting it in your constructor:

        public MyEntryElement(ConfigElement parent)
            : base(parent)
        {
            if ( String.IsNullOrEmpty(ID) )
            {
                ID = Guid.NewGuid().ToString();
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have converted devise new session from erb to Haml but doens't work, this is
have a php code like this,going to convert it in to C#. function isValid($n){
Totally confused about the data types required here. I have this Linq statement: var
Have a xml data like <Items><Item><name>test1</name></Item><Item><name>test2</name></Item></Items> Looks like jaxb cannot unmashall this when defining
Have a recurring situation, petty I know, but I'd like to consolidate the following:
Have I lost it, but if feels like I remember doing something along the
have an XML file like this: <VS> <Fields> <Field Id=$1*>Column1</Field> <Field Id=$2*>Column2</Field> <Field Id=$3*>Column3</Field>
have written this little class, which generates a UUID every time an object of
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:

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.