Skip to content

Commit

Permalink
Fix onplatform generics crash on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkatz6 committed Nov 10, 2022
1 parent 8a6bb0f commit a8f5d5c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ static object LoadSreCore(string xaml, Assembly localAssembly, object rootInstan
compiler.ParseAndCompile(xaml, uri?.ToString(), null, _sreTypeSystem.CreateTypeBuilder(tb), overrideType);
var created = tb.CreateTypeInfo();
clrPropertyBuilder.CreateTypeInfo();
indexerClosureType.CreateTypeInfo();
trampolineBuilder.CreateTypeInfo();

return LoadOrPopulate(created, rootInstance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public OptionsMarkupExtensionNode(
IXamlType contextParameter)
: base(
original.Value,
new OptionsMarkupExtensionMethod(new OptionsMarkupExtensionNodesContainer(branches, defaultNode), original.Type.GetClrType(), contextParameter),
new OptionsMarkupExtensionMethod(new OptionsMarkupExtensionNodesContainer(branches, defaultNode), original.Value.Type.GetClrType(), contextParameter),
original.Value)
{
_contextParameter = contextParameter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ public OnFormFactorExtension(object defaultValue)
{
Default = defaultValue;
}

public static bool ShouldProvideOption(IServiceProvider serviceProvider, FormFactorType option)
{
return serviceProvider.GetService<IRuntimePlatform>().GetRuntimeInfo().FormFactor == option;
}
}

public class OnFormFactorExtension<TReturn> : OnFormFactorExtensionBase<TReturn, On<TReturn>>
Expand All @@ -35,11 +30,6 @@ public OnFormFactorExtension(TReturn defaultValue)
{
Default = defaultValue;
}

public static bool ShouldProvideOption(IServiceProvider serviceProvider, FormFactorType option)
{
return serviceProvider.GetService<IRuntimePlatform>().GetRuntimeInfo().FormFactor == option;
}
}

public abstract class OnFormFactorExtensionBase<TReturn, TOn> : IAddChild<TOn>
Expand All @@ -54,6 +44,11 @@ public abstract class OnFormFactorExtensionBase<TReturn, TOn> : IAddChild<TOn>
[MarkupExtensionOption(FormFactorType.Mobile)]
public TReturn? Mobile { get; set; }

public static bool ShouldProvideOption(IServiceProvider serviceProvider, FormFactorType option)
{
return serviceProvider.GetService<IRuntimePlatform>().GetRuntimeInfo().FormFactor == option;
}

// Required for the compiler, will be replaced with actual method compile time.
public object ProvideValue() { return this; }
void IAddChild<TOn>.AddChild(TOn child) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ public OnPlatformExtension(object defaultValue)
{
Default = defaultValue;
}

public static bool ShouldProvideOption(IServiceProvider serviceProvider, OperatingSystemType option)
{
return serviceProvider.GetService<IRuntimePlatform>().GetRuntimeInfo().OperatingSystem == option;
}
}

public class OnPlatformExtension<TReturn> : OnPlatformExtensionBase<TReturn, On<TReturn>>
Expand All @@ -34,11 +29,6 @@ public OnPlatformExtension(TReturn defaultValue)
{
Default = defaultValue;
}

public static bool ShouldProvideOption(IServiceProvider serviceProvider, OperatingSystemType option)
{
return serviceProvider.GetService<IRuntimePlatform>().GetRuntimeInfo().OperatingSystem == option;
}
}

public abstract class OnPlatformExtensionBase<TReturn, TOn> : IAddChild<TOn>
Expand Down Expand Up @@ -70,4 +60,9 @@ public abstract class OnPlatformExtensionBase<TReturn, TOn> : IAddChild<TOn>
// Required for the compiler, will be replaced with actual method compile time.
public object ProvideValue() { return this; }
void IAddChild<TOn>.AddChild(TOn child) {}

public static bool ShouldProvideOption(IServiceProvider serviceProvider, OperatingSystemType option)
{
return serviceProvider.GetService<IRuntimePlatform>().GetRuntimeInfo().OperatingSystem == option;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public void Support_Xml_Syntax_With_Custom_TypeArguments()
xmlns:local='clr-namespace:Avalonia.Markup.Xaml.UnitTests.MarkupExtensions;assembly=Avalonia.Markup.Xaml.UnitTests'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<Border.Tag>
<local:OptionsMarkupExtensionWithGeneric x:TypeArguments='Thickness' OptionA='10, 10, 10, 10' Default='20' />
<local:OptionsMarkupExtension x:TypeArguments='Thickness' OptionA='10, 10, 10, 10' Default='20' />
</Border.Tag>
</Border>";

Expand Down

0 comments on commit a8f5d5c

Please sign in to comment.