필자는 필수 요소인지 또는 키인지 나타내는 데코 레이팅 된 속성을 가진 ConfigElement를 가지고 있습니다. 이 키를 만들고 싶습니다. 그러나 사용자가 고유 한 키를 사용하도록 의존 할 필요가 없도록 키를 생성하는 방법은 무엇입니까? 나는 Guid.NewGuid()을 퍼팅 시도하지만, 기본 값이 일정하다고가 없다는 오류를 준 :ConfigurationProperty 키의 ID를 생성 하시겠습니까?
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;
}
}