Initial Commit

master
Harald Christian Joachim Wolff 2018-07-30 12:56:24 +02:00
commit 32b28565e9
7 changed files with 277 additions and 0 deletions

41
.gitignore vendored 100644
View File

@ -0,0 +1,41 @@
# Autosave files
*~
# build
[Oo]bj/
[Bb]in/
packages/
TestResults/
# globs
Makefile.in
*.DS_Store
*.sln.cache
*.suo
*.cache
*.pidb
*.userprefs
*.usertasks
config.log
config.make
config.status
aclocal.m4
install-sh
autom4te.cache/
*.user
*.tar.gz
tarballs/
test-results/
Thumbs.db
.vs/
# Mac bundle stuff
*.dmg
*.app
# resharper
*_Resharper.*
*.Resharper
# dotCover
*.dotCover

55
Configuration.cs 100644
View File

@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
namespace ReflectiveConfiguration
{
public abstract class Configuration
{
Dictionary<String, ConfigurationSection> sections = new Dictionary<string, ConfigurationSection>();
public Configuration()
{
ConfigurationSection defaultSection = this[""];
}
public Configuration(String path){
LoadFrom(path);
}
public ConfigurationSection this[string name] {
get {
if (sections.ContainsKey(name))
{
return sections[name];
}
return createSection(name);
}
}
public Dictionary<String,ConfigurationSection>.KeyCollection Keys {
get { return this.sections.Keys; }
}
public void LoadFrom(String path)
{
using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read))
{
LoadFrom(stream);
}
}
public void SaveTo(String path)
{
using (FileStream stream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write))
{
SaveTo(stream);
}
}
public abstract ConfigurationSection createSection(String name);
public abstract void LoadFrom(Stream stream);
public abstract void SaveTo(Stream stream);
}
}

View File

@ -0,0 +1,42 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace ReflectiveConfiguration
{
public class ConfigurationSection
{
private Dictionary<string, object> values = new Dictionary<string, object>();
public string Name { get; private set; }
public Configuration Configuration { get; private set; }
public ConfigurationSection(Configuration configuration)
: this(configuration,null)
{
}
public ConfigurationSection(Configuration configuration,string name)
{
this.Name = name;
}
public object this[string key]
{
get {
return this.values[key];
}
set {
this.values[key] = value;
}
}
public Dictionary<string,object>.KeyCollection Keys {
get {
return this.values.Keys;
}
}
}
}

View File

@ -0,0 +1,49 @@
using System;
using System.IO;
using System.Linq;
namespace ReflectiveConfiguration
{
public class FlatFileConfiguration : Configuration
{
public FlatFileConfiguration()
{
}
public override ConfigurationSection createSection(string name)
{
if (this.Keys.Contains(name))
throw new ArgumentException(String.Format("Section {0} already exists",name));
return new ConfigurationSection(this,name);
}
public override void LoadFrom(Stream stream)
{
StreamReader reader = new StreamReader(stream);
ConfigurationSection currentSection = this[""];
while (!reader.EndOfStream){
String line = reader.ReadLine().Trim();
if (line.StartsWith("[",StringComparison.InvariantCulture)){
currentSection = this[ line.Substring(1,line.Length-2)];
} else {
String[] tokens = line.Split(new char[] { '=' }, 2);
currentSection[tokens[0]] = tokens[1];
}
}
reader.Close();
}
public override void SaveTo(Stream stream)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,26 @@
using System.Reflection;
using System.Runtime.CompilerServices;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle("ReflectiveConfiguration")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("${AuthorCopyright}")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion("1.0.*")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

View File

@ -0,0 +1,24 @@
using System;
using System.IO;
using System.Collections.Generic;
namespace ReflectiveConfiguration
{
public class ReflectiveConfiguration
{
public ReflectiveConfiguration(String path)
:this(new FileStream(path,FileMode.Open,FileAccess.Read))
{
}
public ReflectiveConfiguration(Stream stream){
}
}
}

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{1ABC409D-81CC-426B-B890-77D61C5335A9}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>ReflectiveConfiguration</RootNamespace>
<AssemblyName>ReflectiveConfiguration</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="ReflectiveConfiguration.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Configuration.cs" />
<Compile Include="ConfigurationSection.cs" />
<Compile Include="FlatFileConfiguration.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>