यहां मैंने बनाए गए कॉन्फ़िगरेशन सेक्शन का एक उदाहरण दिया है। आपको सही दिशा में इंगित करना चाहिए।
public class ImportConfiguration : ConfigurationSection
{
[ConfigurationProperty("importMap")]
public ImportMapElementCollection ImportMap
{
get
{
return this["importMap"] as ImportMapElementCollection;
}
}
}
public class ImportColumnMapElement : ConfigurationElement
{
[ConfigurationProperty("localName", IsRequired = true, IsKey = true)]
public string LocalName
{
get
{
return this["localName"] as string;
}
set
{
this["localName"] = value;
}
}
[ConfigurationProperty("sourceName", IsRequired = true)]
public string SourceName
{
get
{
return this["sourceName"] as string;
}
set
{
this["sourceName"] = value;
}
}
}
public class ImportMapElementCollection : ConfigurationElementCollection
{
public ImportColumnMapElement this[object key]
{
get
{
return base.BaseGet(key) as ImportColumnMapElement;
}
}
public override ConfigurationElementCollectionType CollectionType
{
get
{
return ConfigurationElementCollectionType.BasicMap;
}
}
protected override string ElementName
{
get
{
return "columnMap";
}
}
protected override bool IsElementName(string elementName)
{
bool isName = false;
if (!String.IsNullOrEmpty(elementName))
isName = elementName.Equals("columnMap");
return isName;
}
protected override ConfigurationElement CreateNewElement()
{
return new ImportColumnMapElement();
}
protected override object GetElementKey(ConfigurationElement element)
{
return ((ImportColumnMapElement)element).LocalName;
}
}
और यहाँ यह web.config में किया जा रहा है:
<importConfiguration>
<importMap>
<columnMap localName="PropertyID" sourceName="Detail Number"/>
<columnMap localName="DateOfOpen" sourceName="Open Date & Time"/>
<columnMap localName="StartTime" sourceName="Open Date & Time"/>
<columnMap localName="ClosingTime" sourceName="Close Date & Time"/>
<columnMap localName="StreetAddress" sourceName="Street Address"/>
</importMap>
</importConfiguration>
स्रोत
2011-11-02 15:46:25
+1 यह, इस और केवल इस। हालांकि, सबसे बुनियादी प्रकार के कॉन्फ़िगरेशन अनुभाग [कस्टम कॉन्फ़िगरेशन अनुभाग 3 आसान चरणों में] के थोड़ा कम शामिल अवलोकन के लिए (http://haacked.com/archive/2007/03/11/custom-configuration-sections-in- 3-आसान steps.aspx)। –