Skip to content

Commit

Permalink
move C# Markup out of forms with internalsvisibleto, eliminate reflec…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
Vincent Hoogendoorn committed Sep 15, 2020
1 parent ce5ff9b commit 939150d
Show file tree
Hide file tree
Showing 50 changed files with 205 additions and 45 deletions.
93 changes: 93 additions & 0 deletions Markup.UnitTests/Markup.UnitTests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{43798DE5-81F4-4C31-8BB2-AEF46F6732AB}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Markup.UnitTests</RootNamespace>
<AssemblyName>Markup.UnitTests</AssemblyName>
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Markup\BindableLayoutExtensionsTests.cs" />
<Compile Include="Markup\BindableObjectExtensionsTests.cs" />
<Compile Include="Markup\BindableObjectMultiBindExtensionsTests.cs" />
<Compile Include="Markup\BindingHelpers.cs" />
<Compile Include="Markup\DefaultBindablePropertiesTests.cs" />
<Compile Include="Markup\ElementExtensionsTests.cs" />
<Compile Include="Markup\ElementGesturesExtensionsTests.cs" />
<Compile Include="Markup\FuncConverter.cs" />
<Compile Include="Markup\GridRowsColumns.cs" />
<Compile Include="Markup\LabelExtensionsLeftToRightTests.cs" />
<Compile Include="Markup\LabelExtensionsRightToLeftTests.cs" />
<Compile Include="Markup\LabelExtensionsTests.cs" />
<Compile Include="Markup\MarkupBaseTestFixture.cs" />
<Compile Include="Markup\PaddingElementExtensionsTests.cs" />
<Compile Include="Markup\RelativeLayoutExtensionsTests.cs" />
<Compile Include="Markup\StyleTests.cs" />
<Compile Include="Markup\ViewExtensionsLeftToRightTests.cs" />
<Compile Include="Markup\ViewExtensionsRightToLeftTests.cs" />
<Compile Include="Markup\ViewExtensionsTests.cs" />
<Compile Include="Markup\ViewInFlexLayoutExtensionsTests.cs" />
<Compile Include="Markup\ViewInGridExtensionsTests.cs" />
<Compile Include="Markup\VisualElementExtensionsTests.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="NUnit">
<Version>3.12.0</Version>
</PackageReference>
<PackageReference Include="NUnit3TestAdapter">
<Version>3.15.1</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Markup\Markup.csproj">
<Project>{848b3b27-8dfb-4bcb-94fa-1d4eba9c5614}</Project>
<Name>Markup</Name>
</ProjectReference>
<ProjectReference Include="..\Xamarin.Forms.Core.UnitTests\Xamarin.Forms.Core.UnitTests.csproj">
<Project>{00259593-a283-47a5-acb7-9c3819b16364}</Project>
<Name>Xamarin.Forms.Core.UnitTests</Name>
</ProjectReference>
<ProjectReference Include="..\Xamarin.Forms.Core\Xamarin.Forms.Core.csproj">
<Project>{57b8b73d-c3b5-4c42-869e-7b2f17d354ac}</Project>
<Name>Xamarin.Forms.Core</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace Xamarin.Forms.Markup.UnitTests
{
internal static class BindingHelpers
{
static MethodInfo getContextMethodInfo;
static FieldInfo bindingFieldInfo;
//static MethodInfo getContextMethodInfo;
//static FieldInfo bindingFieldInfo;

internal static void AssertBindingExists(
BindableObject bindable,
Expand Down Expand Up @@ -136,21 +136,21 @@ internal static void AssertBindingExists<TDest, TParam>(
/// </remarks>
internal static BindingBase GetBindingBase(BindableObject bindable, BindableProperty property)
{
// return bindable.GetContext(property)?.Binding as Binding;
return bindable.GetContext(property)?.Binding as BindingBase;
// Both BindableObject.GetContext and BindableObject.BindablePropertyContext are private;
// use reflection instead of above line.

if (getContextMethodInfo == null)
getContextMethodInfo = typeof(BindableObject).GetMethod("GetContext", BindingFlags.NonPublic | BindingFlags.Instance);
//if (getContextMethodInfo == null)
// getContextMethodInfo = typeof(BindableObject).GetMethod("GetContext", BindingFlags.NonPublic | BindingFlags.Instance);

var context = getContextMethodInfo?.Invoke(bindable, new object[] { property });
if (context == null)
return null;
//var context = getContextMethodInfo?.Invoke(bindable, new object[] { property });
//if (context == null)
// return null;

if (bindingFieldInfo == null)
bindingFieldInfo = context?.GetType().GetField("Binding");
//if (bindingFieldInfo == null)
// bindingFieldInfo = context?.GetType().GetField("Binding");

return bindingFieldInfo?.GetValue(context) as BindingBase;
//return bindingFieldInfo?.GetValue(context) as BindingBase;
}

internal static IValueConverter AssertConvert<TValue, TConvertedValue>(this IValueConverter converter, TValue value, object parameter, TConvertedValue expectedConvertedValue, bool twoWay = false, bool backOnly = false, CultureInfo culture = null)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions Markup/Markup.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard1.0</TargetFrameworks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard2.0|AnyCPU'">
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netstandard2.0|AnyCPU'">
</PropertyGroup>
<PropertyGroup>
<GitInfoReportImportance>high</GitInfoReportImportance>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Xamarin.Forms.Core\Xamarin.Forms.Core.csproj" />
</ItemGroup>
</Project>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace Xamarin.Forms.Core.Markup
{
internal static class Markup
public static class Markup // TODO: Markup remove class in XTC
{
static bool isExperimentalFlagSet = false;

internal static void VerifyExperimental([CallerMemberName] string memberName = "", string constructorHint = null)
public static void VerifyExperimental([CallerMemberName] string memberName = "", string constructorHint = null)
{
if (isExperimentalFlagSet)
return;
Expand All @@ -16,6 +16,6 @@ internal static void VerifyExperimental([CallerMemberName] string memberName = "
isExperimentalFlagSet = true;
}

internal static void ClearExperimental() => isExperimentalFlagSet = false;
public static void ClearExperimental() => isExperimentalFlagSet = false;
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions Markup/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Markup.UnitTests")]
3 changes: 3 additions & 0 deletions Xamarin.Forms.Core.UnitTests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Markup.UnitTests")]
25 changes: 2 additions & 23 deletions Xamarin.Forms.Core.UnitTests/Xamarin.Forms.Core.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,30 +77,9 @@
<Compile Include="CommandTests.cs" />
<Compile Include="DependencyResolutionTests.cs" />
<Compile Include="ItemsLayoutTypeConverterTests.cs" />
<Compile Include="Markup\BindableObjectMultiBindExtensionsTests.cs" />
<Compile Include="Markup\BindingHelpers.cs" />
<Compile Include="Markup\RelativeLayoutExtensionsTests.cs" />
<Compile Include="Markup\BindableLayoutExtensionsTests.cs" />
<Compile Include="MultiBindingTests.cs" />
<Compile Include="Markup\DefaultBindablePropertiesTests.cs" />
<Compile Include="Markup\BindableObjectExtensionsTests.cs" />
<Compile Include="Markup\ElementExtensionsTests.cs" />
<Compile Include="Markup\GridRowsColumns.cs" />
<Compile Include="Markup\FuncConverter.cs" />
<Compile Include="Markup\LabelExtensionsRightToLeftTests.cs" />
<Compile Include="Markup\LabelExtensionsLeftToRightTests.cs" />
<Compile Include="Markup\PaddingElementExtensionsTests.cs" />
<Compile Include="Markup\StyleTests.cs" />
<Compile Include="Markup\ViewExtensionsRightToLeftTests.cs" />
<Compile Include="Markup\ViewExtensionsLeftToRightTests.cs" />
<Compile Include="Markup\ViewExtensionsTests.cs" />
<Compile Include="Markup\LabelExtensionsTests.cs" />
<Compile Include="Markup\MarkupBaseTestFixture.cs" />
<Compile Include="Markup\ElementGesturesExtensionsTests.cs" />
<Compile Include="Markup\ViewInFlexLayoutExtensionsTests.cs" />
<Compile Include="Markup\ViewInGridExtensionsTests.cs" />
<Compile Include="Markup\VisualElementExtensionsTests.cs" />
<Compile Include="NumericExtensionsTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RefreshViewTests.cs" />
<Compile Include="MockDispatcherProvider.cs" />
<Compile Include="MockDispatcher.cs" />
Expand Down Expand Up @@ -290,7 +269,7 @@
<ItemGroup />
<Target Name="_CopyNUnitTestAdapterFiles" AfterTargets="Build">
<ItemGroup>
<_NUnitTestAdapterFiles Include="$(NuGetPackageRoot)NUnit3TestAdapter\%(Version)\build\net35\**" Condition="@(PackageReference -&gt; '%(Identity)') == 'NUnit3TestAdapter'" InProject="False" />
<_NUnitTestAdapterFiles Include="$(NuGetPackageRoot)NUnit3TestAdapter\%(Version)\build\net35\**" Condition="@(PackageReference -> '%(Identity)') == 'NUnit3TestAdapter'" InProject="False" />
</ItemGroup>
<Copy SourceFiles="@(_NUnitTestAdapterFiles)" DestinationFolder="$(SolutionDir)packages\NUnitTestAdapter.AnyVersion\tools\%(RecursiveDir)" ContinueOnError="true" Retries="0" />
<Copy SourceFiles="@(_NUnitTestAdapterFiles)" DestinationFolder="$(SolutionDir)packages\NUnitTestAdapter.AnyVersion\build\%(RecursiveDir)" ContinueOnError="true" Retries="0" />
Expand Down
8 changes: 4 additions & 4 deletions Xamarin.Forms.Core/BindableObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ BindablePropertyContext CreateAndAddContext(BindableProperty property)
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
BindablePropertyContext GetContext(BindableProperty property) => _properties.TryGetValue(property, out var result) ? result : null;
internal BindablePropertyContext GetContext(BindableProperty property) => _properties.TryGetValue(property, out var result) ? result : null;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
BindablePropertyContext GetOrCreateContext(BindableProperty property) => GetContext(property) ?? CreateAndAddContext(property);
Expand Down Expand Up @@ -561,7 +561,7 @@ void CoerceValue(BindableProperty property, bool checkAccess)
}

[Flags]
enum BindableContextAttributes
internal enum BindableContextAttributes
{
IsManuallySet = 1 << 0,
IsBeingSet = 1 << 1,
Expand All @@ -571,7 +571,7 @@ enum BindableContextAttributes
IsDefaultValueCreated = 1 << 5,
}

class BindablePropertyContext
internal class BindablePropertyContext
{
public BindableContextAttributes Attributes;
public BindingBase Binding;
Expand All @@ -592,7 +592,7 @@ internal enum SetValuePrivateFlags
Default = CheckAccess
}

class SetValueArgs
internal class SetValueArgs
{
public readonly SetValueFlags Attributes;
public readonly BindablePropertyContext Context;
Expand Down
2 changes: 1 addition & 1 deletion Xamarin.Forms.Core/FontElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Xamarin.Forms
{
static class FontElement
internal static class FontElement
{
public static readonly BindableProperty FontProperty =
BindableProperty.Create("Font", typeof(Font), typeof(IFontElement), default(Font),
Expand Down
2 changes: 1 addition & 1 deletion Xamarin.Forms.Core/PaddingElement.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Xamarin.Forms
{
static class PaddingElement
internal static class PaddingElement
{
public static readonly BindableProperty PaddingProperty =
BindableProperty.Create(nameof(IPaddingElement.Padding), typeof(Thickness), typeof(IPaddingElement), default(Thickness),
Expand Down
2 changes: 2 additions & 0 deletions Xamarin.Forms.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using Xamarin.Forms.Internals;
using Xamarin.Forms.StyleSheets;

[assembly: InternalsVisibleTo("Markup")]
[assembly: InternalsVisibleTo("Markup.UnitTests")]
[assembly: InternalsVisibleTo("iOSUnitTests")]
[assembly: InternalsVisibleTo("Xamarin.Forms.Controls")]
[assembly: InternalsVisibleTo("Xamarin.Forms.Core.Design")]
Expand Down
3 changes: 3 additions & 0 deletions Xamarin.Forms.Core/Xamarin.Forms.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
</ItemGroup>
<ItemGroup>
<Compile Remove="Internals\Legacy\**" />
<Compile Remove="Markup\**" />
<EmbeddedResource Remove="Internals\Legacy\**" />
<EmbeddedResource Remove="Markup\**" />
<None Remove="Internals\Legacy\**" />
<None Remove="Markup\**" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.0' ">
<Compile Include="Internals\Legacy\**" />
Expand Down
Loading

0 comments on commit 939150d

Please sign in to comment.