Skip to content

Commit

Permalink
v1.0.2.2 Added support for IniKey.ParentSection property.
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioZ committed Jan 31, 2015
1 parent 98211b1 commit 07de997
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 44 deletions.
31 changes: 30 additions & 1 deletion MadMilkman.Ini.Tests/IniFileMiscellaneousTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,36 @@ public void ParseValueMappingsTest()
Assert.IsTrue(file.Sections["DOUBLES"].Keys[1].TryParseValue(out doubleResult));
Assert.AreEqual(double.NegativeInfinity, doubleResult);
Assert.IsTrue(file.Sections["DOUBLES"].Keys[2].TryParseValue(out doubleResult));
Assert.AreEqual(double.NaN, doubleResult);
Assert.IsNaN(doubleResult);
}

[Test]
public void IniItemParentsTest()
{
var file = new IniFile();
var section = new IniSection(file, "Section");
var key = new IniKey(file, "Key");

Assert.AreSame(file, section.ParentFile);
Assert.AreSame(file, key.ParentFile);

Assert.IsNull(section.ParentCollection);
Assert.IsNull(key.ParentCollection);
Assert.IsNull(key.ParentSection);

section.Keys.Add(key);
Assert.AreSame(section.Keys, key.ParentCollection);
Assert.AreSame(section, key.ParentSection);

file.Sections.Add(section);
Assert.AreSame(file.Sections, section.ParentCollection);

file.Sections.Remove(section);
Assert.IsNull(section.ParentCollection);

section.Keys.Remove(key);
Assert.IsNull(key.ParentCollection);
Assert.IsNull(key.ParentSection);
}
}
}
34 changes: 0 additions & 34 deletions MadMilkman.Ini.Tests/MadMilkman.Ini.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@
<AssemblyName>MadMilkman.Ini.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -55,14 +48,6 @@
</Reference>
<Reference Include="System" />
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise />
</Choose>
<ItemGroup>
<Compile Include="IniFileCreateUpdateTests.cs" />
<Compile Include="IniFileMiscellaneousTests.cs" />
Expand All @@ -76,25 +61,6 @@
<Name>MadMilkman.Ini</Name>
</ProjectReference>
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
5 changes: 5 additions & 0 deletions MadMilkman.Ini/IniItems/IniKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public sealed class IniKey : IniItem
/// </summary>
public IniKeyCollection ParentCollection { get { return (IniKeyCollection)this.ParentCollectionCore; } }

/// <summary>
/// Gets the <see cref="IniSection"/> to which this <see cref="IniKey"/> belongs to.
/// </summary>
public IniSection ParentSection { get { return (IniSection)((this.ParentCollectionCore != null) ? this.ParentCollection.Owner : null); } }

/// <summary>
/// Initializes a new instance of the <see cref="IniKey"/> class.
/// </summary>
Expand Down
6 changes: 3 additions & 3 deletions MadMilkman.Ini/IniItems/IniSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public IniSection(IniFile parentFile, string name, IEnumerable<KeyValuePair<stri
public IniSection(IniFile parentFile, string name, IEnumerable<IniKey> keys)
: base(parentFile, name)
{
this.keys = new IniKeyCollection(parentFile, parentFile.options.KeyDuplicate, parentFile.options.KeyNameCaseSensitive);
this.keys = new IniKeyCollection(parentFile, this, parentFile.options.KeyDuplicate, parentFile.options.KeyNameCaseSensitive);

if (keys != null)
foreach (IniKey key in keys)
Expand All @@ -78,14 +78,14 @@ public IniSection(IniFile parentFile, string name, IEnumerable<IniKey> keys)
internal IniSection(IniFile parentFile, string name, IniComment trailingComment)
: base(parentFile, name, trailingComment)
{
this.keys = new IniKeyCollection(parentFile, parentFile.options.KeyDuplicate, parentFile.options.KeyNameCaseSensitive);
this.keys = new IniKeyCollection(parentFile, this, parentFile.options.KeyDuplicate, parentFile.options.KeyNameCaseSensitive);
}

// Deep copy constructor.
internal IniSection(IniFile destinationFile, IniSection sourceSection)
: base(destinationFile, sourceSection)
{
this.keys = new IniKeyCollection(destinationFile, destinationFile.options.KeyDuplicate, destinationFile.options.KeyNameCaseSensitive);
this.keys = new IniKeyCollection(destinationFile, this, destinationFile.options.KeyDuplicate, destinationFile.options.KeyNameCaseSensitive);

foreach (var key in sourceSection.keys)
this.keys.Add(key.Copy(destinationFile));
Expand Down
10 changes: 8 additions & 2 deletions MadMilkman.Ini/IniItemsCollection/IniItemCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,28 @@ public abstract class IniItemCollection<T> : IItemNameVerifier, IList<T> where T
private readonly IList<T> items;
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly IniFile parentFile;
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly IniItem owner;

/// <exclude/>
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
protected IniFile ParentFile { get { return parentFile; } }
protected IniFile ParentFile { get { return this.parentFile; } }

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
internal IniItem Owner { get { return this.owner; } }

///
/// <summary>
/// Gets the number of items in this collection.
/// </summary>
public int Count { get { return this.items.Count; } }

internal IniItemCollection(IniFile parentFile, IniDuplication duplication, bool caseSensitive)
internal IniItemCollection(IniFile parentFile, IniItem owner, IniDuplication duplication, bool caseSensitive)
{
this.caseSensitive = caseSensitive;
this.duplication = duplication;
this.parentFile = parentFile;
this.owner = owner;
this.items = new List<T>();
}

Expand Down
4 changes: 2 additions & 2 deletions MadMilkman.Ini/IniItemsCollection/IniKeyCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace MadMilkman.Ini
/// <seealso cref="IniKey"/>
public sealed class IniKeyCollection : IniItemCollection<IniKey>
{
internal IniKeyCollection(IniFile parentFile, IniDuplication duplication, bool caseSensitive)
: base(parentFile, duplication, caseSensitive) { }
internal IniKeyCollection(IniFile parentFile, IniSection parentSection, IniDuplication duplication, bool caseSensitive)
: base(parentFile, parentSection, duplication, caseSensitive) { }

/// <summary>
/// Adds an item to the end of this collection.
Expand Down
2 changes: 1 addition & 1 deletion MadMilkman.Ini/IniItemsCollection/IniSectionCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace MadMilkman.Ini
public sealed class IniSectionCollection : IniItemCollection<IniSection>
{
internal IniSectionCollection(IniFile parentFile, IniDuplication duplication, bool caseSensitive)
: base(parentFile, duplication, caseSensitive) { }
: base(parentFile, null, duplication, caseSensitive) { }

/// <summary>
/// Adds an item to the end of this collection.
Expand Down
2 changes: 1 addition & 1 deletion MadMilkman.Ini/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
[assembly: AllowPartiallyTrustedCallers]
[assembly: CLSCompliant(true)]

[assembly: AssemblyVersion("1.0.2.1")]
[assembly: AssemblyVersion("1.0.2.2")]
[assembly: NeutralResourcesLanguageAttribute("en-US")]
1 change: 1 addition & 0 deletions RELEASENOTES
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[1.0.2.2] Added support for IniKey.ParentSection property.
[1.0.2.1] Switched from MS tests to NUnit tests.

[1.0.2.0] NEW RELEASE
Expand Down

0 comments on commit 07de997

Please sign in to comment.