-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3888 from unoplatform/dev/djo/gsr-instance
Adjust Xaml code generation
- Loading branch information
Showing
21 changed files
with
638 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
576 changes: 339 additions & 237 deletions
576
src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Uno.UI.Tests.ViewLibrary | ||
{ | ||
// This type should only be created by the Test_Dictionary_Initializer dictionary | ||
public class TestInitializer | ||
{ | ||
public static bool IsInitialized { get; private set; } | ||
|
||
public TestInitializer() | ||
{ | ||
IsInitialized = true; | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/Uno.UI.Tests.ViewLibrary/Themes/More/Test_Dictionary_Initializer.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:win="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:ext="using:Uno.UI.Tests.ViewLibrary"> | ||
<!--This dictionary should only be referenced by the Test_Control_With_Initializer control--> | ||
<ext:TestInitializer x:Key="TestInitializer" /> | ||
</ResourceDictionary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/Uno.UI.Tests/App/Xaml/Test_Control_With_Initializer.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<UserControl x:Class="Uno.UI.Tests.App.Xaml.Test_Control_With_Initializer" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:Uno.UI.Tests.App.Xaml" | ||
xmlns:views="using:Uno.UI.Tests.App.Views" | ||
xmlns:ext="using:Uno.UI.Tests.ViewLibrary" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d"> | ||
<!--This control should only be created by the When_Needs_Eager_Materialization() test--> | ||
<UserControl.Resources> | ||
<ResourceDictionary Source="ms-appx:///Uno.UI.Tests.ViewLibrary/Themes/More/Test_Dictionary_Initializer.xaml" /> | ||
</UserControl.Resources> | ||
|
||
<Grid> | ||
</Grid> | ||
</UserControl> |
32 changes: 32 additions & 0 deletions
32
src/Uno.UI.Tests/App/Xaml/Test_Control_With_Initializer.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.InteropServices.WindowsRuntime; | ||
using Uno.UI.Tests.App.Views; | ||
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.App.Xaml | ||
{ | ||
/// <summary> | ||
/// An empty page that can be used on its own or navigated to within a Frame. | ||
/// </summary> | ||
public sealed partial class Test_Control_With_Initializer : UserControl | ||
{ | ||
|
||
public Test_Control_With_Initializer() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Windows.UI.Xaml; | ||
|
||
namespace Uno.UI.Helpers.Xaml | ||
{ | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
// This is normally called from code generated by the Xaml parser | ||
// | ||
// NOTE: This class' methods may be called often from generated code. It MUST NOT have static state or a static ctor as it impacts the size of the generated code of the call site of this method when using mono's AOT engine. | ||
public static class SetterHelper | ||
{ | ||
public static Setter GetPropertySetterWithResourceValue(DependencyProperty dependencyProperty, object key, object context, object defaultValue) | ||
{ | ||
return new Setter(dependencyProperty, ProvideSetterValue); | ||
|
||
object ProvideSetterValue() | ||
{ | ||
if (ResourceResolver.ResolveResourceStatic(key, out var value, context)) | ||
{ | ||
return value; | ||
} | ||
|
||
return defaultValue; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Diagnostics; | ||
using System.Text; | ||
using Microsoft.Extensions.Logging; | ||
using Uno.Diagnostics.Eventing; | ||
using Uno.Extensions; | ||
using Uno.UI.DataBinding; | ||
using Uno.UI.Xaml; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Data; | ||
using Windows.UI.Xaml.Resources; | ||
|
||
namespace Uno.UI | ||
{ | ||
/// <summary> | ||
/// Provides initialization logic for resources defined in a ResourceDictionary. | ||
/// </summary> | ||
/// <remarks> Normally only implemented and referenced by Xaml-generated code.</remarks> | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public interface IXamlLazyResourceInitializer | ||
{ | ||
object GetInitializedValue(string resourceRetrievalKey); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Diagnostics; | ||
using System.Text; | ||
using Microsoft.Extensions.Logging; | ||
using Uno.Diagnostics.Eventing; | ||
using Uno.Extensions; | ||
using Uno.UI.DataBinding; | ||
using Uno.UI.Xaml; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Data; | ||
using Windows.UI.Xaml.Resources; | ||
|
||
namespace Uno.UI | ||
{ | ||
/// <summary> | ||
/// Provides lazy initialization for a resource dictionary. | ||
/// </summary> | ||
/// <remarks> Normally only implemented and referenced by Xaml-generated code.</remarks> | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public interface IXamlResourceDictionaryProvider | ||
{ | ||
ResourceDictionary GetResourceDictionary(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Diagnostics; | ||
using System.Text; | ||
using Microsoft.Extensions.Logging; | ||
using Uno.Diagnostics.Eventing; | ||
using Uno.Extensions; | ||
using Uno.UI.DataBinding; | ||
using Uno.UI.Xaml; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Data; | ||
using Windows.UI.Xaml.Resources; | ||
|
||
namespace Uno.UI | ||
{ | ||
/// <summary> | ||
/// A wrapper for <see cref="ResourceResolver"/> methods following the singleton pattern. | ||
/// </summary> | ||
/// <remarks> | ||
/// The motivation is to avoid additional overhead associated with static method calls into types with static state. This is normally | ||
/// only called from Xaml-generated code. | ||
/// </remarks> | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public sealed class ResourceResolverSingleton | ||
{ | ||
private static ResourceResolverSingleton _instance; | ||
public static ResourceResolverSingleton Instance => _instance ??= new ResourceResolverSingleton(); | ||
|
||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public bool ResolveResourceStatic(object key, out object value, object context) => ResourceResolver.ResolveResourceStatic(key, out value, context); | ||
|
||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public void ApplyResource(DependencyObject owner, DependencyProperty property, object resourceKey, bool isThemeResourceExtension, object context) => ResourceResolver.ApplyResource(owner, property, resourceKey, isThemeResourceExtension, context); | ||
|
||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public object ResolveStaticResourceAlias(string resourceKey, object parseContext) => ResourceResolver.ResolveStaticResourceAlias(resourceKey, parseContext); | ||
} | ||
} |
Oops, something went wrong.