diff --git a/Directory.Build.props b/Directory.Build.props
new file mode 100644
index 0000000..1e2b9d1
--- /dev/null
+++ b/Directory.Build.props
@@ -0,0 +1,12 @@
+
+
+
+ $(MSBuildThisFileDirectory)
+ $(BasePath)artifacts\obj\$(MSBuildProjectName)\
+
+ PackageReference
+ false
+ False
+
+
+
\ No newline at end of file
diff --git a/Directory.Build.targets b/Directory.Build.targets
new file mode 100644
index 0000000..7ea2661
--- /dev/null
+++ b/Directory.Build.targets
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/NuGet.Config b/NuGet.Config
new file mode 100644
index 0000000..c971e75
--- /dev/null
+++ b/NuGet.Config
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/build/build.cmd b/build.cmd
similarity index 77%
rename from build/build.cmd
rename to build.cmd
index 69bc0e8..c103442 100644
--- a/build/build.cmd
+++ b/build.cmd
@@ -12,6 +12,7 @@ if not defined VisualStudioVersion (
:EnvSet
-msbuild -t:Package Build.proj
+set BUILD_DIR=%~dp0build
+msbuild -t:Package "%BUILD_DIR%\Build.proj"
pause
\ No newline at end of file
diff --git a/build.sh b/build.sh
new file mode 100755
index 0000000..ff61a11
--- /dev/null
+++ b/build.sh
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+msbuild /t:Package $DIR/build/Build.proj
diff --git a/build/Build.proj b/build/Build.proj
index 110af11..aad961d 100644
--- a/build/Build.proj
+++ b/build/Build.proj
@@ -1,32 +1,30 @@
-
+
Release
Any CPU
..
$(BaseDir)\src
- $(SourceDir)\.nuget
- $(NugetDir)\nuget.exe
- $(BaseDir)/artifacts
- $(ArtifactsDir)/nupkg/$(Configuration)
+ $(BaseDir)\artifacts
+ $(ArtifactsDir)\tools
+ $(ToolsDir)\nuget.exe
+ $(ArtifactsDir)\nupkg\$(Configuration)
mono
- $(ArtifactsDir)\obj
-
-
+
-
-
-
+
+
+
-
+
-
+
@@ -36,10 +34,9 @@
-
-
+
@@ -47,7 +44,7 @@
-
+
@@ -68,7 +65,7 @@
-
+
diff --git a/build/Utilities.targets b/build/Utilities.targets
index 1174923..0b39fe7 100644
--- a/build/Utilities.targets
+++ b/build/Utilities.targets
@@ -1,20 +1,18 @@
-
-
- true
- packages
- $(UtilitiesBasePath)\UtilitiesTasks
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+ (this System.Reflection.Assembly ass) where T : Attribute
@@ -36,24 +33,20 @@ public static class Extensions
return attributes.OfType().SingleOrDefault();
}
- public static bool IsUnix
+ public static bool IsMono
{
- get
- {
- return
- Environment.OSVersion.Platform == PlatformID.MacOSX
- || Environment.OSVersion.Platform == PlatformID.Unix;
- }
+ get { return Type.GetType("Mono.Runtime", false) != null; }
}
public static string FixParameter(string value)
{
- if (IsUnix)
- return value.Replace("//", "%5C%5C");
- return value;
+ if (IsMono)
+ return value.Replace("//", @"\");
+ else
+ return value.Replace(@"\\", @"\");
}
-}]]>
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+}
+]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/build/build.sh b/build/build.sh
deleted file mode 100755
index 0cf6812..0000000
--- a/build/build.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/bash
-
-msbuild /t:Package Build.proj
diff --git a/src/.nuget/nuget.exe b/src/.nuget/nuget.exe
deleted file mode 100644
index 6bb79fe..0000000
Binary files a/src/.nuget/nuget.exe and /dev/null differ
diff --git a/src/Portable.Xaml.Benchmark/Portable.Xaml.Benchmark.csproj b/src/Portable.Xaml.Benchmark/Portable.Xaml.Benchmark.csproj
index ef083fa..113395a 100644
--- a/src/Portable.Xaml.Benchmark/Portable.Xaml.Benchmark.csproj
+++ b/src/Portable.Xaml.Benchmark/Portable.Xaml.Benchmark.csproj
@@ -10,14 +10,13 @@
Portable.Xaml.Benchmark
Portable.Xaml.Benchmark
v4.6.1
- ..\..\artifacts\obj\$(MSBuildProjectName)\
-
+ true
true
full
false
- ..\..\artifacts\Debug\net_4_5\
+ ..\..\artifacts\benchmark\Debug\net461\
DEBUG;
prompt
4
@@ -25,146 +24,20 @@
true
- ..\..\artifacts\Release\net_4_5\
+ ..\..\artifacts\benchmark\Release\net461\
prompt
4
true
true
-
- ..\packages\BenchmarkDotNet.0.10.6\lib\net46\BenchmarkDotNet.dll
-
-
- ..\packages\BenchmarkDotNet.Core.0.10.6\lib\net46\BenchmarkDotNet.Core.dll
-
-
- ..\packages\BenchmarkDotNet.Toolchains.Roslyn.0.10.6\lib\net46\BenchmarkDotNet.Toolchains.Roslyn.dll
-
-
- ..\packages\Glass.Core.2.0.0\lib\netstandard1.2\Glass.Core.dll
- True
-
-
- ..\packages\Microsoft.CodeAnalysis.Common.2.1.0\lib\netstandard1.3\Microsoft.CodeAnalysis.dll
-
-
- ..\packages\Microsoft.CodeAnalysis.CSharp.2.1.0\lib\netstandard1.3\Microsoft.CodeAnalysis.CSharp.dll
-
-
- ..\packages\Microsoft.DotNet.InternalAbstractions.1.0.0\lib\net451\Microsoft.DotNet.InternalAbstractions.dll
-
-
- ..\packages\Microsoft.DotNet.PlatformAbstractions.1.1.2\lib\net451\Microsoft.DotNet.PlatformAbstractions.dll
-
-
- ..\packages\OmniXaml.2.0.0\lib\netstandard1.2\OmniXaml.dll
- True
-
-
- ..\packages\OmniXaml.Attributes.2.0.0\lib\netstandard1.2\OmniXaml.Attributes.dll
- True
-
-
- ..\packages\OmniXaml.Services.2.0.0\lib\netstandard1.2\OmniXaml.Services.dll
- True
-
-
- ..\packages\Serilog.2.3.0\lib\net46\Serilog.dll
-
-
- ..\packages\Sprache.2.1.0\lib\net40\Sprache.dll
- True
-
-
- ..\packages\System.AppContext.4.3.0\lib\net46\System.AppContext.dll
-
-
- ..\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll
- True
-
-
- ..\packages\System.ComponentModel.Primitives.4.3.0\lib\net45\System.ComponentModel.Primitives.dll
- True
-
-
- ..\packages\System.ComponentModel.TypeConverter.4.3.0\lib\net45\System.ComponentModel.TypeConverter.dll
- True
-
-
- ..\packages\System.Console.4.3.0\lib\net46\System.Console.dll
-
-
- ..\packages\System.Diagnostics.DiagnosticSource.4.3.1\lib\net46\System.Diagnostics.DiagnosticSource.dll
-
-
- ..\packages\System.Diagnostics.FileVersionInfo.4.3.0\lib\net46\System.Diagnostics.FileVersionInfo.dll
-
-
- ..\packages\System.Diagnostics.StackTrace.4.3.0\lib\net46\System.Diagnostics.StackTrace.dll
-
-
- ..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll
-
-
- ..\packages\System.IO.FileSystem.4.3.0\lib\net46\System.IO.FileSystem.dll
-
-
- ..\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll
-
-
- ..\packages\System.Net.Http.4.3.2\lib\net46\System.Net.Http.dll
-
-
- ..\packages\System.Reflection.Metadata.1.4.2\lib\portable-net45+win8\System.Reflection.Metadata.dll
-
-
- ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll
- True
-
-
- ..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net461\System.Security.Cryptography.Algorithms.dll
-
-
- ..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll
-
-
- ..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll
-
-
- ..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll
-
-
- ..\packages\System.Text.Encoding.CodePages.4.3.0\lib\net46\System.Text.Encoding.CodePages.dll
-
-
- ..\packages\System.Threading.Tasks.Extensions.4.3.0\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll
-
-
- ..\packages\System.Threading.Thread.4.3.0\lib\net46\System.Threading.Thread.dll
-
-
- ..\packages\System.ValueTuple.4.3.1\lib\netstandard1.0\System.ValueTuple.dll
-
-
- ..\packages\System.Xml.ReaderWriter.4.3.0\lib\net46\System.Xml.ReaderWriter.dll
-
-
- ..\packages\System.Xml.XmlDocument.4.3.0\lib\net46\System.Xml.XmlDocument.dll
-
-
- ..\packages\System.Xml.XPath.4.3.0\lib\net46\System.Xml.XPath.dll
-
-
- ..\packages\System.Xml.XPath.XDocument.4.3.0\lib\net46\System.Xml.XPath.XDocument.dll
-
@@ -180,7 +53,6 @@
-
@@ -196,5 +68,22 @@
Portable.Xaml-netstandard1.3
+
+
+ 0.10.12
+
+
+ 2.0.0
+
+
+ 2.0.0
+
+
+ 2.0.0
+
+
+ 1.4.0
+
+
\ No newline at end of file
diff --git a/src/Portable.Xaml.Benchmark/Program.cs b/src/Portable.Xaml.Benchmark/Program.cs
index dd08c90..e587c5d 100644
--- a/src/Portable.Xaml.Benchmark/Program.cs
+++ b/src/Portable.Xaml.Benchmark/Program.cs
@@ -9,6 +9,7 @@
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Columns;
+using BenchmarkDotNet.Validators;
namespace Portable.Xaml.Benchmark
{
@@ -41,12 +42,16 @@ public static void Main(string[] args)
.Where(r => typeof(IXamlBenchmark).IsAssignableFrom(r) && !r.IsAbstract);
- var config = ManualConfig
- .Create(DefaultConfig.Instance)
- .With(Job.Default)
- .With(MemoryDiagnoser.Default)
- .With(StatisticColumn.OperationsPerSecond)
- .With(RankColumn.Arabic);
+ var config = new ManualConfig();
+ config.Add(DefaultConfig.Instance.GetLoggers().ToArray());
+ config.Add(DefaultConfig.Instance.GetExporters().ToArray());
+ config.Add(DefaultConfig.Instance.GetColumnProviders().ToArray());
+
+ config.Add(JitOptimizationsValidator.DontFailOnError);
+ config.Add(Job.Default);
+ config.Add(MemoryDiagnoser.Default);
+ config.Add(StatisticColumn.OperationsPerSecond);
+ config.Add(RankColumn.Arabic);
var switcher = new BenchmarkSwitcher(types.ToArray());
switcher.Run(args, config);
diff --git a/src/Portable.Xaml.Benchmark/app.config b/src/Portable.Xaml.Benchmark/app.config
index 88250c1..1b99e1c 100644
--- a/src/Portable.Xaml.Benchmark/app.config
+++ b/src/Portable.Xaml.Benchmark/app.config
@@ -1,68 +1,4 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/Portable.Xaml.Benchmark/packages.config b/src/Portable.Xaml.Benchmark/packages.config
deleted file mode 100644
index e9e31ea..0000000
--- a/src/Portable.Xaml.Benchmark/packages.config
+++ /dev/null
@@ -1,73 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/Portable.Xaml.sln b/src/Portable.Xaml.sln
index eb78dcc..bbde7b1 100644
--- a/src/Portable.Xaml.sln
+++ b/src/Portable.Xaml.sln
@@ -1,19 +1,15 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
-VisualStudioVersion = 15.0.26430.4
+VisualStudioVersion = 15.0.27130.2024
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Portable.Xaml-pcl259", "Portable.Xaml\Portable.Xaml-pcl259.csproj", "{179484EC-DB00-451A-AD2D-2E2AB20DE519}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Portable.Xaml-pcl136", "Portable.Xaml\Portable.Xaml-pcl136.csproj", "{A283EEF5-D2BF-47DD-AFD6-A1DB3DF7CDA0}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Portable.Xaml-tests-pcl136", "Test\Portable.Xaml-tests-pcl136.csproj", "{307DC911-E3EE-41F9-87BA-D1FD734E04BC}"
-EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Portable.Xaml-tests-net_4_5", "Test\Portable.Xaml-tests-net_4_5.csproj", "{F4FA4B21-EF1C-48DE-8F4C-16496005FB94}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Portable.Xaml.Benchmark", "Portable.Xaml.Benchmark\Portable.Xaml.Benchmark.csproj", "{AC406459-D324-4ADF-853D-A58B63396591}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Portable.Xaml-netstandard1.3", "Portable.Xaml\Portable.Xaml-netstandard1.3.csproj", "{CDC8F791-56FC-4B15-AAD2-BC460657CC02}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Portable.Xaml-netstandard1.3", "Portable.Xaml\Portable.Xaml-netstandard1.3.csproj", "{CDC8F791-56FC-4B15-AAD2-BC460657CC02}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Portable.Xaml-tests-pcl259", "Test\Portable.Xaml-tests-pcl259.csproj", "{FDA04C3E-7386-4F45-A7F2-C69DB33B72FF}"
EndProject
@@ -21,7 +17,15 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Portable.Xaml-tests-netstan
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Portable.Xaml-tests-uwp", "Test\Portable.Xaml-tests-uwp.csproj", "{1B4909D0-ECFB-4E32-8C02-B164DB1D64C6}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Portable.Xaml-tests-core", "Test\Portable.Xaml-tests-core.csproj", "{1E5C8B3A-E196-499C-9849-9876EB621A7C}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Portable.Xaml-tests-core", "Test\Portable.Xaml-tests-core.csproj", "{1E5C8B3A-E196-499C-9849-9876EB621A7C}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{39859568-90DD-4BA1-A525-2899C232B44E}"
+ ProjectSection(SolutionItems) = preProject
+ ..\build\Build.proj = ..\build\Build.proj
+ ..\Directory.Build.props = ..\Directory.Build.props
+ ..\Directory.Build.targets = ..\Directory.Build.targets
+ ..\NuGet.Config = ..\NuGet.Config
+ EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -51,38 +55,6 @@ Global
{179484EC-DB00-451A-AD2D-2E2AB20DE519}.Release|x64.Build.0 = Release|Any CPU
{179484EC-DB00-451A-AD2D-2E2AB20DE519}.Release|x86.ActiveCfg = Release|Any CPU
{179484EC-DB00-451A-AD2D-2E2AB20DE519}.Release|x86.Build.0 = Release|Any CPU
- {A283EEF5-D2BF-47DD-AFD6-A1DB3DF7CDA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {A283EEF5-D2BF-47DD-AFD6-A1DB3DF7CDA0}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {A283EEF5-D2BF-47DD-AFD6-A1DB3DF7CDA0}.Debug|ARM.ActiveCfg = Debug|Any CPU
- {A283EEF5-D2BF-47DD-AFD6-A1DB3DF7CDA0}.Debug|ARM.Build.0 = Debug|Any CPU
- {A283EEF5-D2BF-47DD-AFD6-A1DB3DF7CDA0}.Debug|x64.ActiveCfg = Debug|Any CPU
- {A283EEF5-D2BF-47DD-AFD6-A1DB3DF7CDA0}.Debug|x64.Build.0 = Debug|Any CPU
- {A283EEF5-D2BF-47DD-AFD6-A1DB3DF7CDA0}.Debug|x86.ActiveCfg = Debug|Any CPU
- {A283EEF5-D2BF-47DD-AFD6-A1DB3DF7CDA0}.Debug|x86.Build.0 = Debug|Any CPU
- {A283EEF5-D2BF-47DD-AFD6-A1DB3DF7CDA0}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {A283EEF5-D2BF-47DD-AFD6-A1DB3DF7CDA0}.Release|Any CPU.Build.0 = Release|Any CPU
- {A283EEF5-D2BF-47DD-AFD6-A1DB3DF7CDA0}.Release|ARM.ActiveCfg = Release|Any CPU
- {A283EEF5-D2BF-47DD-AFD6-A1DB3DF7CDA0}.Release|ARM.Build.0 = Release|Any CPU
- {A283EEF5-D2BF-47DD-AFD6-A1DB3DF7CDA0}.Release|x64.ActiveCfg = Release|Any CPU
- {A283EEF5-D2BF-47DD-AFD6-A1DB3DF7CDA0}.Release|x64.Build.0 = Release|Any CPU
- {A283EEF5-D2BF-47DD-AFD6-A1DB3DF7CDA0}.Release|x86.ActiveCfg = Release|Any CPU
- {A283EEF5-D2BF-47DD-AFD6-A1DB3DF7CDA0}.Release|x86.Build.0 = Release|Any CPU
- {307DC911-E3EE-41F9-87BA-D1FD734E04BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {307DC911-E3EE-41F9-87BA-D1FD734E04BC}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {307DC911-E3EE-41F9-87BA-D1FD734E04BC}.Debug|ARM.ActiveCfg = Debug|Any CPU
- {307DC911-E3EE-41F9-87BA-D1FD734E04BC}.Debug|ARM.Build.0 = Debug|Any CPU
- {307DC911-E3EE-41F9-87BA-D1FD734E04BC}.Debug|x64.ActiveCfg = Debug|Any CPU
- {307DC911-E3EE-41F9-87BA-D1FD734E04BC}.Debug|x64.Build.0 = Debug|Any CPU
- {307DC911-E3EE-41F9-87BA-D1FD734E04BC}.Debug|x86.ActiveCfg = Debug|Any CPU
- {307DC911-E3EE-41F9-87BA-D1FD734E04BC}.Debug|x86.Build.0 = Debug|Any CPU
- {307DC911-E3EE-41F9-87BA-D1FD734E04BC}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {307DC911-E3EE-41F9-87BA-D1FD734E04BC}.Release|Any CPU.Build.0 = Release|Any CPU
- {307DC911-E3EE-41F9-87BA-D1FD734E04BC}.Release|ARM.ActiveCfg = Release|Any CPU
- {307DC911-E3EE-41F9-87BA-D1FD734E04BC}.Release|ARM.Build.0 = Release|Any CPU
- {307DC911-E3EE-41F9-87BA-D1FD734E04BC}.Release|x64.ActiveCfg = Release|Any CPU
- {307DC911-E3EE-41F9-87BA-D1FD734E04BC}.Release|x64.Build.0 = Release|Any CPU
- {307DC911-E3EE-41F9-87BA-D1FD734E04BC}.Release|x86.ActiveCfg = Release|Any CPU
- {307DC911-E3EE-41F9-87BA-D1FD734E04BC}.Release|x86.Build.0 = Release|Any CPU
{F4FA4B21-EF1C-48DE-8F4C-16496005FB94}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F4FA4B21-EF1C-48DE-8F4C-16496005FB94}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F4FA4B21-EF1C-48DE-8F4C-16496005FB94}.Debug|ARM.ActiveCfg = Debug|Any CPU
diff --git a/src/Portable.Xaml/Assembly/AssemblyInfo.cs b/src/Portable.Xaml/Assembly/AssemblyInfo.cs
index b446e50..319662d 100644
--- a/src/Portable.Xaml/Assembly/AssemblyInfo.cs
+++ b/src/Portable.Xaml/Assembly/AssemblyInfo.cs
@@ -46,16 +46,14 @@
[assembly: CLSCompliant(true)]
//[assembly: ComVisible (false)]
-#if !NETSTANDARD
[assembly: AssemblyTitle("Portable.Xaml.dll")]
[assembly: AssemblyDescription("Portable.Xaml.dll")]
[assembly: AssemblyDefaultAlias("Portable.Xaml.dll")]
-[assembly: AssemblyVersion("0.15.*")]
-[assembly: AssemblyInformationalVersion("0.17.0")]
+[assembly: AssemblyVersion("0.18.0.0")]
+[assembly: AssemblyInformationalVersion("0.18.0")]
[assembly: AssemblyCompany("Mono development team")]
[assembly: AssemblyCopyright("(c) Various Mono authors")]
-#endif
#if !PCL
diff --git a/src/Portable.Xaml/Compat.snk b/src/Portable.Xaml/Compat.snk
new file mode 100644
index 0000000..0e7d4f7
Binary files /dev/null and b/src/Portable.Xaml/Compat.snk differ
diff --git a/src/Portable.Xaml/Helpers/ReflectionHelpers.cs b/src/Portable.Xaml/Helpers/ReflectionHelpers.cs
new file mode 100644
index 0000000..aae5eb4
--- /dev/null
+++ b/src/Portable.Xaml/Helpers/ReflectionHelpers.cs
@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Portable.Xaml
+{
+ static class ReflectionHelpers
+ {
+ static Assembly componentModelAssembly = typeof(System.ComponentModel.CancelEventArgs).GetTypeInfo().Assembly;
+ static Assembly corlibAssembly = typeof(int).GetTypeInfo().Assembly;
+
+ public static Type GetComponentModelType(string name) => componentModelAssembly.GetType(name);
+ public static Type GetCorlibType(string name) => corlibAssembly.GetType(name);
+ }
+}
diff --git a/src/Portable.Xaml/Portable.Xaml-netstandard1.3.csproj b/src/Portable.Xaml/Portable.Xaml-netstandard1.3.csproj
index cf0d063..2465132 100644
--- a/src/Portable.Xaml/Portable.Xaml-netstandard1.3.csproj
+++ b/src/Portable.Xaml/Portable.Xaml-netstandard1.3.csproj
@@ -4,17 +4,16 @@
netstandard1.3
Portable.Xaml
Portable.Xaml
- ..\..\artifacts\obj\$(MSBuildProjectName)\
- ..\..\artifacts\Debug\
- TRACE;DEBUG;NETSTANDARD1_3;PCL;NETSTANDARD
+ ..\..\artifacts\core\Debug\
+ TRACE;PCL;NETSTANDARD;DEBUG;HAS_TYPE_CONVERTER;NETSTANDARD1_3
pdbonly
- ..\..\artifacts\Release\
- TRACE;RELEASE;NETSTANDARD1_3;PCL;NETSTANDARD
+ ..\..\artifacts\core\Release\
+ TRACE;PCL;NETSTANDARD;RELEASE;HAS_TYPE_CONVERTER;NETSTANDARD1_3
True
diff --git a/src/Portable.Xaml/Portable.Xaml-pcl136.csproj b/src/Portable.Xaml/Portable.Xaml-pcl136.csproj
deleted file mode 100644
index 041cfd9..0000000
--- a/src/Portable.Xaml/Portable.Xaml-pcl136.csproj
+++ /dev/null
@@ -1,202 +0,0 @@
-
-
-
- Debug
- AnyCPU
- {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
- 8.0.30703
- 2.0
- {A283EEF5-D2BF-47DD-AFD6-A1DB3DF7CDA0}
- Library
- Portable.Xaml
- Portable.Xaml
- Profile136
- v4.0
- ..\..\artifacts\obj\$(MSBuildProjectName)\
-
-
- true
- full
- false
- ..\..\artifacts\Debug\pcl136\
- DEBUG;PCL;PCL136
- prompt
- 4
- false
-
-
- true
- ..\..\artifacts\Release\pcl136\
- prompt
- 4
- false
- PCL;PCL136
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/Portable.Xaml/Portable.Xaml-pcl259.csproj b/src/Portable.Xaml/Portable.Xaml-pcl259.csproj
index 64184aa..5017c42 100644
--- a/src/Portable.Xaml/Portable.Xaml-pcl259.csproj
+++ b/src/Portable.Xaml/Portable.Xaml-pcl259.csproj
@@ -10,15 +10,13 @@
Portable.Xaml
Profile259
v4.5
- ..\..\artifacts\obj\$(MSBuildProjectName)\
- 8.0.30703
- 2.0
+ 10.0
true
full
false
- ..\..\artifacts\Debug\pcl259\
+ ..\..\artifacts\core\Debug\portable-net45+win8+wpa81+wp8\
DEBUG;PCL;MONO;PCL259
prompt
4
@@ -26,7 +24,7 @@
true
- ..\..\artifacts\Release\pcl259\
+ ..\..\artifacts\core\Release\portable-net45+win8+wpa81+wp8\
prompt
4
false
@@ -34,25 +32,12 @@
pdbonly
true
-
- false
-
-
-
+
-
-
-
-
-
-
-
-
-
@@ -172,20 +157,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -196,11 +168,18 @@
+
+
+
+
-
+
+
+
+
\ No newline at end of file
diff --git a/src/Portable.Xaml/Portable.Xaml.ComponentModel/BaseNumberConverter.cs b/src/Portable.Xaml/Portable.Xaml.ComponentModel/BaseNumberConverter.cs
deleted file mode 100644
index a333e9e..0000000
--- a/src/Portable.Xaml/Portable.Xaml.ComponentModel/BaseNumberConverter.cs
+++ /dev/null
@@ -1,104 +0,0 @@
-#if PCL && !NETSTANDARD
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Portable.Xaml.ComponentModel;
-using System.Runtime.Serialization;
-using System.Reflection;
-
-namespace Portable.Xaml.ComponentModel
-{
-
- public abstract class BaseNumberConverter : TypeConverter
- {
- internal virtual bool AllowHex { get { return true; } }
-
- internal abstract Type NumberType { get; }
-
- internal abstract object FromString(string value, int fromBase);
-
- internal abstract object FromString(string value, NumberFormatInfo formatInfo);
-
- internal virtual string ToString(object value, NumberFormatInfo formatInfo)
- {
- return Convert.ToString (value, formatInfo);
- }
-
- public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
- {
- return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
- }
-
- public override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType)
- {
- return destinationType == typeof(string) || base.CanConvertTo (context, destinationType);
- }
-
- public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
- {
- var str = value as string;
- if (str != null)
- {
- string text = str.Trim();
- try
- {
- object result;
- if (AllowHex && text[0] == '#')
- {
- result = FromString(text.Substring(1), 16);
- return result;
- }
- if ((AllowHex && text.StartsWith("0x", StringComparison.OrdinalIgnoreCase)) || text.StartsWith("&h", StringComparison.OrdinalIgnoreCase))
- {
- result = FromString(text.Substring(2), 16);
- return result;
- }
- culture = culture ?? CultureInfo.CurrentCulture;
- var formatInfo = (NumberFormatInfo)culture.GetFormat(typeof(NumberFormatInfo));
- result = FromString(text, formatInfo);
- return result;
- }
- catch (InvalidOperationException innerException)
- {
- throw new InvalidOperationException(text, innerException);
- }
- catch (ArgumentNullException innerException)
- {
- throw new ArgumentNullException(text, innerException);
- }
- catch (ArgumentOutOfRangeException innerException)
- {
- throw new ArgumentOutOfRangeException(text, innerException);
- }
- catch (ArgumentException innerException)
- {
- throw new ArgumentException(text, innerException);
- }
- catch (Exception innerException)
- {
- throw new Exception(text, innerException);
- }
- }
- return base.ConvertFrom(context, culture, value);
- }
-
- public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
- {
- if (destinationType == null)
- throw new ArgumentNullException("destinationType");
-
- if (destinationType == typeof(string) && value != null && NumberType.GetTypeInfo().IsAssignableFrom(value.GetType().GetTypeInfo()))
- {
- culture = culture ?? CultureInfo.CurrentCulture;
- var formatInfo = (NumberFormatInfo)culture.GetFormat(typeof(NumberFormatInfo));
- return ToString(value, formatInfo);
- }
- return base.ConvertTo(context, culture, value, destinationType);
- }
- }
-
-}
-#endif
\ No newline at end of file
diff --git a/src/Portable.Xaml/Portable.Xaml.ComponentModel/BoolConverter.cs b/src/Portable.Xaml/Portable.Xaml.ComponentModel/BoolConverter.cs
deleted file mode 100644
index 2ceb720..0000000
--- a/src/Portable.Xaml/Portable.Xaml.ComponentModel/BoolConverter.cs
+++ /dev/null
@@ -1,43 +0,0 @@
-#if !NETSTANDARD
-using System;
-using System.Collections;
-using System.Globalization;
-using System.Reflection;
-using System.Collections.Generic;
-
-namespace Portable.Xaml.ComponentModel
-{
-
- public class BoolConverter : TypeConverter
- {
- public override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)
- {
- return sourceType == typeof(string) || base.CanConvertFrom (context, sourceType);
- }
-
- public override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType)
- {
- return destinationType == typeof(string) || base.CanConvertTo (context, destinationType);
- }
-
- public override object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object value)
- {
- var text = value as string;
- if (text != null) {
- bool result;
- if (bool.TryParse (text, out result))
- return result;
- }
- return base.ConvertFrom (context, culture, value);
- }
-
- public override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
- {
- if (destinationType == typeof(string) && value is bool)
- return Convert.ToString (value);
- return base.ConvertTo (context, culture, value, destinationType);
- }
- }
-
-}
-#endif
\ No newline at end of file
diff --git a/src/Portable.Xaml/Portable.Xaml.ComponentModel/ByteConverter.cs b/src/Portable.Xaml/Portable.Xaml.ComponentModel/ByteConverter.cs
deleted file mode 100644
index cc94509..0000000
--- a/src/Portable.Xaml/Portable.Xaml.ComponentModel/ByteConverter.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-#if !NETSTANDARD
-using System;
-using System.Collections;
-using System.Globalization;
-using System.Reflection;
-using System.Collections.Generic;
-
-namespace Portable.Xaml.ComponentModel
-{
- public class ByteConverter : BaseNumberConverter
- {
- internal override Type NumberType { get { return typeof(byte); } }
-
- internal override object FromString (string value, int fromBase)
- {
- return Byte.Parse (value, CultureInfo.InvariantCulture);
- }
-
- internal override object FromString (string value, NumberFormatInfo formatInfo)
- {
- return Byte.Parse (value, formatInfo);
- }
- }
-
-}
-#endif
\ No newline at end of file
diff --git a/src/Portable.Xaml/Portable.Xaml.ComponentModel/CharConverter.cs b/src/Portable.Xaml/Portable.Xaml.ComponentModel/CharConverter.cs
deleted file mode 100644
index 73ca914..0000000
--- a/src/Portable.Xaml/Portable.Xaml.ComponentModel/CharConverter.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-#if !NETSTANDARD
-using System;
-using System.Collections;
-using System.Globalization;
-using System.Reflection;
-using System.Collections.Generic;
-
-namespace Portable.Xaml.ComponentModel
-{
-
- public class CharConverter : TypeConverter
- {
- public override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)
- {
- return sourceType == typeof(string) || base.CanConvertFrom (context, sourceType);
- }
-
- public override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType)
- {
- return destinationType == typeof(string) || base.CanConvertTo (context, destinationType);
- }
-
- public override object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object value)
- {
- var text = value as string;
- if (text != null && text.Length == 1) {
- return text [0];
- }
- return base.ConvertFrom (context, culture, value);
- }
-
- public override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
- {
- if (destinationType == typeof(string) && value is char)
- return ((char)value).ToString();
- return base.ConvertTo (context, culture, value, destinationType);
- }
- }
-
-}
-#endif
\ No newline at end of file
diff --git a/src/Portable.Xaml/Portable.Xaml.ComponentModel/DateTimeConverter.cs b/src/Portable.Xaml/Portable.Xaml.ComponentModel/DateTimeConverter.cs
index d30eb61..a65776e 100644
--- a/src/Portable.Xaml/Portable.Xaml.ComponentModel/DateTimeConverter.cs
+++ b/src/Portable.Xaml/Portable.Xaml.ComponentModel/DateTimeConverter.cs
@@ -2,12 +2,13 @@
using System.Globalization;
#if NETSTANDARD
using System.ComponentModel;
+using System.Reflection;
#endif
namespace Portable.Xaml.ComponentModel
{
- public class DateTimeConverter : TypeConverter
+ class DateTimeConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
diff --git a/src/Portable.Xaml/Portable.Xaml.ComponentModel/DecimalConverter.cs b/src/Portable.Xaml/Portable.Xaml.ComponentModel/DecimalConverter.cs
deleted file mode 100644
index c4d6a94..0000000
--- a/src/Portable.Xaml/Portable.Xaml.ComponentModel/DecimalConverter.cs
+++ /dev/null
@@ -1,33 +0,0 @@
-#if PCL && !NETSTANDARD
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Portable.Xaml.ComponentModel;
-using System.Runtime.Serialization;
-using System.Reflection;
-
-namespace Portable.Xaml.ComponentModel
-{
-
- public class DecimalConverter : BaseNumberConverter
- {
- internal override bool AllowHex { get { return false; } }
-
- internal override Type NumberType { get { return typeof(decimal); } }
-
- internal override object FromString(string value, int fromBase)
- {
- return Convert.ToDecimal(value, CultureInfo.InvariantCulture);
- }
-
- internal override object FromString(string value, NumberFormatInfo formatInfo)
- {
- return decimal.Parse(value, NumberStyles.Float, formatInfo);
- }
- }
-
-}
-#endif
\ No newline at end of file
diff --git a/src/Portable.Xaml/Portable.Xaml.ComponentModel/DoubleConverter.cs b/src/Portable.Xaml/Portable.Xaml.ComponentModel/DoubleConverter.cs
deleted file mode 100644
index d6558ad..0000000
--- a/src/Portable.Xaml/Portable.Xaml.ComponentModel/DoubleConverter.cs
+++ /dev/null
@@ -1,38 +0,0 @@
-#if PCL && !NETSTANDARD
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Portable.Xaml.ComponentModel;
-using System.Runtime.Serialization;
-using System.Reflection;
-
-namespace Portable.Xaml.ComponentModel
-{
-
- public class DoubleConverter : BaseNumberConverter
- {
- internal override bool AllowHex { get { return false; } }
-
- internal override Type NumberType { get { return typeof(double); } }
-
- internal override object FromString(string value, int fromBase)
- {
- return Convert.ToDouble(value, CultureInfo.InvariantCulture);
- }
-
- internal override object FromString(string value, NumberFormatInfo formatInfo)
- {
- return double.Parse(value, NumberStyles.Float, formatInfo);
- }
-
- internal override string ToString(object value, NumberFormatInfo formatInfo)
- {
- return ((double)value).ToString("R", formatInfo);
- }
- }
-
-}
-#endif
\ No newline at end of file
diff --git a/src/Portable.Xaml/Portable.Xaml.ComponentModel/EnumConverter.cs b/src/Portable.Xaml/Portable.Xaml.ComponentModel/EnumConverter.cs
deleted file mode 100644
index b5c8b68..0000000
--- a/src/Portable.Xaml/Portable.Xaml.ComponentModel/EnumConverter.cs
+++ /dev/null
@@ -1,55 +0,0 @@
-#if !NETSTANDARD
-using System;
-using System.Collections;
-using System.Globalization;
-using System.Reflection;
-using System.Collections.Generic;
-
-namespace Portable.Xaml.ComponentModel
-{
- public class EnumConverter : TypeConverter
- {
- public Type Type { get; private set; }
-
- public EnumConverter(Type type)
- {
- Type = type;
- }
-
- public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
- {
- return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
- }
-
- public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
- {
- var text = value as string;
- if (text != null)
- {
- try
- {
- if (text.IndexOf(',') == -1)
- return Enum.Parse(Type, text, true);
-
- long enumValue = 0L;
- var array = text.Split(',');
- for (int i = 0; i < array.Length; i++)
- {
- string value2 = array[i];
- enumValue |= Convert.ToInt64((Enum)Enum.Parse(Type, value2, true), culture);
- }
-
- return Enum.ToObject(Type, enumValue);
- }
- catch (Exception innerException)
- {
- throw new FormatException("Invalid Primitive", innerException);
- }
- }
- return base.ConvertFrom(context, culture, value);
- }
- }
-
-}
-
-#endif
\ No newline at end of file
diff --git a/src/Portable.Xaml/Portable.Xaml.ComponentModel/GuidConverter.cs b/src/Portable.Xaml/Portable.Xaml.ComponentModel/GuidConverter.cs
deleted file mode 100644
index 3c2d055..0000000
--- a/src/Portable.Xaml/Portable.Xaml.ComponentModel/GuidConverter.cs
+++ /dev/null
@@ -1,40 +0,0 @@
-#if !NETSTANDARD
-using System;
-using System.Collections;
-using System.Globalization;
-using System.Reflection;
-using System.Collections.Generic;
-
-namespace Portable.Xaml.ComponentModel
-{
-
- public class GuidConverter : TypeConverter
- {
- public override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)
- {
- return sourceType == typeof(string) || base.CanConvertFrom (context, sourceType);
- }
-
- public override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType)
- {
- return destinationType == typeof(string) || base.CanConvertTo (context, destinationType);
- }
-
- public override object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object value)
- {
- var text = value as string;
- if (text != null)
- return Guid.Parse (text);
- return base.ConvertFrom (context, culture, value);
- }
-
- public override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
- {
- if (destinationType == typeof(string) && value is Guid)
- return Convert.ToString (value);
- return base.ConvertTo (context, culture, value, destinationType);
- }
- }
-
-}
-#endif
\ No newline at end of file
diff --git a/src/Portable.Xaml/Portable.Xaml.ComponentModel/ITypeConverter.cs b/src/Portable.Xaml/Portable.Xaml.ComponentModel/ITypeConverter.cs
new file mode 100644
index 0000000..b625837
--- /dev/null
+++ b/src/Portable.Xaml/Portable.Xaml.ComponentModel/ITypeConverter.cs
@@ -0,0 +1,18 @@
+using System;
+using System.Globalization;
+
+namespace Portable.Xaml.ComponentModel
+{
+#if !HAS_TYPE_CONVERTER
+
+ interface ITypeDescriptorContext : IServiceProvider
+ {
+ object Instance { get; }
+
+ void OnComponentChanged();
+
+ bool OnComponentChanging();
+ }
+
+#endif
+}
\ No newline at end of file
diff --git a/src/Portable.Xaml/Portable.Xaml.ComponentModel/ITypeDescriptorContext.cs b/src/Portable.Xaml/Portable.Xaml.ComponentModel/ITypeDescriptorContext.cs
deleted file mode 100644
index 14d7934..0000000
--- a/src/Portable.Xaml/Portable.Xaml.ComponentModel/ITypeDescriptorContext.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-#if PCL && !NETSTANDARD
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Portable.Xaml.ComponentModel;
-using System.Runtime.Serialization;
-using System.Reflection;
-
-namespace Portable.Xaml.ComponentModel
-{
-
- ///
- /// Interface for a type descriptor context, for type converter compatibility in portable class libraries.
- ///
- public interface ITypeDescriptorContext : IServiceProvider
- {
- }
-
-}
-#endif
\ No newline at end of file
diff --git a/src/Portable.Xaml/Portable.Xaml.ComponentModel/Int16Converter.cs b/src/Portable.Xaml/Portable.Xaml.ComponentModel/Int16Converter.cs
deleted file mode 100644
index b259f8d..0000000
--- a/src/Portable.Xaml/Portable.Xaml.ComponentModel/Int16Converter.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-#if !NETSTANDARD
-using System;
-using System.Collections;
-using System.Globalization;
-using System.Reflection;
-using System.Collections.Generic;
-
-namespace Portable.Xaml.ComponentModel
-{
- public class Int16Converter : BaseNumberConverter
- {
- internal override Type NumberType { get { return typeof(Int16); } }
-
- internal override object FromString (string value, int fromBase)
- {
- return Int16.Parse (value, CultureInfo.InvariantCulture);
- }
-
- internal override object FromString (string value, NumberFormatInfo formatInfo)
- {
- return Int16.Parse (value, formatInfo);
- }
- }
-
-}
-#endif
\ No newline at end of file
diff --git a/src/Portable.Xaml/Portable.Xaml.ComponentModel/Int32Converter.cs b/src/Portable.Xaml/Portable.Xaml.ComponentModel/Int32Converter.cs
deleted file mode 100644
index 0c67df2..0000000
--- a/src/Portable.Xaml/Portable.Xaml.ComponentModel/Int32Converter.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-#if !NETSTANDARD
-using System;
-using System.Collections;
-using System.Globalization;
-using System.Reflection;
-using System.Collections.Generic;
-
-namespace Portable.Xaml.ComponentModel
-{
- public class Int32Converter : BaseNumberConverter
- {
- internal override Type NumberType { get { return typeof(Int32); } }
-
- internal override object FromString (string value, int fromBase)
- {
- return Int32.Parse (value, CultureInfo.InvariantCulture);
- }
-
- internal override object FromString (string value, NumberFormatInfo formatInfo)
- {
- return Int32.Parse (value, formatInfo);
- }
- }
-
-}
-#endif
\ No newline at end of file
diff --git a/src/Portable.Xaml/Portable.Xaml.ComponentModel/Int64Converter.cs b/src/Portable.Xaml/Portable.Xaml.ComponentModel/Int64Converter.cs
deleted file mode 100644
index 6cc787d..0000000
--- a/src/Portable.Xaml/Portable.Xaml.ComponentModel/Int64Converter.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-#if !NETSTANDARD
-using System;
-using System.Collections;
-using System.Globalization;
-using System.Reflection;
-using System.Collections.Generic;
-
-namespace Portable.Xaml.ComponentModel
-{
-
- public class Int64Converter : BaseNumberConverter
- {
- internal override Type NumberType { get { return typeof(Int64); } }
-
- internal override object FromString (string value, int fromBase)
- {
- return Int64.Parse (value, CultureInfo.InvariantCulture);
- }
-
- internal override object FromString (string value, NumberFormatInfo formatInfo)
- {
- return Int64.Parse (value, formatInfo);
- }
- }
-
-}
-#endif
\ No newline at end of file
diff --git a/src/Portable.Xaml/Portable.Xaml.ComponentModel/NullableConverter.cs b/src/Portable.Xaml/Portable.Xaml.ComponentModel/NullableConverter.cs
deleted file mode 100644
index c46fe99..0000000
--- a/src/Portable.Xaml/Portable.Xaml.ComponentModel/NullableConverter.cs
+++ /dev/null
@@ -1,66 +0,0 @@
-#if !NETSTANDARD
-using System;
-using System.Collections;
-using System.Globalization;
-using System.Reflection;
-using System.Collections.Generic;
-
-namespace Portable.Xaml.ComponentModel
-{
-
- public class NullableConverter : TypeConverter
- {
- public Type UnderlyingType { get; private set; }
-
- public TypeConverter UnderlyingTypeConverter { get; private set; }
-
- public Type NullableType { get; private set; }
-
- public NullableConverter(Type type)
- {
- NullableType = type;
- UnderlyingType = Nullable.GetUnderlyingType(type);
- if (UnderlyingType == null)
- {
- throw new ArgumentException("Specified type is not nullable", "type");
- }
- UnderlyingTypeConverter = TypeDescriptor.GetConverter(this.UnderlyingType);
- }
-
- public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
- {
- if (UnderlyingType.GetTypeInfo().IsAssignableFrom(sourceType.GetTypeInfo()))
- return true;
-
- if (UnderlyingTypeConverter != null)
- return UnderlyingTypeConverter.CanConvertFrom(context, sourceType);
-
- return base.CanConvertFrom(context, sourceType);
- }
-
- public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
- {
- if (value == null || UnderlyingType.GetTypeInfo().IsAssignableFrom(value.GetType().GetTypeInfo()))
- return value;
-
- if (value is string && string.IsNullOrEmpty(value as string))
- return null;
-
- if (UnderlyingTypeConverter != null)
- return UnderlyingTypeConverter.ConvertFrom(context, culture, value);
- return base.ConvertFrom(context, culture, value);
- }
-
- public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
- {
- if (destinationType == null) throw new ArgumentNullException(nameof(destinationType));
-
- if (destinationType == typeof (string) && UnderlyingTypeConverter != null && value != null)
- {
- return UnderlyingTypeConverter.ConvertTo(context, culture, value, destinationType);
- }
- return GetConvertToException(value, destinationType);
- }
- }
-}
-#endif
\ No newline at end of file
diff --git a/src/Portable.Xaml/Portable.Xaml.ComponentModel/SingleConverter.cs b/src/Portable.Xaml/Portable.Xaml.ComponentModel/SingleConverter.cs
deleted file mode 100644
index c40fcdc..0000000
--- a/src/Portable.Xaml/Portable.Xaml.ComponentModel/SingleConverter.cs
+++ /dev/null
@@ -1,38 +0,0 @@
-#if PCL && !NETSTANDARD
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Portable.Xaml.ComponentModel;
-using System.Runtime.Serialization;
-using System.Reflection;
-
-namespace Portable.Xaml.ComponentModel
-{
-
- public class SingleConverter : BaseNumberConverter
- {
- internal override bool AllowHex { get { return false; } }
-
- internal override Type NumberType { get { return typeof(float); } }
-
- internal override object FromString(string value, int fromBase)
- {
- return Convert.ToSingle(value, CultureInfo.InvariantCulture);
- }
-
- internal override object FromString(string value, NumberFormatInfo formatInfo)
- {
- return float.Parse(value, NumberStyles.Float, formatInfo);
- }
-
- internal override string ToString(object value, NumberFormatInfo formatInfo)
- {
- return ((float)value).ToString("R", formatInfo);
- }
- }
-
-}
-#endif
\ No newline at end of file
diff --git a/src/Portable.Xaml/Portable.Xaml.ComponentModel/StringConverter.cs b/src/Portable.Xaml/Portable.Xaml.ComponentModel/StringConverter.cs
deleted file mode 100644
index b760e31..0000000
--- a/src/Portable.Xaml/Portable.Xaml.ComponentModel/StringConverter.cs
+++ /dev/null
@@ -1,42 +0,0 @@
-#if !NETSTANDARD
-using System;
-using System.Collections;
-using System.Globalization;
-using System.Reflection;
-using System.Collections.Generic;
-
-namespace Portable.Xaml.ComponentModel
-{
-
- public class StringConverter : TypeConverter
- {
- public override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)
- {
- return sourceType == typeof(string) || base.CanConvertFrom (context, sourceType);
- }
-
- public override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType)
- {
- return destinationType == typeof(string) || base.CanConvertTo (context, destinationType);
- }
-
- public override object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object value)
- {
- var text = value as string;
- if (text != null)
- return text;
- if (value == null)
- return string.Empty;
- return base.ConvertFrom (context, culture, value);
- }
-
- public override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
- {
- if (destinationType == typeof(string) && value is string)
- return value;
- return base.ConvertTo (context, culture, value, destinationType);
- }
- }
-
-}
-#endif
\ No newline at end of file
diff --git a/src/Portable.Xaml/Portable.Xaml.ComponentModel/SystemTypeConverter.cs b/src/Portable.Xaml/Portable.Xaml.ComponentModel/SystemTypeConverter.cs
new file mode 100644
index 0000000..7011e02
--- /dev/null
+++ b/src/Portable.Xaml/Portable.Xaml.ComponentModel/SystemTypeConverter.cs
@@ -0,0 +1,92 @@
+using System;
+using System.Globalization;
+using System.Reflection;
+#if NETSTANDARD
+using System.ComponentModel;
+#endif
+
+namespace Portable.Xaml.ComponentModel
+{
+
+#if !HAS_TYPE_CONVERTER
+ static class TypeDescriptor
+ {
+ static MethodInfo s_getConverterMethod;
+ static object s_getConverterMethodLock = new object();
+
+ public static TypeConverter GetConverter(Type type)
+ {
+ var converterAttribute = type.GetTypeInfo().GetCustomAttribute();
+ if (converterAttribute != null)
+ {
+ var typeConverter = Activator.CreateInstance(Type.GetType(converterAttribute.ConverterTypeName)) as TypeConverter;
+ return typeConverter;
+ }
+
+ if (s_getConverterMethod == null)
+ lock (s_getConverterMethodLock)
+ {
+ if (s_getConverterMethod == null)
+ {
+ var typeDescriptorType = ReflectionHelpers.GetComponentModelType("System.ComponentModel.TypeDescriptor");
+ s_getConverterMethod = typeDescriptorType?.GetRuntimeMethod("GetConverter", new[] { typeof(Type) });
+ }
+ }
+ var converter = s_getConverterMethod?.Invoke(null, new object[] { type });
+ if (converter == null)
+ return null;
+ return new SystemTypeConverter(converter);
+ }
+ }
+
+ class SystemTypeConverter : TypeConverter
+ {
+ object _typeConverter;
+ MethodInfo _canConvertFrom;
+ MethodInfo _canConvertTo;
+ MethodInfo _convertFrom;
+ MethodInfo _convertTo;
+
+ public static readonly Type s_typeDescriptorContentType = ReflectionHelpers.GetComponentModelType("System.ComponentModel.ITypeDescriptorContext");
+
+ public object TypeConverter => _typeConverter;
+
+ public SystemTypeConverter(object typeConverter)
+ {
+ if (s_typeDescriptorContentType == null)
+ throw new XamlException("This platform does not provide System.Component.ITypeDescriptorContext");
+
+ _typeConverter = typeConverter;
+ var type = _typeConverter.GetType();
+ _canConvertFrom = type.GetRuntimeMethod("CanConvertFrom", new[] { s_typeDescriptorContentType, typeof(Type) });
+ _canConvertTo = type.GetRuntimeMethod("CanConvertTo", new[] { s_typeDescriptorContentType, typeof(Type) });
+ _convertFrom = type.GetRuntimeMethod("ConvertFrom", new[] { s_typeDescriptorContentType, typeof(CultureInfo), typeof(object) });
+ _convertTo = type.GetRuntimeMethod("ConvertTo", new[] { s_typeDescriptorContentType, typeof(CultureInfo), typeof(object), typeof(Type) });
+ }
+
+ public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
+ {
+ var c = s_typeDescriptorContentType.GetTypeInfo().IsAssignableFrom(context?.GetType().GetTypeInfo()) ? context : null;
+ return (bool)(_canConvertFrom?.Invoke(_typeConverter, new object[] { c, sourceType }) ?? false);
+ }
+
+ public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
+ {
+ var c = s_typeDescriptorContentType.GetTypeInfo().IsAssignableFrom(context?.GetType().GetTypeInfo()) ? context : null;
+ return (bool)(_canConvertTo?.Invoke(_typeConverter, new object[] { c, destinationType }) ?? false);
+ }
+
+ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
+ {
+ var c = s_typeDescriptorContentType.GetTypeInfo().IsAssignableFrom(context?.GetType().GetTypeInfo()) ? context : null;
+ return _convertFrom?.Invoke(_typeConverter, new object[] { c, culture, value });
+ }
+
+ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
+ {
+ var c = s_typeDescriptorContentType.GetTypeInfo().IsAssignableFrom(context?.GetType().GetTypeInfo()) ? context : null;
+ return _convertTo?.Invoke(_typeConverter, new object[] { c, culture, value, destinationType });
+ }
+ }
+#endif
+}
diff --git a/src/Portable.Xaml/Portable.Xaml.ComponentModel/TimeSpanConverter.cs b/src/Portable.Xaml/Portable.Xaml.ComponentModel/TimeSpanConverter.cs
deleted file mode 100644
index d94792a..0000000
--- a/src/Portable.Xaml/Portable.Xaml.ComponentModel/TimeSpanConverter.cs
+++ /dev/null
@@ -1,40 +0,0 @@
-#if !NETSTANDARD
-using System;
-using System.Collections;
-using System.Globalization;
-using System.Reflection;
-using System.Collections.Generic;
-
-namespace Portable.Xaml.ComponentModel
-{
-
- public class TimeSpanConverter : TypeConverter
- {
- public override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)
- {
- return sourceType == typeof(string) || base.CanConvertFrom (context, sourceType);
- }
-
- public override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType)
- {
- return destinationType == typeof(string) || base.CanConvertTo (context, destinationType);
- }
-
- public override object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object value)
- {
- var text = value as string;
- if (text != null)
- return TimeSpan.Parse (text);
- return base.ConvertFrom (context, culture, value);
- }
-
- public override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
- {
- if (destinationType == typeof(string) && value is TimeSpan)
- return Convert.ToString (value);
- return base.ConvertTo (context, culture, value, destinationType);
- }
- }
-
-}
-#endif
\ No newline at end of file
diff --git a/src/Portable.Xaml/Portable.Xaml.ComponentModel/TypeConverter.cs b/src/Portable.Xaml/Portable.Xaml.ComponentModel/TypeConverter.cs
index 251c668..eb51721 100644
--- a/src/Portable.Xaml/Portable.Xaml.ComponentModel/TypeConverter.cs
+++ b/src/Portable.Xaml/Portable.Xaml.ComponentModel/TypeConverter.cs
@@ -1,4 +1,4 @@
-#if !NETSTANDARD
+#if !HAS_TYPE_CONVERTER
using System;
using System.Collections.Generic;
using System.Globalization;
@@ -14,7 +14,7 @@ namespace Portable.Xaml.ComponentModel
///
/// Type converter implementation, for type converter compatibility in portable class libraries.
///
- public class TypeConverter
+ class TypeConverter
{
///
/// Determines whether this instance can convert from the specified sourceType.
@@ -168,7 +168,7 @@ public virtual object ConvertTo(ITypeDescriptorContext context, CultureInfo cult
if (culture != null)
return Convert.ToString(value, culture);
- return value.ToString();
+ return Convert.ToString(value);
}
return GetConvertToException(value, destinationType);
diff --git a/src/Portable.Xaml/Portable.Xaml.ComponentModel/TypeConverterAttribute.cs b/src/Portable.Xaml/Portable.Xaml.ComponentModel/TypeConverterAttribute.cs
index 5e33906..55e9523 100644
--- a/src/Portable.Xaml/Portable.Xaml.ComponentModel/TypeConverterAttribute.cs
+++ b/src/Portable.Xaml/Portable.Xaml.ComponentModel/TypeConverterAttribute.cs
@@ -1,4 +1,4 @@
-#if PCL && !NETSTANDARD
+#if !HAS_TYPE_CONVERTER
using System;
using System.Collections.Generic;
using System.Globalization;
@@ -15,13 +15,18 @@ namespace Portable.Xaml.ComponentModel
///
/// Type converter attribute, for type converter compatibility in portable class libraries.
///
- public class TypeConverterAttribute : Attribute
+ class TypeConverterAttribute : Attribute
{
+ string _converterTypeName;
///
/// Gets the name of the type for the type converter of the associated type.
///
/// The name of the type.
- public string ConverterTypeName { get; private set; }
+ public string ConverterTypeName
+ {
+ get { return _converterTypeName; }
+ set { _converterTypeName = value; }
+ }
///
/// Initializes a new instance of the class.
diff --git a/src/Portable.Xaml/Portable.Xaml.ComponentModel/TypeDescriptor.cs b/src/Portable.Xaml/Portable.Xaml.ComponentModel/TypeDescriptor.cs
deleted file mode 100644
index cd4fbb6..0000000
--- a/src/Portable.Xaml/Portable.Xaml.ComponentModel/TypeDescriptor.cs
+++ /dev/null
@@ -1,77 +0,0 @@
-#if PCL && !NETSTANDARD
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Portable.Xaml.ComponentModel;
-using System.Runtime.Serialization;
-using System.Reflection;
-
-namespace Portable.Xaml.ComponentModel
-{
-
- ///
- /// Type descriptor for conversion compatibility.
- ///
- public static class TypeDescriptor
- {
- static readonly Dictionary converters = new Dictionary
- {
- { typeof(bool), typeof(BoolConverter) },
- { typeof(char), typeof(CharConverter) },
- { typeof(byte), typeof(ByteConverter) },
- { typeof(Single), typeof(SingleConverter) },
- { typeof(Double), typeof(DoubleConverter) },
- { typeof(Decimal), typeof(DecimalConverter) },
- { typeof(Int16), typeof(Int16Converter) },
- { typeof(Int32), typeof(Int32Converter) },
- { typeof(Int64), typeof(Int64Converter) },
- { typeof(UInt16), typeof(UInt16Converter) },
- { typeof(UInt32), typeof(UInt32Converter) },
- { typeof(UInt64), typeof(UInt64Converter) },
- { typeof(string), typeof(StringConverter) },
- { typeof(Guid), typeof(GuidConverter) },
- { typeof(Uri), typeof(UriTypeConverter) },
- { typeof(TimeSpan), typeof(TimeSpanConverter) },
- { typeof(DateTime), typeof(DateTimeConverter) }
- };
-
- ///
- /// Gets the type converter for the specified type.
- ///
- /// The type converter, or null if the type has no defined converter.
- /// Type to get the converter for.
- public static TypeConverter GetConverter(Type type)
- {
- var attr = type.GetTypeInfo().GetCustomAttribute();
- Type converterType = null;
- if (attr != null)
- converterType = Type.GetType(attr.ConverterTypeName);
- if (converterType == null)
- {
- if (!converters.TryGetValue(type, out converterType))
- {
- /*if (type.GetTypeInfo().IsGenericType && type.GetTypeInfo().GetGenericTypeDefinition() == typeof(Nullable<>))
- return new NullableConverter(type);*/
- if (type.GetTypeInfo().IsEnum)
- return new EnumConverter(type);
- if (typeof(Delegate).GetTypeInfo().IsAssignableFrom(type.GetTypeInfo()))
- return new EventConverter();
- }
- }
-
- if (converterType != null)
- {
- if (converterType.GetTypeInfo().GetConstructors().Any(r => r.GetParameters().Select(p => p.ParameterType).SequenceEqual(new [] { typeof(Type) })))
- return Activator.CreateInstance(converterType, type) as TypeConverter;
- return Activator.CreateInstance(converterType) as TypeConverter;
- }
-
- return null;
- }
- }
-
-}
-#endif
\ No newline at end of file
diff --git a/src/Portable.Xaml/Portable.Xaml.ComponentModel/UInt16Converter.cs b/src/Portable.Xaml/Portable.Xaml.ComponentModel/UInt16Converter.cs
deleted file mode 100644
index 493cf02..0000000
--- a/src/Portable.Xaml/Portable.Xaml.ComponentModel/UInt16Converter.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-#if !NETSTANDARD
-using System;
-using System.Collections;
-using System.Globalization;
-using System.Reflection;
-using System.Collections.Generic;
-
-namespace Portable.Xaml.ComponentModel
-{
- public class UInt16Converter : BaseNumberConverter
- {
- internal override Type NumberType { get { return typeof(UInt16); } }
-
- internal override object FromString (string value, int fromBase)
- {
- return UInt16.Parse (value, CultureInfo.InvariantCulture);
- }
-
- internal override object FromString (string value, NumberFormatInfo formatInfo)
- {
- return UInt16.Parse (value, formatInfo);
- }
- }
-
-}
-#endif
\ No newline at end of file
diff --git a/src/Portable.Xaml/Portable.Xaml.ComponentModel/UInt32Converter.cs b/src/Portable.Xaml/Portable.Xaml.ComponentModel/UInt32Converter.cs
deleted file mode 100644
index 53e03d4..0000000
--- a/src/Portable.Xaml/Portable.Xaml.ComponentModel/UInt32Converter.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-#if !NETSTANDARD
-using System;
-using System.Collections;
-using System.Globalization;
-using System.Reflection;
-using System.Collections.Generic;
-
-namespace Portable.Xaml.ComponentModel
-{
-
- public class UInt32Converter : BaseNumberConverter
- {
- internal override Type NumberType { get { return typeof(UInt32); } }
-
- internal override object FromString (string value, int fromBase)
- {
- return UInt32.Parse (value, CultureInfo.InvariantCulture);
- }
-
- internal override object FromString (string value, NumberFormatInfo formatInfo)
- {
- return UInt32.Parse (value, formatInfo);
- }
- }
-
-}
-#endif
\ No newline at end of file
diff --git a/src/Portable.Xaml/Portable.Xaml.ComponentModel/UInt64Converter.cs b/src/Portable.Xaml/Portable.Xaml.ComponentModel/UInt64Converter.cs
deleted file mode 100644
index 15155e9..0000000
--- a/src/Portable.Xaml/Portable.Xaml.ComponentModel/UInt64Converter.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-#if !NETSTANDARD
-using System;
-using System.Collections;
-using System.Globalization;
-using System.Reflection;
-using System.Collections.Generic;
-
-namespace Portable.Xaml.ComponentModel
-{
-
- public class UInt64Converter : BaseNumberConverter
- {
- internal override Type NumberType { get { return typeof(UInt64); } }
-
- internal override object FromString (string value, int fromBase)
- {
- return UInt64.Parse (value, CultureInfo.InvariantCulture);
- }
-
- internal override object FromString (string value, NumberFormatInfo formatInfo)
- {
- return UInt64.Parse (value, formatInfo);
- }
- }
-
-}
-#endif
\ No newline at end of file
diff --git a/src/Portable.Xaml/Portable.Xaml.ComponentModel/UriTypeConverter.cs b/src/Portable.Xaml/Portable.Xaml.ComponentModel/UriTypeConverter.cs
index 2427d2f..93d670a 100644
--- a/src/Portable.Xaml/Portable.Xaml.ComponentModel/UriTypeConverter.cs
+++ b/src/Portable.Xaml/Portable.Xaml.ComponentModel/UriTypeConverter.cs
@@ -9,7 +9,7 @@
namespace Portable.Xaml.ComponentModel
{
- public class UriTypeConverter : TypeConverter
+ class UriTypeConverter : TypeConverter
{
public override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)
{
diff --git a/src/Portable.Xaml/Portable.Xaml.Markup/IValueSerializerContext.cs b/src/Portable.Xaml/Portable.Xaml.Markup/IValueSerializerContext.cs
index 5f264c8..ab90224 100644
--- a/src/Portable.Xaml/Portable.Xaml.Markup/IValueSerializerContext.cs
+++ b/src/Portable.Xaml/Portable.Xaml.Markup/IValueSerializerContext.cs
@@ -31,7 +31,10 @@
namespace Portable.Xaml.Markup
{
//[System.Runtime.CompilerServices.TypeForwardedFrom (Consts.AssemblyWindowsBase)]
- public interface IValueSerializerContext : ITypeDescriptorContext, IServiceProvider
+ public interface IValueSerializerContext : IServiceProvider
+ #if NETSTANDARD
+ , ITypeDescriptorContext
+ #endif
{
ValueSerializer GetValueSerializerFor (PropertyInfo descriptor);
ValueSerializer GetValueSerializerFor (Type type);
diff --git a/src/Portable.Xaml/Portable.Xaml.Markup/NameReferenceConverter.cs b/src/Portable.Xaml/Portable.Xaml.Markup/NameReferenceConverter.cs
index 3454815..f7da57c 100755
--- a/src/Portable.Xaml/Portable.Xaml.Markup/NameReferenceConverter.cs
+++ b/src/Portable.Xaml/Portable.Xaml.Markup/NameReferenceConverter.cs
@@ -30,7 +30,10 @@
namespace Portable.Xaml.Markup
{
- public class NameReferenceConverter : TypeConverter
+#if HAS_TYPE_CONVERTER
+ public
+#endif
+ class NameReferenceConverter : TypeConverter
{
public override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)
{
diff --git a/src/Portable.Xaml/Portable.Xaml.Markup/ValueSerializer.cs b/src/Portable.Xaml/Portable.Xaml.Markup/ValueSerializer.cs
index 536da13..7bc7753 100644
--- a/src/Portable.Xaml/Portable.Xaml.Markup/ValueSerializer.cs
+++ b/src/Portable.Xaml/Portable.Xaml.Markup/ValueSerializer.cs
@@ -54,13 +54,8 @@ public static ValueSerializer GetSerializerFor(PropertyInfo descriptor, IValueSe
if (context != null)
return context.GetValueSerializerFor(descriptor);
- var typeConverterInfo = descriptor.GetCustomAttribute();
- var typeConverterName = typeConverterInfo?.ConverterTypeName;
- if (string.IsNullOrEmpty(typeConverterName))
- return null;
- var tcType = Type.GetType(typeConverterName);
- var tc = Activator.CreateInstance(tcType) as TypeConverter;
- if (tc != null && tc.GetType() != typeof(TypeConverter))
+ var tc = descriptor.GetTypeConverter();
+ if (tc != null && !tc.IsBaseTypeConverter())
return new TypeConverterValueSerializer(tc);
return null;
}
@@ -91,16 +86,14 @@ public static ValueSerializer GetSerializerFor(Type type, IValueSerializerContex
// Since System.Type does not have a valid TypeConverter, I use TypeExtensionConverter (may sound funny considering the above notes!) for this serializer.
return new TypeValueSerializer();
-#if NETSTANDARD
if (type == typeof(Array))
return null;
-#endif
// FIXME: this is hack. The complete condition is fully documented at http://msdn.microsoft.com/en-us/library/ms590363.aspx
- if (type.GetTypeInfo().GetCustomAttribute(true) != null)
+ if (type.GetTypeInfo().GetTypeConverterName(true) != null)
{
var tc = type.GetTypeConverter();
- if (tc != null && tc.GetType() != typeof(TypeConverter))
+ if (tc != null && !tc.IsBaseTypeConverter())
return new TypeConverterValueSerializer(tc);
}
@@ -109,7 +102,7 @@ public static ValueSerializer GetSerializerFor(Type type, IValueSerializerContex
if (type != typeof(object) || type == typeof(TimeSpan))
{
var typeConverter = type.GetTypeConverter ();
- if (typeConverter != null && typeConverter.GetType() != typeof(TypeConverter))
+ if (typeConverter != null && !typeConverter.IsBaseTypeConverter())
return new TypeConverterValueSerializer (typeConverter);
}
@@ -211,7 +204,7 @@ public override object ConvertFromString (string value, IValueSerializerContext
public override string ConvertToString (object value, IValueSerializerContext context)
{
- return (string) txc.ConvertTo (context, CultureInfo.InvariantCulture, value, typeof (string));
+ return (string) txc.ConvertTo ((ITypeDescriptorContext)context, CultureInfo.InvariantCulture, value, typeof (string));
}
public override IEnumerable TypeReferences (object value, IValueSerializerContext context)
@@ -231,22 +224,22 @@ public TypeConverterValueSerializer (TypeConverter typeConverter)
public override bool CanConvertFromString (string value, IValueSerializerContext context)
{
- return c.CanConvertFrom (context, typeof (string));
+ return c.CanConvertFrom ((ITypeDescriptorContext)context, typeof (string));
}
public override bool CanConvertToString (object value, IValueSerializerContext context)
{
- return c.CanConvertTo (context, typeof (string));
+ return c.CanConvertTo ((ITypeDescriptorContext)context, typeof (string));
}
public override object ConvertFromString (string value, IValueSerializerContext context)
{
- return c.ConvertFrom (context, CultureInfo.InvariantCulture, value);
+ return c.ConvertFrom ((ITypeDescriptorContext)context, CultureInfo.InvariantCulture, value);
}
public override string ConvertToString (object value, IValueSerializerContext context)
{
- return value == null ? String.Empty : (string) c.ConvertTo (context, CultureInfo.InvariantCulture, value, typeof (string));
+ return value == null ? String.Empty : (string) c.ConvertTo ((ITypeDescriptorContext)context, CultureInfo.InvariantCulture, value, typeof (string));
}
public override IEnumerable TypeReferences (object value, IValueSerializerContext context)
diff --git a/src/Portable.Xaml/Portable.Xaml.Markup/XamlSetTypeConverterEventArgs.cs b/src/Portable.Xaml/Portable.Xaml.Markup/XamlSetTypeConverterEventArgs.cs
index 8294f52..0efae9c 100644
--- a/src/Portable.Xaml/Portable.Xaml.Markup/XamlSetTypeConverterEventArgs.cs
+++ b/src/Portable.Xaml/Portable.Xaml.Markup/XamlSetTypeConverterEventArgs.cs
@@ -33,7 +33,12 @@ namespace Portable.Xaml.Markup
{
public class XamlSetTypeConverterEventArgs : XamlSetValueEventArgs
{
- public XamlSetTypeConverterEventArgs (XamlMember member, TypeConverter typeConverter, object value, ITypeDescriptorContext serviceProvider, CultureInfo cultureInfo)
+#if HAS_TYPE_CONVERTER
+ public
+#else
+ internal
+#endif
+ XamlSetTypeConverterEventArgs (XamlMember member, TypeConverter typeConverter, object value, ITypeDescriptorContext serviceProvider, CultureInfo cultureInfo)
: base (member, value)
{
CultureInfo = cultureInfo;
@@ -42,8 +47,19 @@ public XamlSetTypeConverterEventArgs (XamlMember member, TypeConverter typeConve
}
public CultureInfo CultureInfo { get; private set; }
- public ITypeDescriptorContext ServiceProvider { get; private set; }
- public TypeConverter TypeConverter { get; private set; }
+#if HAS_TYPE_CONVERTER
+ public
+#else
+ internal
+#endif
+ ITypeDescriptorContext ServiceProvider { get; private set; }
+
+#if HAS_TYPE_CONVERTER
+ public
+#else
+ internal
+#endif
+ TypeConverter TypeConverter { get; private set; }
public override void CallBase ()
{
diff --git a/src/Portable.Xaml/Portable.Xaml.Schema/XamlTypeTypeConverter.cs b/src/Portable.Xaml/Portable.Xaml.Schema/XamlTypeTypeConverter.cs
index 5c3a867..721aa26 100644
--- a/src/Portable.Xaml/Portable.Xaml.Schema/XamlTypeTypeConverter.cs
+++ b/src/Portable.Xaml/Portable.Xaml.Schema/XamlTypeTypeConverter.cs
@@ -30,36 +30,40 @@
namespace Portable.Xaml.Schema
{
- public class XamlTypeTypeConverter : TypeConverter
+ #if HAS_TYPE_CONVERTER
+ public
+ #endif
+ class XamlTypeTypeConverter : TypeConverter
{
- public override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)
+ public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
- return sourceType == typeof (string);
+ return sourceType == typeof(string);
}
- public override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType)
+ public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
- return destinationType == typeof (string);
+ return destinationType == typeof(string);
}
- public override Object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, Object value)
+ public override Object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
{
- throw new NotSupportedException (String.Format ("Conversion from type {0} is not supported", value != null ? value.GetType () : null));
+ throw new NotSupportedException(String.Format("Conversion from type {0} is not supported", value != null ? value.GetType() : null));
}
- public override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
+ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
- if (!CanConvertTo (context, destinationType))
- throw new NotSupportedException (String.Format ("Conversion to type {0} is not supported", destinationType));
+ if (!CanConvertTo(context, destinationType))
+ throw new NotSupportedException(String.Format("Conversion to type {0} is not supported", destinationType));
- var vctx = (IValueSerializerContext) context;
- var lookup = vctx != null ? (INamespacePrefixLookup) vctx.GetService (typeof (INamespacePrefixLookup)) : null;
+ var vctx = (IValueSerializerContext)context;
+ var lookup = vctx != null ? (INamespacePrefixLookup)vctx.GetService(typeof(INamespacePrefixLookup)) : null;
var xt = value as XamlType;
- if (xt != null && destinationType == typeof (string)) {
+ if (xt != null && destinationType == typeof(string))
+ {
if (lookup != null)
- return new XamlTypeName (xt).ToString (lookup);
+ return new XamlTypeName(xt).ToString(lookup);
else
- return xt.UnderlyingType != null ? xt.UnderlyingType.ToString () : xt.ToString ();
+ return xt.UnderlyingType != null ? xt.UnderlyingType.ToString() : xt.ToString();
}
else
return base.ConvertTo (context, culture, value, destinationType); // it seems it still handles not-supported types (such as int).
diff --git a/src/Portable.Xaml/Portable.Xaml.Schema/XamlValueConverter.cs b/src/Portable.Xaml/Portable.Xaml.Schema/XamlValueConverter.cs
index 0939c76..d80fdc0 100644
--- a/src/Portable.Xaml/Portable.Xaml.Schema/XamlValueConverter.cs
+++ b/src/Portable.Xaml/Portable.Xaml.Schema/XamlValueConverter.cs
@@ -1,4 +1,4 @@
-//
+//
// Copyright (C) 2010 Novell Inc. http://novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
@@ -29,6 +29,50 @@
namespace Portable.Xaml.Schema
{
+#if !HAS_TYPE_CONVERTER
+ class XamlTypeValueConverter : XamlValueConverter
+ where TConverterBase: class
+ {
+ public XamlTypeValueConverter(Type converterType, XamlType targetType)
+ : base(converterType, targetType)
+ {
+ }
+
+ public XamlTypeValueConverter(Type converterType, XamlType targetType, string name)
+ : base(converterType, targetType, name)
+ {
+ }
+
+ static Type s_typeConverterType = ReflectionHelpers.GetComponentModelType("System.ComponentModel.TypeConverter");
+
+ protected override TConverterBase CreateInstance()
+ {
+ if (ConverterType == null)
+ return null;
+
+ if (!typeof(TConverterBase).GetTypeInfo().IsAssignableFrom(ConverterType.GetTypeInfo())
+ && !s_typeConverterType.GetTypeInfo().IsAssignableFrom(ConverterType.GetTypeInfo()))
+ throw new XamlSchemaException(String.Format("ConverterType '{0}' is not derived from '{1}' or '{2}' types", ConverterType, typeof(TConverterBase), s_typeConverterType));
+
+ object instance = null;
+ if (ConverterType.GetTypeInfo().GetConstructors().Any(r => r.GetParameters().Length == 0))
+ instance = Activator.CreateInstance(ConverterType);
+
+ if (ConverterType.GetTypeInfo().GetConstructors().Any(r => r.GetParameters().Length == 1 && r.GetParameters()[0].ParameterType == typeof(Type)))
+ instance = Activator.CreateInstance(ConverterType, TargetType.UnderlyingType);
+
+ if (instance == null)
+ return null;
+
+ var tc = instance as TConverterBase;
+ if (tc != null)
+ return tc;
+
+ return (TConverterBase)(object)new SystemTypeConverter(instance);
+ }
+ }
+#endif
+
public class XamlValueConverter : IEquatable>
where TConverterBase : class
{
@@ -46,7 +90,6 @@ public XamlValueConverter (Type converterType, XamlType targetType, string name)
Name = name;
}
- internal TConverterBase InitialConverterInstance { get; set; }
TConverterBase converter_instance;
public TConverterBase ConverterInstance
{
@@ -56,6 +99,10 @@ public TConverterBase ConverterInstance
converter_instance = CreateInstance();
return converter_instance;
}
+ internal set
+ {
+ converter_instance = value;
+ }
}
public Type ConverterType { get; private set; }
public string Name { get; private set; }
@@ -85,13 +132,11 @@ public override bool Equals (object obj)
protected virtual TConverterBase CreateInstance ()
{
- if (InitialConverterInstance != null)
- return InitialConverterInstance;
if (ConverterType == null)
return null;
- if (!typeof (TConverterBase).GetTypeInfo().IsAssignableFrom (ConverterType.GetTypeInfo()))
- throw new XamlSchemaException (String.Format ("ConverterType '{0}' is not derived from '{1}' type", ConverterType, typeof (TConverterBase)));
+ if (!typeof(TConverterBase).GetTypeInfo().IsAssignableFrom(ConverterType.GetTypeInfo()))
+ throw new XamlSchemaException(String.Format("ConverterType '{0}' is not derived from '{1}' type", ConverterType, typeof(TConverterBase)));
if (ConverterType.GetTypeInfo().GetConstructors().Any(r => r.GetParameters().Length == 0))
return (TConverterBase) Activator.CreateInstance (ConverterType);
diff --git a/src/Portable.Xaml/Portable.Xaml.nuspec b/src/Portable.Xaml/Portable.Xaml.nuspec
index dc47377..f5b62b9 100644
--- a/src/Portable.Xaml/Portable.Xaml.nuspec
+++ b/src/Portable.Xaml/Portable.Xaml.nuspec
@@ -19,7 +19,6 @@ This allows you to read/write xaml for desktop, mobile, and .NET Core projects.
cross platform xaml
-
@@ -30,9 +29,8 @@ This allows you to read/write xaml for desktop, mobile, and .NET Core projects.
-
-
-
-
+
+
+
\ No newline at end of file
diff --git a/src/Portable.Xaml/Portable.Xaml/TypeExtensionMethods.cs b/src/Portable.Xaml/Portable.Xaml/TypeExtensionMethods.cs
index 3285e6d..49eb887 100644
--- a/src/Portable.Xaml/Portable.Xaml/TypeExtensionMethods.cs
+++ b/src/Portable.Xaml/Portable.Xaml/TypeExtensionMethods.cs
@@ -1,4 +1,4 @@
-//
+//
// Copyright (C) 2010 Novell Inc. http://novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
@@ -37,13 +37,20 @@ static class TypeExtensionMethods
{
#region inheritance search and custom attribute provision
- public static T GetCustomAttribute (this ICustomAttributeProvider type, bool inherit) where T : Attribute
+ public static T GetCustomAttribute (this ICustomAttributeProvider provider, bool inherit) where T : Attribute
{
- foreach (var a in type.GetCustomAttributes (typeof(T), inherit))
+ foreach (var a in provider.GetCustomAttributes (typeof(T), inherit))
return (T)(object)a;
return null;
}
+ public static Attribute GetCustomAttribute(this ICustomAttributeProvider provider, Type type, bool inherit)
+ {
+ foreach (var a in provider.GetCustomAttributes(type, inherit))
+ return (Attribute)(object)a;
+ return null;
+ }
+
public static T GetCustomAttribute (this XamlType type) where T : Attribute
{
if (type.UnderlyingType == null)
@@ -113,16 +120,111 @@ public static string GetStringValue (XamlType xt, XamlMember xm, object obj, IVa
// FIXME: does this make sense?
var vc = xm?.TypeConverter ?? xt.TypeConverter;
var tc = vc?.ConverterInstance;
- if (tc != null && tc.CanConvertTo (vsctx, typeof(string)))
- return (string)tc.ConvertTo (vsctx, CultureInfo.InvariantCulture, obj, typeof(string));
+ if (tc != null && tc.CanConvertTo ((ITypeDescriptorContext) vsctx, typeof(string)))
+ return (string)tc.ConvertTo ((ITypeDescriptorContext)vsctx, CultureInfo.InvariantCulture, obj, typeof(string));
if (obj is string || obj == null)
return (string)obj;
throw new InvalidCastException (String.Format ("Cannot cast object '{0}' to string", obj.GetType ()));
}
- public static TypeConverter GetTypeConverter (this Type type)
+#if !HAS_TYPE_CONVERTER
+ static Type s_typeConverterAttribute = ReflectionHelpers.GetComponentModelType("System.ComponentModel.TypeConverterAttribute");
+ static PropertyInfo s_typeConverterTypeNameProperty = s_typeConverterAttribute?.GetRuntimeProperty("ConverterTypeName");
+#endif
+
+ public static string GetTypeConverterName(this ICustomAttributeProvider member, bool inherit)
+ {
+ if (member == null)
+ return null;
+ var typeConverterName = member.GetCustomAttribute(inherit)?.ConverterTypeName;
+#if !HAS_TYPE_CONVERTER
+ if (typeConverterName == null && s_typeConverterAttribute != null)
+ {
+ var systemTypeConverterInfo = member.GetCustomAttribute(s_typeConverterAttribute, inherit);
+ if (systemTypeConverterInfo != null)
+ {
+ typeConverterName = s_typeConverterTypeNameProperty.GetValue(systemTypeConverterInfo) as string;
+ }
+ }
+#endif
+ return typeConverterName;
+ }
+
+ public static string GetTypeConverterName(this MemberInfo member, bool inherit)
+ {
+ if (member == null)
+ return null;
+ var typeConverterName = member.GetCustomAttribute(inherit)?.ConverterTypeName;
+#if !HAS_TYPE_CONVERTER
+ if (typeConverterName == null && s_typeConverterAttribute != null)
+ {
+ var systemTypeConverterInfo = member.GetCustomAttribute(s_typeConverterAttribute);
+ if (systemTypeConverterInfo != null)
+ {
+ typeConverterName = s_typeConverterTypeNameProperty.GetValue(systemTypeConverterInfo) as string;
+ }
+ }
+#endif
+ return typeConverterName;
+ }
+
+ public static string GetTypeConverterName(this TypeInfo type, bool inherit)
+ {
+ if (type == null)
+ return null;
+ var typeConverterName = type.GetCustomAttribute(inherit)?.ConverterTypeName;
+#if !HAS_TYPE_CONVERTER
+ if (typeConverterName == null && s_typeConverterAttribute != null)
+ {
+ var systemTypeConverterInfo = type.GetCustomAttribute(s_typeConverterAttribute);
+ if (systemTypeConverterInfo != null)
+ {
+ typeConverterName = s_typeConverterTypeNameProperty.GetValue(systemTypeConverterInfo) as string;
+ }
+ }
+#endif
+ return typeConverterName;
+ }
+
+ public static bool IsBaseTypeConverter(this TypeConverter typeConverter)
+ {
+#if HAS_TYPE_CONVERTER
+ var type = typeConverter.GetType();
+ return type == typeof(TypeConverter)
+ || type == typeof(CollectionConverter)
+ || type.FullName == "System.ComponentModel.ReferenceConverter";
+#else
+ var sysType = typeConverter as SystemTypeConverter;
+ var type = sysType?.TypeConverter.GetType() ?? typeConverter.GetType();
+ var fullName = type.FullName;
+ return fullName == "System.ComponentModel.TypeConverter"
+ || fullName == "System.ComponentModel.CollectionConverter"
+ || fullName == "System.ComponentModel.ReferenceConverter";
+#endif
+ }
+
+ public static TypeConverter GetTypeConverter(this MemberInfo member)
+ {
+ var typeConverterName = GetTypeConverterName(member, true);
+ if (string.IsNullOrEmpty(typeConverterName))
+ return null;
+
+ var tcType = Type.GetType(typeConverterName);
+
+ var tc = Activator.CreateInstance(tcType);
+#if HAS_TYPE_CONVERTER
+ return tc as TypeConverter;
+#else
+ if (tc is TypeConverter typeConverter)
+ return typeConverter;
+
+ return new SystemTypeConverter(tc);
+#endif
+ }
+
+ public static TypeConverter GetTypeConverter(this Type type)
{
- return TypeDescriptor.GetConverter (type);
+ return TypeDescriptor.GetConverter(type);
}
/*
@@ -167,7 +269,7 @@ public static bool IsContentValue (this XamlMember member, IValueSerializerConte
if (ReferenceEquals(member, XamlLanguage.PositionalParameters) || ReferenceEquals(member, XamlLanguage.Arguments))
return false; // it's up to the argument (no need to check them though, as IList