오히려 당신의 값이 문자열 분할 작업의 올바른 인덱스에 떨어 필요에 의존하는 것보다, 당신은 당신의 자신의 ConfigurationSection
정의를 작성해야합니다.
How To on MSDN 및 MSDN ConfigurationProperty example을 참조하십시오. 당신이 당신의 사용자 정의 구성이 지정되면
class CustomConfig : ConfigurationSection
{
private readonly CustomElementCollection entries =
new CustomElementCollection();
[ConfigurationProperty("customEntries", IsDefaultCollection = true)]
[ConfigurationCollection(typeof(CustomElementCollection), AddItemName = "add")]
public CustomElementCollection CustomEntries { get { return entries; } }
}
class CustomElementCollection : ConfigurationElementCollection
{
public CustomElement this[int index]
{
get { return (CustomElement) BaseGet(index); }
set
{
if (BaseGet(index) != null)
{
BaseRemoveAt(index);
}
BaseAdd(index, value);
}
}
protected override ConfigurationElement CreateNewElement()
{
return new CustomElement();
}
protected override object GetElementKey(ConfigurationElement element)
{
return ((CustomElement)element).Name;
}
}
class CustomElement : ConfigurationElement
{
[ConfigurationProperty("name", IsRequired = true)]
public string Name
{
get { return this["name"] as string; }
set { this["name"] = value; }
}
[ConfigurationProperty("direction", IsRequired = true)]
public string Direction
{
get { return this["direction"] as string; }
set { this["direction"] = value; }
}
[ConfigurationProperty("filePath", IsRequired = true)]
public string FilePath
{
get { return this["filePath"] as string; }
set { this["filePath"] = value; }
}
}
다음 할 수있는 사용자 정의 ConfigurationElement
에 지정된 속성을 사용하여 람다와 Select
: 여기
당신이 시작하는 몇 가지 코드입니다.
ConfigurationManager를 사용하여 app.config에서 값을 가져올 수 있습니다. 이 솔루션과 함께 가고 싶다면 -이 구조의 모든 항목, 즉 소스, 무언가, 숫자, 숫자, 경로입니까? 그렇다면 객체를 만들어 값으로 인스턴스화 할 수 있습니다. 그러면 필터링은 매우 간단합니다. 당신이 찾고자하는 텍스트의 예는 무엇입니까? 그것은 'SOURCE; FLAC'인가 다른 것입니까? –