0
我有一个装饰属性ConfigElement指示是否需要或一个关键。我想将其作为关键,但是如何生成密钥以便我不必依靠用户来创建唯一密钥?我试图把Guid.NewGuid(),但它给了一个错误说的默认值必须是一个常数:为ConfigurationProperty密钥生成ID?
An attribute argument must be a constant expression,
typeof expression or array creation expression of an attribute parameter type
这里是我的课是什么样子:
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;
}
}