Skip to content

Commit

Permalink
Merge pull request #5 from keith-hsv/master
Browse files Browse the repository at this point in the history
Bug Fix - Fixes #3
  • Loading branch information
David Grochocki committed Feb 5, 2016
2 parents e1eb37f + 7ea4468 commit 81db27f
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 1 deletion.
32 changes: 32 additions & 0 deletions Service/Helpers/AttributeHelper.cs
@@ -0,0 +1,32 @@
using System.Xml.Linq;

namespace XamlMagic.Service.Helpers
{
internal static class AttributeHelper
{
/// <summary>
/// Gets a properly configured XName object from an XAttribute.
/// </summary>
/// <param name="attribute"></param>
/// <returns></returns>
public static XName GetName(XAttribute attribute)
{
if(attribute.Value.Contains(":"))
{
string[] parts = attribute.Value.Split(':');

if (parts.Length == 2)
{
string prefix = parts[0];
string value = parts[1];

var namespaceOfPrefix = attribute.Parent.GetNamespaceOfPrefix(prefix);

return XName.Get(value, namespaceOfPrefix.NamespaceName);
}
}

return XName.Get(attribute.Value);
}
}
}
2 changes: 1 addition & 1 deletion Service/Reorder/FormatThicknessService.cs
Expand Up @@ -40,7 +40,7 @@ public void ProcessElement(XElement element)
{
var propertyAttribute = element.Attributes("Property").FirstOrDefault();
if ((propertyAttribute != null)
&& this.ThicknessAttributeNames.Any(_ => _.IsMatch(propertyAttribute.Value)))
&& this.ThicknessAttributeNames.Any(_ => _.IsMatch(AttributeHelper.GetName(propertyAttribute))))
{
var valueAttribute = element.Attributes("Value").FirstOrDefault();
if (valueAttribute != null)
Expand Down
1 change: 1 addition & 0 deletions Service/Service.csproj
Expand Up @@ -47,6 +47,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Helpers\AttributeInfoExtension.cs" />
<Compile Include="Helpers\AttributeHelper.cs" />
<Compile Include="Helpers\XmlReaderExtensions.cs" />
<Compile Include="Helpers\MarkupExtensionInfoExtension.cs" />
<Compile Include="Helpers\StringExtension.cs" />
Expand Down
8 changes: 8 additions & 0 deletions UnitTests/TestFiles/TestAttachedProperty.expected
@@ -0,0 +1,8 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:XamlMagic">
<Style x:Key="ToggleButtonStyle" TargetType="ToggleButton">
<Setter Property="local:AttachedProperties.MyProperty" Value="Red" />
<Setter Property="BorderThickness" Value="1" />
</Style>
</ResourceDictionary>
6 changes: 6 additions & 0 deletions UnitTests/TestFiles/TestAttachedProperty.testxaml
@@ -0,0 +1,6 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:XamlMagic">
<Style x:Key="ToggleButtonStyle" TargetType="ToggleButton">
<Setter Property="local:AttachedProperties.MyProperty" Value="Red"/>
<Setter Property="BorderThickness" Value="1"/>
</Style>
</ResourceDictionary>
17 changes: 17 additions & 0 deletions UnitTests/UnitTests.AttachedProperty.cs
@@ -0,0 +1,17 @@
using NUnit.Framework;
using XamlMagic.Service.Options;

namespace XamlMagic.UnitTests
{
[TestFixture]
public sealed partial class UnitTests
{
[Test]
public void TestAttachedProperty()
{
var stylerOptions = new StylerOptions(config: this.legacyConfig);

this.DoTest(stylerOptions);
}
}
}
12 changes: 12 additions & 0 deletions UnitTests/UnitTests.csproj
Expand Up @@ -36,6 +36,9 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
Expand Down Expand Up @@ -74,6 +77,9 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UnitTests.AttachedProperty.cs">
<DependentUpon>UnitTests.cs</DependentUpon>
</Compile>
<Compile Include="UnitTests.Configuration.cs">
<DependentUpon>UnitTests.cs</DependentUpon>
</Compile>
Expand Down Expand Up @@ -140,6 +146,12 @@
<Content Include="TestConfigurations\SerializedSingle.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="TestFiles\TestAttachedProperty.testxaml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="TestFiles\TestAttachedProperty.expected">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="TestFiles\TestCommentHandling_1.expected">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down

0 comments on commit 81db27f

Please sign in to comment.