[XamlC] Compiled UriTypeConverter (#1166)
This commit is contained in:
Родитель
e8660383b0
Коммит
4feaf14c55
|
@ -0,0 +1,28 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
using Mono.Cecil;
|
||||||
|
using Mono.Cecil.Cil;
|
||||||
|
using Xamarin.Forms.Xaml;
|
||||||
|
|
||||||
|
namespace Xamarin.Forms.Core.XamlC
|
||||||
|
{
|
||||||
|
class UriTypeConverter : ICompiledTypeConverter
|
||||||
|
{
|
||||||
|
public IEnumerable<Instruction> ConvertFromString(string value, ModuleDefinition module, BaseNode node)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(value)) {
|
||||||
|
yield return Instruction.Create(OpCodes.Ldnull);
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
|
||||||
|
var uriCtor = module.ImportReference(typeof(Uri)).Resolve().Methods.FirstOrDefault(md => md.IsConstructor && md.Parameters.Count == 2 && md.Parameters[1].ParameterType.FullName == "System.UriKind");
|
||||||
|
var uriCtorRef = module.ImportReference(uriCtor);
|
||||||
|
|
||||||
|
yield return Instruction.Create(OpCodes.Ldstr, value);
|
||||||
|
yield return Instruction.Create(OpCodes.Ldc_I4_0); //UriKind.RelativeOrAbsolute
|
||||||
|
yield return Instruction.Create(OpCodes.Newobj, uriCtorRef);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -112,6 +112,7 @@
|
||||||
<Compile Include="CompiledMarkupExtensions\TypeExtension.cs" />
|
<Compile Include="CompiledMarkupExtensions\TypeExtension.cs" />
|
||||||
<Compile Include="CompiledMarkupExtensions\NullExtension.cs" />
|
<Compile Include="CompiledMarkupExtensions\NullExtension.cs" />
|
||||||
<Compile Include="GetTasksAbi.cs" />
|
<Compile Include="GetTasksAbi.cs" />
|
||||||
|
<Compile Include="CompiledConverters\UriTypeConverter.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<Target Name="AfterBuild">
|
<Target Name="AfterBuild">
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Xamarin.Forms
|
namespace Xamarin.Forms
|
||||||
{
|
{
|
||||||
|
[Xaml.ProvideCompiled("Xamarin.Forms.Core.XamlC.UriTypeConverter")]
|
||||||
public class UriTypeConverter : TypeConverter
|
public class UriTypeConverter : TypeConverter
|
||||||
{
|
{
|
||||||
public override object ConvertFromInvariantString(string value)
|
public override object ConvertFromInvariantString(string value)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче