Skip to content

Commit

Permalink
Simplified the conversions, more already available TypeConverters are…
Browse files Browse the repository at this point in the history
… now taken.
  • Loading branch information
Lakritzator committed Aug 4, 2015
1 parent ecfbe8f commit 8d4340d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 295 deletions.
2 changes: 2 additions & 0 deletions Dapplo.Config.Test/IniTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public async Task TestIniInit()
}
var iniTest = await iniConfig.RegisterAndGetAsync<IIniTest>().ConfigureAwait(false);
Assert.IsTrue(iniTest.Height == 185);
Assert.IsTrue(iniTest.PropertySize.Width == 16);
Assert.IsTrue(iniTest.PropertyArea.Width == 100);
Assert.IsTrue(iniTest.WindowCornerCutShape.Count > 0);
Assert.IsTrue(iniTest.SomeValues.ContainsKey("dapplo"));

Expand Down
12 changes: 12 additions & 0 deletions Dapplo.Config.Test/TestInterfaces/IIniTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using Dapplo.Config.Ini;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.Serialization;

namespace Dapplo.Config.Test.TestInterfaces
Expand Down Expand Up @@ -81,5 +82,16 @@ IDictionary<string, int> SomeValues
get;
set;
}

[DefaultValue("16,16")]
Size PropertySize {
get;
set;
}
[DefaultValue("16,16,100,100")]
Rectangle PropertyArea {
get;
set;
}
}
}
273 changes: 0 additions & 273 deletions Dapplo.Config/Converters/SystemDrawingTypeConverters.cs

This file was deleted.

1 change: 0 additions & 1 deletion Dapplo.Config/Dapplo.Config.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="Converters\SystemDrawingTypeConverters.cs" />
<Compile Include="DapploConfig.cs" />
<Compile Include="ExtensionAttribute.cs" />
<Compile Include="Extension\IDescription.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ private object GetConvertedDefaultValue(PropertyInfo propertyInfo)
if (typeConverter != null && typeConverter.CanConvertFrom(defaultValue.GetType()))
{
// Convert
return typeConverter.ConvertFrom(defaultValue);
var defaultStringValue = defaultValue as string;
if (defaultStringValue != null) {
return typeConverter.ConvertFromInvariantString(defaultStringValue);
} else {
return typeConverter.ConvertFrom(defaultValue);
}
}
}
return defaultValue;
Expand Down
21 changes: 1 addition & 20 deletions Dapplo.Config/Ini/IniConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,14 @@ public static IniConfig Get(string applicationName, string fileName)
/// <param name="fileName"></param>
/// <param name="fixedDirectory">Specify a path if you don't want to use the default loading</param>
/// <param name="registerDefaultConverters">false if you don't want to have any default converters</param>
public IniConfig(string applicationName, string fileName, string fixedDirectory = null, bool registerDefaultConverters = true)
public IniConfig(string applicationName, string fileName, string fixedDirectory = null)
{
_applicationName = applicationName;
_fileName = fileName;
_fixedDirectory = fixedDirectory;
// Look for the ini file, this is only done 1 time.
_iniFile = CreateFileLocation(false, "", _fixedDirectory);

if (registerDefaultConverters)
{
SetDefaultConverters();
}

WriteErrorHandler = (iniSection, iniValue, exception) =>
{
if (!iniValue.Behavior.IgnoreErrors)
Expand Down Expand Up @@ -159,20 +154,6 @@ public IniConfig SetDefaultConverter(Type type, Type typeConverter)
return this;
}

/// <summary>
/// Set the default converters
/// </summary>
public IniConfig SetDefaultConverters()
{
// System.Drawing
SetDefaultConverter(typeof(System.Drawing.Size), typeof(SizeTypeConverter));
SetDefaultConverter(typeof(System.Drawing.Point), typeof(PointTypeConverter));
SetDefaultConverter(typeof(System.Drawing.Rectangle), typeof(RectangleTypeConverter));
SetDefaultConverter(typeof(System.Drawing.Color), typeof(ColorTypeConverter));

return this;
}

/// <summary>
/// Set the after load action for a IIniSection
/// </summary>
Expand Down

0 comments on commit 8d4340d

Please sign in to comment.