Skip to content

Commit

Permalink
fix: Add null check for GetMethod in case of write-only property
Browse files Browse the repository at this point in the history
  • Loading branch information
kazo0 committed Oct 16, 2020
1 parent dd8d73c commit 0f00793
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -541,12 +541,12 @@ private static bool SourceIsAttachedProperty(INamedTypeSymbol type, string name)
var property = type.GetAllPropertiesWithName(name).FirstOrDefault();
var setMethod = type.GetMethods().FirstOrDefault(p => p.Name == "Set" + name);

if (property != null && property.GetMethod.IsStatic)
if (property?.GetMethod?.IsStatic ?? false)
{
return true;
}

if (setMethod != null && setMethod.IsStatic)
if (setMethod?.IsStatic ?? false)
{
return true;
}
Expand Down
6 changes: 6 additions & 0 deletions src/Uno.UI.Tests/Uno.UI.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Windows_Data_Xml\DomTests\basictest.xml" />
<EmbeddedResource Include="Windows_UI_XAML_Controls\UserControlTests\UserControl_WriteOnlyProperty_UserControl.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -147,6 +150,9 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<Generator>ResXFileCodeGenerator</Generator>
</None>
<None Update="Windows_UI_XAML_Controls\UserControlTests\UserControl_WriteOnlyProperty.xaml">
<Generator>MSBuild:Compile</Generator>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,19 @@ public void When_UserControl_TopLevel_Binding()
Assert.AreEqual(1, UserControl_TopLevelBinding_AttachedProperty.MyPropertyChangedCount);
Assert.AreEqual(42, UserControl_TopLevelBinding_AttachedProperty.GetMyProperty(uc01));
}

[TestMethod]
public void When_UserControl_WriteOnlyProperty_Binding()
{
var sut = new UserControl_WriteOnlyProperty();
sut.ForceLoaded();

var textBlock = sut.FindName("TextDisplay") as TextBlock;
var uc02 = sut.FindName("uc02") as UserControl_WriteOnlyProperty_UserControl;

Assert.AreEqual("Hello, World!", textBlock.Text);
uc02.Text = "Test";
Assert.AreEqual("Test", textBlock.Text);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Page
x:Class="Uno.UI.Tests.Windows_UI_XAML_Controls.UserControlTests.UserControl_WriteOnlyProperty"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Uno.UI.Tests.Windows_UI_XAML_Controls.UserControlTests"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid x:Name="test02">
<local:UserControl_WriteOnlyProperty_UserControl x:Name="uc02" Text="Hello, World!"/>
</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238

namespace Uno.UI.Tests.Windows_UI_XAML_Controls.UserControlTests
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class UserControl_WriteOnlyProperty : Page
{
public UserControl_WriteOnlyProperty()
{
this.InitializeComponent();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<UserControl
x:Class="Uno.UI.Tests.Windows_UI_XAML_Controls.UserControlTests.UserControl_WriteOnlyProperty_UserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Uno.UI.Tests.Windows_UI_XAML_Controls.UserControlTests"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<TextBlock x:Name="TextDisplay" />
</Grid>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace Uno.UI.Tests.Windows_UI_XAML_Controls.UserControlTests
{
public sealed partial class UserControl_WriteOnlyProperty_UserControl : UserControl
{
public string Text
{
set => TextDisplay.Text = value;
}

public UserControl_WriteOnlyProperty_UserControl()
{
InitializeComponent();
}
}
}

0 comments on commit 0f00793

Please sign in to comment.