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 is not of value) var typeConverter = member.TypeConverter; - if (typeConverter != null && typeConverter.ConverterInstance != null && typeConverter.ConverterInstance.CanConvertTo (vsctx, typeof(string))) + if (typeConverter != null && typeConverter.ConverterInstance != null && typeConverter.ConverterInstance.CanConvertTo ((ITypeDescriptorContext)vsctx, typeof(string))) return true; return IsContentValue (member.Type, vsctx); } @@ -175,7 +277,7 @@ public static bool IsContentValue (this XamlMember member, IValueSerializerConte public static bool IsContentValue (this XamlType type, IValueSerializerContext vsctx) { var typeConverter = type.TypeConverter; - if (typeConverter != null && typeConverter.ConverterInstance != null && typeConverter.ConverterInstance.CanConvertTo (vsctx, typeof(string))) + if (typeConverter != null && typeConverter.ConverterInstance != null && typeConverter.ConverterInstance.CanConvertTo ((ITypeDescriptorContext)vsctx, typeof(string))) return true; return false; } diff --git a/src/Portable.Xaml/Portable.Xaml/ValueSerializerContext.cs b/src/Portable.Xaml/Portable.Xaml/ValueSerializerContext.cs index 29be78d..88bb03a 100644 --- a/src/Portable.Xaml/Portable.Xaml/ValueSerializerContext.cs +++ b/src/Portable.Xaml/Portable.Xaml/ValueSerializerContext.cs @@ -1,4 +1,4 @@ -// +// // Copyright (C) 2010 Novell Inc. http://novell.com // // Permission is hereby granted, free of charge, to any person obtaining @@ -33,6 +33,18 @@ using Portable.Xaml.Schema; using System.Xml; using System.ComponentModel; +using System.Reflection.Emit; +using System.Runtime.CompilerServices; + +#if !HAS_TYPE_CONVERTER + +#if STRONGNAME +[assembly: InternalsVisibleTo("Portable.Xaml.Compat, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d1c3c3fdff475bd48ad578039ab969e954c6378b6c7ab21ebcb1059d450b8c77e8260b1d6c227f6da946a45f1e67dea68e5e45daa21cd208bc9ea72c86568de861c64fd2c57d16a955ad24fb8b1cd78f4b7f9747014e69a1dfb3ea4dab6eb3a76a639dfb51eda575d5906831ca9cf251a200010d84faafb0ca64eae3504fecdc")] +#else +[assembly: InternalsVisibleTo("Portable.Xaml.Compat")] +#endif + +#endif namespace Portable.Xaml { @@ -49,14 +61,110 @@ internal class ValueSerializerContext : IValueSerializerContext, IXamlSchemaCont IDestinationTypeProvider destinationProvider; IXamlObjectWriterFactory objectWriterFactory; - public ValueSerializerContext(PrefixLookup prefixLookup, XamlSchemaContext schemaContext, IAmbientProvider ambientProvider, IProvideValueTarget provideValue, IRootObjectProvider rootProvider, IDestinationTypeProvider destinationProvider, IXamlObjectWriterFactory objectWriterFactory) +#if !HAS_TYPE_CONVERTER + + static bool s_valueSerializerTypeInitialized; + static Type s_valueSerializerType; + + static Type GetValueSerializerType() + { + if (s_valueSerializerTypeInitialized) + return s_valueSerializerType; + s_valueSerializerTypeInitialized = true; + + // use reflection.emit to create a subclass of ValueSerializerContext that implements + // System.ComponentModel.ITypeDescriptorContext since we can't access it here. + var typeName = "SystemValueSerializerContext"; + + var appDomainType = ReflectionHelpers.GetCorlibType("System.AppDomain"); + var assemblyBuilderAccess = ReflectionHelpers.GetCorlibType("System.Reflection.Emit.AssemblyBuilderAccess"); + var typeAttributesType = ReflectionHelpers.GetCorlibType("System.Reflection.TypeAttributes"); + var currentDomainProp = appDomainType?.GetRuntimeProperty("CurrentDomain"); + var typeDescriptorContextType = ReflectionHelpers.GetComponentModelType("System.ComponentModel.ITypeDescriptorContext"); + var containerType = ReflectionHelpers.GetComponentModelType("System.ComponentModel.IContainer"); + var propertyDescriptorType = ReflectionHelpers.GetComponentModelType("System.ComponentModel.PropertyDescriptor"); + var strongNameKeyPairType = ReflectionHelpers.GetCorlibType("System.Reflection.StrongNameKeyPair"); + if (appDomainType == null + || assemblyBuilderAccess == null + || typeAttributesType == null + || currentDomainProp == null + || typeDescriptorContextType == null + || containerType == null + || propertyDescriptorType == null + || strongNameKeyPairType == null + ) + return null; + + object currentDomain = currentDomainProp.GetValue(null); + + dynamic an = new AssemblyName("Portable.Xaml.Compat"); +#if STRONGNAME + using (var stream = typeof(ValueSerializerContext).GetTypeInfo().Assembly.GetManifestResourceStream("Portable.Xaml.Compat.snk")) + { + var data = new byte[stream.Length]; + stream.Read(data, 0, (int)stream.Length); + dynamic keyPair = Activator.CreateInstance(strongNameKeyPairType, data); + an.KeyPair = keyPair; + + } +#endif + + dynamic assemblyBuilder = appDomainType + .GetRuntimeMethod("DefineDynamicAssembly", new Type[] { typeof(AssemblyName), assemblyBuilderAccess }) + .Invoke(currentDomain, new object[] { an, 1 }); + + object moduleBuilder = assemblyBuilder.DefineDynamicModule("MainModule"); + + dynamic typeBuilder = moduleBuilder + .GetType() + .GetRuntimeMethod("DefineType", new Type[] { typeof(string), typeAttributesType, typeof(Type) }) + .Invoke(moduleBuilder, new object[] { typeName, 0, typeof(ValueSerializerContext) }); // 0 = Class + + typeBuilder.AddInterfaceImplementation(typeDescriptorContextType); + + Type notImplementedException = typeof(NotImplementedException); + var notImplementedExceptionConstructor = notImplementedException.GetTypeInfo().GetConstructors().First(r => r.GetParameters().Length == 0); + + var getSetAttr = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.Virtual;; + //public IContainer Container => throw new NotImplementedException(); + var propertyBuilder = typeBuilder.DefineProperty("Container", PropertyAttributes.None, containerType, null); + var getter = typeBuilder.DefineMethod("get_Container", getSetAttr, containerType, null); + var il = getter.GetILGenerator(); + il.ThrowException(notImplementedException); + propertyBuilder.SetGetMethod(getter); + + //public PropertyDescriptor PropertyDescriptor => throw new NotImplementedException(); + propertyBuilder = typeBuilder.DefineProperty("PropertyDescriptor", PropertyAttributes.None, propertyDescriptorType, null); + getter = typeBuilder.DefineMethod("get_PropertyDescriptor", getSetAttr, propertyDescriptorType, null); + il = getter.GetILGenerator(); + il.ThrowException(notImplementedException); + propertyBuilder.SetGetMethod(getter); + + s_valueSerializerType = typeBuilder.CreateType(); + return s_valueSerializerType; + } +#endif + + public static ValueSerializerContext Create(PrefixLookup prefixLookup, XamlSchemaContext schemaContext, IAmbientProvider ambientProvider, IProvideValueTarget provideValue, IRootObjectProvider rootProvider, IDestinationTypeProvider destinationProvider, IXamlObjectWriterFactory objectWriterFactory) { - if (prefixLookup == null) - throw new ArgumentNullException("prefixLookup"); - if (schemaContext == null) - throw new ArgumentNullException("schemaContext"); - prefix_lookup = prefixLookup; - sctx = schemaContext; +#if !HAS_TYPE_CONVERTER + ValueSerializerContext context; + var type = GetValueSerializerType(); + if (type != null) + context = Activator.CreateInstance(type) as ValueSerializerContext; + else + context = new ValueSerializerContext(); +#else + var context = new ValueSerializerContext(); +#endif + context.Initialize(prefixLookup, schemaContext, ambientProvider, provideValue, rootProvider, destinationProvider, objectWriterFactory); + return context; + } + + void Initialize(PrefixLookup prefixLookup, XamlSchemaContext schemaContext, IAmbientProvider ambientProvider, IProvideValueTarget provideValue, IRootObjectProvider rootProvider, IDestinationTypeProvider destinationProvider, IXamlObjectWriterFactory objectWriterFactory) + { + prefix_lookup = prefixLookup ?? throw new ArgumentNullException("prefixLookup"); + sctx = schemaContext ?? throw new ArgumentNullException("schemaContext"); ambient_provider = ambientProvider; this.provideValue = provideValue; this.rootProvider = rootProvider; @@ -95,36 +203,23 @@ public object GetService(Type serviceType) return null; } - XamlSchemaContext IXamlSchemaContextProvider.SchemaContext - { - get { return sctx; } - } + XamlSchemaContext IXamlSchemaContextProvider.SchemaContext => sctx; - public object Instance - { - get { throw new NotImplementedException(); } - } + public virtual object Instance => throw new NotImplementedException(); -#if NETSTANDARD +#if HAS_TYPE_CONVERTER public IContainer Container => throw new NotImplementedException(); public PropertyDescriptor PropertyDescriptor => throw new NotImplementedException(); #else - /* - public IContainer Container { - get { throw new NotImplementedException (); } - }*/ - public PropertyInfo PropertyDescriptor - { - get { throw new NotImplementedException(); } - } + public PropertyInfo PropertyDescriptor => throw new NotImplementedException(); #endif - public void OnComponentChanged() + public virtual void OnComponentChanged() { throw new NotImplementedException(); } - public bool OnComponentChanging () + public virtual bool OnComponentChanging () { throw new NotImplementedException (); } diff --git a/src/Portable.Xaml/Portable.Xaml/XamlDirective.cs b/src/Portable.Xaml/Portable.Xaml/XamlDirective.cs index 48deecf..b2c7099 100644 --- a/src/Portable.Xaml/Portable.Xaml/XamlDirective.cs +++ b/src/Portable.Xaml/Portable.Xaml/XamlDirective.cs @@ -49,7 +49,12 @@ public XamlDirective (string xamlNamespace, string name) is_unknown = true; } - public XamlDirective (IEnumerable xamlNamespaces, string name, XamlType xamlType, XamlValueConverter typeConverter, AllowedMemberLocations allowedLocation) +#if HAS_TYPE_CONVERTER + public +#else + internal +#endif + XamlDirective (IEnumerable xamlNamespaces, string name, XamlType xamlType, XamlValueConverter typeConverter, AllowedMemberLocations allowedLocation) : base (true, xamlNamespaces != null ? xamlNamespaces.FirstOrDefault () : null, name) { if (xamlNamespaces == null) @@ -150,7 +155,12 @@ protected override sealed XamlType LookupType () return type; } - protected override sealed XamlValueConverter LookupTypeConverter () +#if HAS_TYPE_CONVERTER + protected +#else + internal +#endif + override sealed XamlValueConverter LookupTypeConverter () { if (type_converter == null) type_converter = base.LookupTypeConverter (); diff --git a/src/Portable.Xaml/Portable.Xaml/XamlMember.cs b/src/Portable.Xaml/Portable.Xaml/XamlMember.cs index db34ed9..183a600 100644 --- a/src/Portable.Xaml/Portable.Xaml/XamlMember.cs +++ b/src/Portable.Xaml/Portable.Xaml/XamlMember.cs @@ -295,7 +295,12 @@ bool LookupShouldSerialize() public XamlType Type => type.HasValue ? type.Value : type.Set(LookupType()); - public XamlValueConverter TypeConverter => typeConverter.HasValue ? typeConverter.Value : typeConverter.Set(LookupTypeConverter()); +#if HAS_TYPE_CONVERTER + public +#else + internal +#endif + XamlValueConverter TypeConverter => typeConverter.HasValue ? typeConverter.Value : typeConverter.Set(LookupTypeConverter()); public MemberInfo UnderlyingMember => underlying_member ?? (underlying_member = LookupUnderlyingMember()); @@ -487,7 +492,12 @@ Type DoGetType() return typeof(object); } - protected virtual XamlValueConverter LookupTypeConverter() +#if HAS_TYPE_CONVERTER + protected +#else + internal +#endif + virtual XamlValueConverter LookupTypeConverter() { var t = Type.UnderlyingType; if (t == null) @@ -496,14 +506,11 @@ protected virtual XamlValueConverter LookupTypeConverter() return null; - var a = CustomAttributeProvider; - var ca = a != null ? a.GetCustomAttribute(false) : null; - if (ca != null) - return context.GetValueConverter(System.Type.GetType(ca.ConverterTypeName), Type); -#if NETSTANDARD + var converterName = CustomAttributeProvider.GetTypeConverterName(false); + if (converterName != null) + return context.GetValueConverter(System.Type.GetType(converterName), Type); if (IsEvent) return context.GetValueConverter(typeof(EventConverter), Type); -#endif return Type.TypeConverter; } diff --git a/src/Portable.Xaml/Portable.Xaml/XamlObjectReader.cs b/src/Portable.Xaml/Portable.Xaml/XamlObjectReader.cs index 1501ecd..7864b0f 100644 --- a/src/Portable.Xaml/Portable.Xaml/XamlObjectReader.cs +++ b/src/Portable.Xaml/Portable.Xaml/XamlObjectReader.cs @@ -99,7 +99,7 @@ public XamlObjectReader (object instance, XamlSchemaContext schemaContext, XamlO throw new XamlObjectReaderException (String.Format ("instance type '{0}' has no default constructor.", type)); } - value_serializer_context = new ValueSerializerContext (new PrefixLookup (sctx), sctx, null, null, null, null, null); + value_serializer_context = ValueSerializerContext.Create(new PrefixLookup (sctx), sctx, null, null, null, null, null); new XamlObjectNodeIterator (instance, sctx, value_serializer_context, this.settings).PrepareReading (); } diff --git a/src/Portable.Xaml/Portable.Xaml/XamlSchemaContext.cs b/src/Portable.Xaml/Portable.Xaml/XamlSchemaContext.cs index 32b4fee..3499d96 100644 --- a/src/Portable.Xaml/Portable.Xaml/XamlSchemaContext.cs +++ b/src/Portable.Xaml/Portable.Xaml/XamlSchemaContext.cs @@ -343,6 +343,12 @@ public virtual string GetPreferredPrefix(string xmlns) protected internal XamlValueConverter GetValueConverter(Type converterType, XamlType targetType) where TConverterBase : class { +#if !HAS_TYPE_CONVERTER + if (typeof(TConverterBase) == typeof(TypeConverter)) + { + return new XamlTypeValueConverter(converterType, targetType); + } +#endif return new XamlValueConverter(converterType, targetType); } diff --git a/src/Portable.Xaml/Portable.Xaml/XamlType.cs b/src/Portable.Xaml/Portable.Xaml/XamlType.cs index bbec23b..781b5e6 100644 --- a/src/Portable.Xaml/Portable.Xaml/XamlType.cs +++ b/src/Portable.Xaml/Portable.Xaml/XamlType.cs @@ -270,7 +270,12 @@ string LookupPreferredXamlNamespace() public IList TypeArguments { get; private set; } - public XamlValueConverter TypeConverter => typeConverter.HasValue ? typeConverter.Value : typeConverter.Set(LookupTypeConverter()); +#if HAS_TYPE_CONVERTER + public +#else + internal +#endif + XamlValueConverter TypeConverter => typeConverter.HasValue ? typeConverter.Value : typeConverter.Set(LookupTypeConverter()); public Type UnderlyingType => underlying_type ?? (underlying_type = LookupUnderlyingType()); @@ -942,7 +947,12 @@ protected virtual bool LookupTrimSurroundingWhitespace() return this.GetCustomAttribute() != null; } - protected virtual XamlValueConverter LookupTypeConverter() +#if HAS_TYPE_CONVERTER + protected +#else + internal +#endif + virtual XamlValueConverter LookupTypeConverter() { var t = UnderlyingType; if (t == null) @@ -955,10 +965,9 @@ protected virtual XamlValueConverter LookupTypeConverter() t = Nullable.GetUnderlyingType(t) ?? t; - var a = CustomAttributeProvider; - var ca = a?.GetCustomAttribute(false); - if (ca != null) - return SchemaContext.GetValueConverter(Type.GetType(ca.ConverterTypeName), this); + var converterName = CustomAttributeProvider.GetTypeConverterName(false); + if (converterName != null) + return SchemaContext.GetValueConverter(Type.GetType(converterName), this); if (t == typeof(object)) // This is a special case. ConverterType is null. return SchemaContext.GetValueConverter(null, this); @@ -970,21 +979,13 @@ protected virtual XamlValueConverter LookupTypeConverter() return SchemaContext.GetValueConverter(typeof(UriTypeConverter), this); // It's still not decent to check CollectionConverter. + var tc = t.GetTypeConverter(); - var tct = tc?.GetType(); - if (tct != null - && tct != typeof(TypeConverter) -#if NETSTANDARD - && tct != typeof(CollectionConverter) -#else - && tct.FullName != "System.ComponentModel.CollectionConverter" -#endif - && tct.FullName != "System.ComponentModel.ReferenceConverter" - ) + if (tc != null && !tc.IsBaseTypeConverter()) { - var vc = SchemaContext.GetValueConverter(tct, this); - vc.InitialConverterInstance = tc; + var vc = SchemaContext.GetValueConverter(tc.GetType(), this); + vc.ConverterInstance = tc; return vc; } diff --git a/src/Portable.Xaml/Portable.Xaml/XamlWriterInternalBase.cs b/src/Portable.Xaml/Portable.Xaml/XamlWriterInternalBase.cs index 37f20ec..eef8630 100644 --- a/src/Portable.Xaml/Portable.Xaml/XamlWriterInternalBase.cs +++ b/src/Portable.Xaml/Portable.Xaml/XamlWriterInternalBase.cs @@ -48,7 +48,7 @@ protected XamlWriterInternalBase(XamlSchemaContext schemaContext, XamlWriterStat this.sctx = schemaContext; this.manager = manager; var p = new PrefixLookup(sctx) { IsCollectingNamespaces = true }; // it does not raise unknown namespace error. - service_provider = new ValueSerializerContext(p, schemaContext, this, this, this, this, this as IXamlObjectWriterFactory); + service_provider = ValueSerializerContext.Create(p, schemaContext, this, this, this, this, this as IXamlObjectWriterFactory); } internal XamlSchemaContext sctx; diff --git a/src/Portable.Xaml/Portable.Xaml/XamlXmlReader.cs b/src/Portable.Xaml/Portable.Xaml/XamlXmlReader.cs index a7cf0b4..44ef41d 100644 --- a/src/Portable.Xaml/Portable.Xaml/XamlXmlReader.cs +++ b/src/Portable.Xaml/Portable.Xaml/XamlXmlReader.cs @@ -1,4 +1,4 @@ -// +// // Copyright (C) 2011 Novell Inc. http://novell.com // // Permission is hereby granted, free of charge, to any person obtaining @@ -24,6 +24,8 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Text; +using System.Text.RegularExpressions; using System.Xml; using Portable.Xaml.Schema; @@ -315,8 +317,7 @@ IEnumerable ReadObjectElement (XamlType parentType, XamlMember yield break; if (r.NodeType == XmlNodeType.Text || r.NodeType == XmlNodeType.CDATA) { - //throw new XamlParseException (String.Format ("Element is expected, but got {0}", r.NodeType)); - yield return Node (XamlNodeType.Value, r.Value); + yield return Node (XamlNodeType.Value, NormalizeWhitespace(r.Value)); r.Read(); yield break; } @@ -539,7 +540,7 @@ List ProcessAttributes(XmlReader r, List members, out string t } throw new NotSupportedException(String.Format("Attribute '{0}' is not supported", r.Name)); default: - if (string.IsNullOrEmpty(r.NamespaceURI)) + if (string.IsNullOrEmpty(r.NamespaceURI) || r.LocalName.IndexOf('.') > 0) { atts.Add(new StringPair(r.Name, r.Value)); continue; @@ -612,6 +613,35 @@ static XamlDirective FindStandardDirective (string name, AllowedMemberLocations return XamlLanguage.AllDirectives.FirstOrDefault (dd => (dd.AllowedLocation & loc) != 0 && dd.Name == name); } + string NormalizeWhitespace(string value) + { + var sb = new StringBuilder(value.Length); + bool lastWasWhitesp = false; + for (var index = 0; index < value.Length; index++) + { + var c = value[index]; + if (c == ' ' || c == '\n' || c == '\t' || c == '\r') + { + if (lastWasWhitesp || sb.Length == 0) + continue; + lastWasWhitesp = true; + sb.Append(' '); + continue; + } + else + { + lastWasWhitesp = false; + } + + sb.Append(c); + } + + if (lastWasWhitesp) + sb.Length--; + + return sb.ToString(); + } + IEnumerable ReadMemberText (XamlType xt) { // this value is for Initialization, or Content property value @@ -621,7 +651,7 @@ IEnumerable ReadMemberText (XamlType xt) else xm = XamlLanguage.Initialization; yield return Node (XamlNodeType.StartMember, xm); - yield return Node (XamlNodeType.Value, r.Value); + yield return Node (XamlNodeType.Value, NormalizeWhitespace(r.Value)); r.Read (); yield return Node (XamlNodeType.EndMember, xm); } diff --git a/src/Shared/Common.props b/src/Shared/Common.props deleted file mode 100644 index e751d8d..0000000 --- a/src/Shared/Common.props +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/src/Shared/Common.targets b/src/Shared/Common.targets deleted file mode 100644 index 6820bf3..0000000 --- a/src/Shared/Common.targets +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/src/Test/Portable.Xaml-tests-core.csproj b/src/Test/Portable.Xaml-tests-core.csproj index 49909c5..afe01be 100644 --- a/src/Test/Portable.Xaml-tests-core.csproj +++ b/src/Test/Portable.Xaml-tests-core.csproj @@ -2,25 +2,21 @@ Exe - netcoreapp1.1 + netcoreapp2.0 MonoTests.Portable.Xaml Portable.Xaml_test_core - ..\..\artifacts\obj\$(MSBuildProjectName)\ + true - ..\..\artifacts\Debug\ - TRACE;DEBUG;NETSTANDARD;PCL;CORE;NETCOREAPP1_1 + ..\..\artifacts\test\Debug\ + TRACE;NETSTANDARD;PCL;CORE;DEBUG;NETCOREAPP2_0 - ..\..\artifacts\Release\ - TRACE;RELEASE;NETCOREAPP1_1;NETSTANDARD;PCL;CORE; + ..\..\artifacts\test\Release\ + TRACE;RELEASE;NETCOREAPP2_0;NETSTANDARD;PCL;CORE; - - - - @@ -29,6 +25,10 @@ - + + + + + \ No newline at end of file diff --git a/src/Test/Portable.Xaml-tests-net_4_5.csproj b/src/Test/Portable.Xaml-tests-net_4_5.csproj index 392538c..26740f0 100644 --- a/src/Test/Portable.Xaml-tests-net_4_5.csproj +++ b/src/Test/Portable.Xaml-tests-net_4_5.csproj @@ -1,135 +1,39 @@  - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {F4FA4B21-EF1C-48DE-8F4C-16496005FB94} - Library - 1699 - bin\Debug\System.Xaml-tests-net_4_5 - True - False - Properties - Portable.Xaml_test_net_4_5 - v4.5 - 512 - ..\..\artifacts\obj\$(MSBuildProjectName)\ - - - true + + + Library + net461 + MonoTests.Portable.Xaml + Portable.Xaml_test_net_4_5 + true full - false - DEBUG;TRACE;NET_1_1;NET_2_0;NET_3_0;NET_3_5;NET_4_0;NET_4_5; - prompt - 4 - false - ..\..\artifacts\Debug\net_4_5\ - - - true - NET_1_1;NET_2_0;NET_3_0;NET_3_5;NET_4_0;NET_4_5; - prompt - 4 - false - ..\..\artifacts\Release\net_4_5\ - pdbonly - true - - - - false - - + + + ..\..\artifacts\test\Debug + TRACE;DEBUG;NET_4_5;HAS_TYPE_CONVERTER + + + + + ..\..\artifacts\test\Release + TRACE;NET_4_5;HAS_TYPE_CONVERTER + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ..\packages\NUnit.3.6.1\lib\net45\nunit.framework.dll - - - ..\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll - + + + + + + + - - - - - PreserveNewest - - - - - + + + \ No newline at end of file diff --git a/src/Test/Portable.Xaml-tests-netstandard1.3.csproj b/src/Test/Portable.Xaml-tests-netstandard1.3.csproj index 7872cb4..6106f29 100644 --- a/src/Test/Portable.Xaml-tests-netstandard1.3.csproj +++ b/src/Test/Portable.Xaml-tests-netstandard1.3.csproj @@ -1,149 +1,42 @@  - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {E9DCCDCC-03A8-4BD1-888D-CEE86468A15A} - Library - 1699 - True - False - Properties - Portable.Xaml_test_netstandard - v4.6.2 - 512 - ..\..\artifacts\obj\$(MSBuildProjectName)\ - - - true + + + Library + net461 + MonoTests.Portable.Xaml + Portable.Xaml_test_netstandard + true + false full - false - DEBUG;TRACE;NET_1_1;NET_2_0;NET_3_0;NET_3_5;NET_4_0;NET_4_5;PCL259;PCL;NETSTANDARD - prompt - 4 - false - ..\..\artifacts\Debug\netstandard1.3\ - - - true - NET_1_1;NET_2_0;NET_3_0;NET_3_5;NET_4_0;NET_4_5;PCL259;PCL;NETSTANDARD - prompt - 4 - false - ..\..\artifacts\Release\netstandard1.3\ - pdbonly - true - - - - false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + ..\..\artifacts\test\Debug\netstandard1.3 + TRACE;DEBUG;PCL259;PCL;NETSTANDARD;HAS_TYPE_CONVERTER + + + + + ..\..\artifacts\test\Release\netstandard1.3 + TRACE;PCL259;PCL;NETSTANDARD;HAS_TYPE_CONVERTER + + + + - - ..\packages\NUnit.3.6.1\lib\net45\nunit.framework.dll - - - ..\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll - - - ..\packages\System.Collections.NonGeneric.4.3.0\lib\net46\System.Collections.NonGeneric.dll - - - - ..\packages\System.ComponentModel.Primitives.4.3.0\lib\net45\System.ComponentModel.Primitives.dll - - - ..\packages\System.ComponentModel.TypeConverter.4.3.0\lib\net462\System.ComponentModel.TypeConverter.dll - - - - - - - - - PreserveNewest - - - - + + + + + + + - - {CDC8F791-56FC-4B15-AAD2-BC460657CC02} - Portable.Xaml-netstandard1.3 - + + + \ No newline at end of file diff --git a/src/Test/Portable.Xaml-tests-pcl136.csproj b/src/Test/Portable.Xaml-tests-pcl136.csproj deleted file mode 100644 index cfd0bcf..0000000 --- a/src/Test/Portable.Xaml-tests-pcl136.csproj +++ /dev/null @@ -1,137 +0,0 @@ - - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {307DC911-E3EE-41F9-87BA-D1FD734E04BC} - Library - 1699 - bin\Debug\System.Xaml-tests-pcl136 - True - False - Properties - Portable.Xaml_test_pcl136 - 512 - ..\..\artifacts\obj\$(MSBuildProjectName)\ - Portable.Xaml - - - true - full - false - DEBUG;TRACE;NET_1_1;NET_2_0;NET_3_0;NET_3_5;NET_4_0;NET_4_5;PCL136;PCL - prompt - 4 - false - ..\..\artifacts\Debug\pcl136\ - - - true - NET_1_1;NET_2_0;NET_3_0;NET_3_5;NET_4_0;NET_4_5;PCL136;PCL - prompt - 4 - false - ..\..\artifacts\Release\pcl136\ - pdbonly - true - - - - false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ..\packages\NUnit.3.6.1\lib\net40\nunit.framework.dll - - - - - - - - - - - PreserveNewest - - - - - - - - - {a283eef5-d2bf-47dd-afd6-a1db3df7cda0} - Portable.Xaml-pcl136 - - - \ No newline at end of file diff --git a/src/Test/Portable.Xaml-tests-pcl259.csproj b/src/Test/Portable.Xaml-tests-pcl259.csproj index 12f8578..f5fd16a 100644 --- a/src/Test/Portable.Xaml-tests-pcl259.csproj +++ b/src/Test/Portable.Xaml-tests-pcl259.csproj @@ -1,140 +1,42 @@  - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {FDA04C3E-7386-4F45-A7F2-C69DB33B72FF} - Library - 1699 - bin\Debug\System.Xaml-tests-net_4_5 - True - False - Properties - Portable.Xaml_test_pcl259 - v4.5 - 512 - ..\..\artifacts\obj\$(MSBuildProjectName)\ - - - true + + + Library + net461 + MonoTests.Portable.Xaml + Portable.Xaml_test_pcl259 + true + false full - false - DEBUG;TRACE;NET_1_1;NET_2_0;NET_3_0;NET_3_5;NET_4_0;NET_4_5;PCL259;PCL - prompt - 4 - false - ..\..\artifacts\Debug\pcl259\ - - - true - NET_1_1;NET_2_0;NET_3_0;NET_3_5;NET_4_0;NET_4_5;PCL259;PCL - prompt - 4 - false - ..\..\artifacts\Release\pcl259\ - pdbonly - true - - - - false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + ..\..\artifacts\test\Debug\portable-net45+win8+wpa81+wp8 + TRACE;DEBUG;PCL259;PCL + + + + + ..\..\artifacts\test\Release\portable-net45+win8+wpa81+wp8 + TRACE;PCL259;PCL + + + + - - ..\packages\NUnit.3.6.1\lib\net45\nunit.framework.dll - - - ..\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll - - - - - - - - PreserveNewest - - - - - - {179484EC-DB00-451A-AD2D-2E2AB20DE519} - Portable.Xaml-pcl259 - + + + + + + + - + + + \ No newline at end of file diff --git a/src/Test/Portable.Xaml-tests-uwp.csproj b/src/Test/Portable.Xaml-tests-uwp.csproj index 5e05ce8..65ff7c1 100644 --- a/src/Test/Portable.Xaml-tests-uwp.csproj +++ b/src/Test/Portable.Xaml-tests-uwp.csproj @@ -11,18 +11,17 @@ Portable.Xaml_test_uwp en-US UAP - 10.0.15063.0 + 10.0.16299.0 10.0.10586.0 14 512 {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} UnitTestProject2_TemporaryKey.pfx $(VisualStudioVersion) - ..\..\artifacts\obj\Portable.Xaml-tests-uwp true - ..\..\artifacts\Debug\uwp\x86\ + ..\..\artifacts\test\Debug\uwp\x86\ DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP;PCL;NETSTANDARD ;2008 full @@ -32,7 +31,7 @@ true - ..\..\artifacts\Release\uwp\x86\ + ..\..\artifacts\test\Release\uwp\x86\ TRACE;NETFX_CORE;WINDOWS_UWP;PCL;NETSTANDARD true ;2008 @@ -45,7 +44,7 @@ true - ..\..\artifacts\Debug\uwp\ARM\ + ..\..\artifacts\test\Debug\uwp\ARM\ DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP;PCL;NETSTANDARD ;2008 full @@ -55,7 +54,7 @@ true - ..\..\artifacts\Release\uwp\ARM\ + ..\..\artifacts\test\Release\uwp\ARM\ TRACE;NETFX_CORE;WINDOWS_UWP;PCL;NETSTANDARD true ;2008 @@ -68,7 +67,7 @@ true - ..\..\artifacts\Debug\uwp\x64\ + ..\..\artifacts\test\Debug\uwp\x64\ TRACE;DEBUG;NETFX_CORE;WINDOWS_UWP;CODE_ANALYSIS;PCL;NETSTANDARD ;2008 full @@ -78,7 +77,7 @@ true - ..\..\artifacts\Release\uwp\x64\ + ..\..\artifacts\test\Release\uwp\x64\ TRACE;NETFX_CORE;WINDOWS_UWP;PCL;NETSTANDARD true ;2008 @@ -321,7 +320,7 @@ 1.1.14 - 3.6.1 + 3.9.0 3.6.1 diff --git a/src/Test/Program.cs b/src/Test/Program.cs index 8829457..19e91bf 100644 --- a/src/Test/Program.cs +++ b/src/Test/Program.cs @@ -42,31 +42,22 @@ class Program { static void Main(string[] args) { + var output = Console.Out; // capture console.out as nunit overrides it when running var builder = new DefaultTestAssemblyBuilder(); var runner = new NUnitTestAssemblyRunner(builder); var settings = new Dictionary(); var assembly = Assembly.GetEntryAssembly(); - var messages = new List(); var listener = new TestListener { - Log = message => messages.Add(message) // writing directly to console doesn't work for some reason + Log = output.WriteLine }; runner.Load(assembly, settings); var result = runner.Run(listener, TestFilter.Empty); - foreach (var msg in messages) - { - Console.WriteLine(msg); - } Console.WriteLine(); Console.WriteLine(result.FailCount > 0 ? "FAILED" : "PASSED"); Console.WriteLine($"Pass: {result.PassCount}, Fail: {result.FailCount}, Skipped: {result.SkipCount}, Inconclusive: {result.InconclusiveCount}"); Console.WriteLine($"Duration: {result.Duration}"); - if (Debugger.IsAttached) - { - Console.Write("Press any key to continue..."); - Console.ReadKey(true); - } } } } diff --git a/src/Test/System.Windows.Markup/TypeExtensionConverterTest.cs b/src/Test/System.Windows.Markup/TypeExtensionConverterTest.cs index 500e7c1..1ab1a27 100644 --- a/src/Test/System.Windows.Markup/TypeExtensionConverterTest.cs +++ b/src/Test/System.Windows.Markup/TypeExtensionConverterTest.cs @@ -45,6 +45,7 @@ namespace MonoTests.Portable.Xaml.Markup { +#if HAS_TYPE_CONVERTER [TestFixture] public class TypeExtensionConverterTest { @@ -55,7 +56,7 @@ public Type Resolve (string qualifiedTypeName) throw new NotImplementedException (); } } - + class TypeDescriptorContext : ITypeDescriptorContext { public object Service { get; set; } @@ -76,7 +77,7 @@ public bool OnComponentChanging () public object Instance { get; set; } -#if !PCL || NETSTANDARD +#if HAS_TYPE_CONVERTER public IContainer Container { get; set; } public PropertyDescriptor PropertyDescriptor { get; set; } #endif @@ -142,4 +143,5 @@ public void ConvertToFail3 () Assert.Throws (() => tc.ConvertTo (new DummyValueSerializerContext (), null, "x:Int32", typeof (TypeExtension))); } } + #endif } diff --git a/src/Test/System.Windows.Markup/ValueSerializerTest.cs b/src/Test/System.Windows.Markup/ValueSerializerTest.cs index 92c034f..ac62a63 100644 --- a/src/Test/System.Windows.Markup/ValueSerializerTest.cs +++ b/src/Test/System.Windows.Markup/ValueSerializerTest.cs @@ -137,9 +137,10 @@ public void GetSerializerFor() #endif Assert.IsNull(ValueSerializer.GetSerializerFor(typeof(object)), "#10"); Assert.IsNotNull(ValueSerializer.GetSerializerFor(typeof(TimeSpan)), "#11"); // has no TypeConverter (undocumented behavior), TypeCode.Object -> unexpectedly has non-null serializer! -#if !NETSTANDARD + + /* TODO: not sure why this isn't true in Portable.Xaml Assert.IsNull (ValueSerializer.GetSerializerFor (typeof (DateTimeOffset)), "#12"); // has no TypeConverter (undocumented behavior), TypeCode.Object -> expected -#endif + */ Assert.IsNull (ValueSerializer.GetSerializerFor (typeof (MyExtension)), "#13"); Assert.IsNotNull (ValueSerializer.GetSerializerFor (typeof (MyExtension4)), "#14"); // has TypeConverter. diff --git a/src/Test/System.Xaml.Schema/XamlTypeTypeConverterTest.cs b/src/Test/System.Xaml.Schema/XamlTypeTypeConverterTest.cs index ebd262a..07d3e51 100644 --- a/src/Test/System.Xaml.Schema/XamlTypeTypeConverterTest.cs +++ b/src/Test/System.Xaml.Schema/XamlTypeTypeConverterTest.cs @@ -41,6 +41,8 @@ namespace MonoTests.Portable.Xaml.Schema { +#if HAS_TYPE_CONVERTER + [TestFixture] public class XamlTypeTypeConverterTest { @@ -126,4 +128,5 @@ public void ConvertStringToXamlType () Assert.Throws (() => c.ConvertTo (new DummyValueSerializerContext (), null, "System.String", typeof (XamlType)), "#1"); } } +#endif } \ No newline at end of file diff --git a/src/Test/System.Xaml.Schema/XamlValueConverterTest.cs b/src/Test/System.Xaml.Schema/XamlValueConverterTest.cs index e52fa63..6818b79 100644 --- a/src/Test/System.Xaml.Schema/XamlValueConverterTest.cs +++ b/src/Test/System.Xaml.Schema/XamlValueConverterTest.cs @@ -1,4 +1,4 @@ -// +// // Copyright (C) 2010 Novell Inc. http://novell.com // // Permission is hereby granted, free of charge, to any person obtaining @@ -26,22 +26,17 @@ using System.Text; using System.Xml; using NUnit.Framework; +using System.ComponentModel; #if PCL using Portable.Xaml.Markup; -using Portable.Xaml.ComponentModel; using Portable.Xaml; using Portable.Xaml.Schema; #else using System.Windows.Markup; -using System.ComponentModel; using System.Xaml; using System.Xaml.Schema; #endif -#if NETSTANDARD -using System.ComponentModel; -#endif - namespace MonoTests.Portable.Xaml.Schema { [TestFixture] @@ -112,7 +107,9 @@ public void ObjectType () // This test asserts that XamlLanguage.Object.TypeConverter.ConverterType is null for different reason. var c = new XamlValueConverter (typeof (TypeConverter), XamlLanguage.Object, null); Assert.IsNotNull (c.ConverterInstance, "#1"); + #if HAS_TYPE_CONVERTER Assert.IsNull (XamlLanguage.Object.TypeConverter.ConverterInstance, "#2"); + #endif } [Test] diff --git a/src/Test/System.Xaml/TestedTypes.cs b/src/Test/System.Xaml/TestedTypes.cs index 678cc38..c280d64 100644 --- a/src/Test/System.Xaml/TestedTypes.cs +++ b/src/Test/System.Xaml/TestedTypes.cs @@ -38,12 +38,9 @@ using System.Collections.Immutable; #endif -#if NETSTANDARD +#if NETSTANDARD || PCL using ISupportInitialize = Portable.Xaml.ComponentModel.ISupportInitialize; using System.ComponentModel; -using DateTimeConverter = System.ComponentModel.DateTimeConverter; -#elif PCL -using DateTimeConverter = Portable.Xaml.ComponentModel.DateTimeConverter; #endif #if PCL @@ -1601,6 +1598,23 @@ bool ShouldSerializeText() return !string.IsNullOrEmpty(Text) && Text != "bar"; } } + + [ContentProperty("Child")] + public class Whitespace + { + public string TabConvertedToSpaces { get; set; } + public string NewlineConvertedToSpaces { get; set; } + public string ConsecutiveSpaces { get; set; } + public string SpacesAroundTags { get; set; } + public string Preserve { get; set; } + public WhitespaceChild Child { get; set; } + } + + [ContentProperty("Content")] + public class WhitespaceChild + { + public string Content { get; set; } + } } namespace XamlTest diff --git a/src/Test/System.Xaml/ValueSerializerContextTest.cs b/src/Test/System.Xaml/ValueSerializerContextTest.cs index 2116cc4..efcb31d 100644 --- a/src/Test/System.Xaml/ValueSerializerContextTest.cs +++ b/src/Test/System.Xaml/ValueSerializerContextTest.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,9 @@ using System.Xml; using NUnit.Framework; using MonoTests.Portable.Xaml; +using System.Globalization; +using System.ComponentModel; +using CategoryAttribute = NUnit.Framework.CategoryAttribute; #if PCL using Portable.Xaml.Markup; using Portable.Xaml.ComponentModel; @@ -36,16 +39,10 @@ using Portable.Xaml.Schema; #else using System.Windows.Markup; -using System.ComponentModel; using System.Xaml; using System.Xaml.Schema; #endif -using CategoryAttribute = NUnit.Framework.CategoryAttribute; -using System.Globalization; -#if NETSTANDARD -using System.ComponentModel; -#endif namespace MonoTests.Portable.Xaml { diff --git a/src/Test/System.Xaml/XamlDirectiveTest.cs b/src/Test/System.Xaml/XamlDirectiveTest.cs index 787fa67..6cd7fe3 100644 --- a/src/Test/System.Xaml/XamlDirectiveTest.cs +++ b/src/Test/System.Xaml/XamlDirectiveTest.cs @@ -66,6 +66,7 @@ public void ConstructorNamespaceXamlNS () new XamlDirective (XamlLanguage.Xaml2006Namespace, "Foo"); } +#if HAS_TYPE_CONVERTER [Test] public void ConstructorComplexParamsTypeNull () { @@ -89,7 +90,7 @@ public void ConstructorComplexParams () { new XamlDirective (new string [] {"urn:foo"}, "Foo", new XamlType (typeof (object), sctx), null, AllowedMemberLocations.Any); } - +#endif [Test] public void DefaultValuesWithName () { @@ -108,7 +109,9 @@ public void DefaultValuesWithName () Assert.IsNull (d.TargetType, "#10"); Assert.IsNotNull (d.Type, "#11"); Assert.AreEqual (typeof (object), d.Type.UnderlyingType, "#11-2"); +#if HAS_TYPE_CONVERTER Assert.IsNull (d.TypeConverter, "#12"); +#endif Assert.IsNull (d.ValueSerializer, "#13"); Assert.IsNull (d.DeferringLoader, "#14"); Assert.IsNull (d.UnderlyingMember, "#15"); @@ -123,6 +126,7 @@ public void DefaultValuesWithName () // TODO: Assert.AreEqual (DesignerSerializationVisibility.Visible, d.SerializationVisibility, "#23"); } +#if HAS_TYPE_CONVERTER [Test] public void DefaultValuesWithComplexParams () { @@ -155,5 +159,6 @@ public void DefaultValuesWithComplexParams () Assert.IsFalse (d.IsAmbient, "#22"); //TODO: Assert.AreEqual (DesignerSerializationVisibility.Visible, d.SerializationVisibility, "#23"); } +#endif } } diff --git a/src/Test/System.Xaml/XamlLanguageTest.cs b/src/Test/System.Xaml/XamlLanguageTest.cs index 7e240ea..a4036aa 100644 --- a/src/Test/System.Xaml/XamlLanguageTest.cs +++ b/src/Test/System.Xaml/XamlLanguageTest.cs @@ -329,6 +329,7 @@ void TestXamlDirectiveCommon (XamlDirective d, string name, string ns, AllowedMe Assert.IsNotNull (d.Type, "#11"); Assert.AreEqual (type, d.Type.UnderlyingType, "#11-2"); +#if HAS_TYPE_CONVERTER // .NET returns StringConverter, but it should not premise that key must be string (it is object) if (name == "Key") { @@ -338,6 +339,7 @@ void TestXamlDirectiveCommon (XamlDirective d, string name, string ns, AllowedMe Assert.IsNull (d.TypeConverter, "#12"); else Assert.IsNotNull (d.TypeConverter, "#12"); +#endif Assert.IsNull (d.ValueSerializer, "#13"); Assert.IsNull (d.DeferringLoader, "#14"); Assert.IsNull (d.UnderlyingMember, "#15"); @@ -406,10 +408,12 @@ public void Static () { var t = XamlLanguage.Static; TestXamlTypeExtension (t, "StaticExtension", typeof (StaticExtension), typeof (object), false); +#if HAS_TYPE_CONVERTER var tc = t.TypeConverter.ConverterInstance; Assert.IsNotNull (tc, "#25-2"); Assert.IsFalse (tc.CanConvertFrom (typeof (string)), "#25-3"); Assert.IsTrue (tc.CanConvertTo (typeof (string)), "#25-4"); +#endif Assert.IsNull (t.ContentProperty, "#27"); var l = t.GetAllMembers ().ToArray (); @@ -440,7 +444,9 @@ public void Type () { var t = XamlLanguage.Type; TestXamlTypeExtension (t, "TypeExtension", typeof (TypeExtension), typeof (Type), false); +#if HAS_TYPE_CONVERTER Assert.IsNotNull (t.TypeConverter.ConverterInstance, "#25-2"); +#endif Assert.IsNull (t.ContentProperty, "#27"); var l = t.GetAllMembers ().ToArray (); @@ -646,7 +652,9 @@ public void Member () { var t = XamlLanguage.Member; TestXamlTypeCommon (t, "Member", typeof (MemberDefinition), true, true, false); +#if HAS_TYPE_CONVERTER Assert.IsNull (t.TypeConverter, "#25"); +#endif // FIXME: test remaining members var l = t.GetAllMembers ().ToArray (); @@ -666,7 +674,9 @@ public void Property () { var t = XamlLanguage.Property; TestXamlTypeCommon (t, "Property", typeof (PropertyDefinition), true); +#if HAS_TYPE_CONVERTER Assert.IsNull (t.TypeConverter, "#25"); +#endif // FIXME: test remaining members var l = t.GetAllMembers ().ToArray (); @@ -689,7 +699,9 @@ public void Property_Type () { var m = XamlLanguage.Property.GetMember ("Type"); TestMemberCommon (m, "Type", typeof (XamlType), typeof (PropertyDefinition), true); +#if HAS_TYPE_CONVERTER Assert.IsNotNull (m.TypeConverter, "#1"); +#endif Assert.IsNull (m.ValueSerializer, "#2"); } @@ -712,7 +724,9 @@ public void Reference () { var t = XamlLanguage.Reference; TestXamlTypeCommon (t, "Reference", typeof (Reference), true); +#if HAS_TYPE_CONVERTER Assert.IsNull (t.TypeConverter, "#25"); +#endif // FIXME: test remaining members var l = t.GetAllMembers ().ToArray (); @@ -733,7 +747,9 @@ public void XData () { var t = XamlLanguage.XData; TestXamlTypeCommon (t, "XData", typeof (XData), true); +#if HAS_TYPE_CONVERTER Assert.IsNull (t.TypeConverter, "#25"); +#endif // FIXME: test remaining members var l = t.GetAllMembers ().ToArray (); @@ -808,7 +824,9 @@ void TestXamlTypePrimitive (XamlType t, string name, Type underlyingType, bool n { TestXamlTypeCommon (t, name, underlyingType, nullable, constructorRequiresArguments); Assert.IsFalse (t.IsMarkupExtension, "#14"); +#if HAS_TYPE_CONVERTER Assert.IsNotNull (t.TypeConverter, "#25"); +#endif Assert.IsNull (t.ContentProperty, "#27"); Assert.IsNull (t.MarkupExtensionReturnType, "#29"); @@ -820,10 +838,12 @@ void TestXamlTypeExtension (XamlType t, string name, Type underlyingType, Type e { TestXamlTypeCommon (t, name, underlyingType, true, false); Assert.IsTrue (t.IsMarkupExtension, "#14"); +#if HAS_TYPE_CONVERTER if (noTypeConverter) Assert.IsNull (t.TypeConverter, "#25"); else Assert.IsNotNull (t.TypeConverter, "#25"); +#endif Assert.IsNotNull (t.MarkupExtensionReturnType, "#29"); Assert.AreEqual (extReturnType, t.MarkupExtensionReturnType.UnderlyingType, "#29-2"); Assert.IsNull (t.Invoker.SetMarkupExtensionHandler, "#31"); // orly? @@ -851,8 +871,10 @@ void TestMemberCommon (XamlMember m, string name, Type type, Type declType, bool Assert.IsNotNull (m.Type, "#11"); Assert.AreEqual (type, m.Type.UnderlyingType, "#11-2"); // Property.Type is a special case here. +#if HAS_TYPE_CONVERTER if (name == "Type" && m.DeclaringType != XamlLanguage.Property) Assert.AreEqual (m.Type.TypeConverter, m.TypeConverter, "#12"); +#endif // String type is a special case here. if (type == typeof (string)) Assert.AreEqual (m.Type.ValueSerializer, m.ValueSerializer, "#13a"); diff --git a/src/Test/System.Xaml/XamlMemberTest.cs b/src/Test/System.Xaml/XamlMemberTest.cs index d01a174..79c8a0c 100644 --- a/src/Test/System.Xaml/XamlMemberTest.cs +++ b/src/Test/System.Xaml/XamlMemberTest.cs @@ -196,7 +196,9 @@ public void EventInfoDefaultValues () Assert.AreEqual (new XamlType (typeof (EventStore), sctx), m.TargetType, "#10"); Assert.IsNotNull (m.Type, "#11"); Assert.AreEqual (typeof (EventHandler), m.Type.UnderlyingType, "#11-2"); +#if HAS_TYPE_CONVERTER Assert.IsNotNull (m.TypeConverter, "#12"); // EventConverter +#endif Assert.IsNull (m.ValueSerializer, "#13"); Assert.IsNull (m.DeferringLoader, "#14"); Assert.AreEqual (eventStore_Event3, m.UnderlyingMember, "#15"); @@ -229,7 +231,9 @@ public void PropertyInfoDefaultValues () Assert.AreEqual (new XamlType (typeof (string), sctx), m.TargetType, "#10"); Assert.IsNotNull (m.Type, "#11"); Assert.AreEqual (typeof (int), m.Type.UnderlyingType, "#11-2"); +#if HAS_TYPE_CONVERTER Assert.IsNotNull (m.TypeConverter, "#12"); +#endif Assert.IsNull (m.ValueSerializer, "#13"); Assert.IsNull (m.DeferringLoader, "#14"); Assert.AreEqual (str_len, m.UnderlyingMember, "#15"); @@ -357,7 +361,9 @@ public void NameTypeDefaultValues () Assert.AreEqual (new XamlType (typeof (string), sctx), m.TargetType, "#10"); Assert.IsNotNull (m.Type, "#11"); Assert.AreEqual (typeof (object), m.Type.UnderlyingType, "#11-2"); +#if HAS_TYPE_CONVERTER Assert.IsNull (m.TypeConverter, "#12"); +#endif Assert.IsNull (m.ValueSerializer, "#13"); Assert.IsNull (m.DeferringLoader, "#14"); Assert.IsNull (m.UnderlyingMember, "#15"); diff --git a/src/Test/System.Xaml/XamlObjectReaderTest.cs b/src/Test/System.Xaml/XamlObjectReaderTest.cs index 60d1130..ca9cd22 100644 --- a/src/Test/System.Xaml/XamlObjectReaderTest.cs +++ b/src/Test/System.Xaml/XamlObjectReaderTest.cs @@ -367,7 +367,9 @@ public void Read_Guid () { var obj = Guid.NewGuid (); var r = new XamlObjectReader (obj); +#if HAS_TYPE_CONVERTER Assert.IsNotNull (r.SchemaContext.GetXamlType (typeof(Guid)).TypeConverter, "premise#1"); +#endif Read_CommonClrType (r, obj); Assert.AreEqual (obj.ToString (), Read_Initialization (r, null), "#1"); } diff --git a/src/Test/System.Xaml/XamlObjectWriterTest.cs b/src/Test/System.Xaml/XamlObjectWriterTest.cs index 4fa9deb..8ca455b 100644 --- a/src/Test/System.Xaml/XamlObjectWriterTest.cs +++ b/src/Test/System.Xaml/XamlObjectWriterTest.cs @@ -2105,5 +2105,22 @@ public void Write_Attached_Collection() Assert.AreEqual("SomeValue", result.Property[0].Foo, "#2"); } + + [Test] + public void Whitespace_ShouldBeCorrectlyHandled() + { + using (var xr = GetReader("Whitespace.xml")) + { + var des = (Whitespace)XamlServices.Load(xr); + Assert.AreEqual("hello world", des.TabConvertedToSpaces); + Assert.AreEqual("hello world", des.NewlineConvertedToSpaces); + Assert.AreEqual("hello world", des.ConsecutiveSpaces); + Assert.AreEqual("hello world", des.SpacesAroundTags); + Assert.AreEqual("hello world", des.Child.Content); + + // TODO: xml:space="preserve" not yet implemented + // Assert.AreEqual(" hello world\t", des.Preserve); + } + } } } diff --git a/src/Test/System.Xaml/XamlReaderTestBase.cs b/src/Test/System.Xaml/XamlReaderTestBase.cs index dd8008b..4d0fb58 100644 --- a/src/Test/System.Xaml/XamlReaderTestBase.cs +++ b/src/Test/System.Xaml/XamlReaderTestBase.cs @@ -3624,7 +3624,7 @@ protected void Read_ContentPropertyContainer (XamlReader r) Assert.IsFalse (r.Read (), "end"); } - protected void Read_AttachedProperty (XamlReader r) + protected void Read_AttachedProperty (XamlReader r, bool withNamespace = false) { var at = new XamlType (typeof (Attachable), r.SchemaContext); @@ -3635,6 +3635,11 @@ protected void Read_AttachedProperty (XamlReader r) var assns = "clr-namespace:MonoTests.Portable.Xaml;assembly=" + GetType ().GetTypeInfo().Assembly.GetName ().Name; Assert.AreEqual (assns, r.Namespace.Namespace, "ns#1-5"); + if (withNamespace) + { + this.ReadNamespace(r, "ns", assns, "ns#2"); + } + // t:AttachedWrapper Assert.IsTrue (r.Read (), "so#1-1"); Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "so#1-2"); diff --git a/src/Test/System.Xaml/XamlTypeTest.cs b/src/Test/System.Xaml/XamlTypeTest.cs index 79e3dd7..41447d6 100644 --- a/src/Test/System.Xaml/XamlTypeTest.cs +++ b/src/Test/System.Xaml/XamlTypeTest.cs @@ -1,4 +1,4 @@ -// +// // Copyright (C) 2010 Novell Inc. http://novell.com // // Permission is hereby granted, free of charge, to any person obtaining @@ -345,8 +345,10 @@ public void DefaultValuesType () Assert.IsFalse (t.IsAmbient, "#22"); Assert.IsNull (t.AllowedContentTypes, "#23"); Assert.IsNull (t.ContentWrappers, "#24"); +#if HAS_TYPE_CONVERTER Assert.IsNotNull (t.TypeConverter, "#25"); Assert.IsTrue (t.TypeConverter.ConverterInstance is Int32Converter, "#25-2"); +#endif Assert.IsNull (t.ValueSerializer, "#26"); Assert.IsNull (t.ContentProperty, "#27"); //Assert.IsNull (t.DeferringLoader, "#28"); @@ -383,7 +385,9 @@ public void DefaultValuesType2 () Assert.IsFalse (t.IsAmbient, "#22"); Assert.IsNull (t.AllowedContentTypes, "#23"); Assert.IsNull (t.ContentWrappers, "#24"); +#if HAS_TYPE_CONVERTER Assert.IsNotNull (t.TypeConverter, "#25"); // TypeTypeConverter +#endif Assert.IsNull (t.ValueSerializer, "#26"); Assert.IsNull (t.ContentProperty, "#27"); //Assert.IsNull (t.DeferringLoader, "#28"); @@ -420,7 +424,9 @@ public void DefaultValuesName () Assert.IsFalse (t.IsAmbient, "#22"); Assert.IsNull (t.AllowedContentTypes, "#23"); Assert.IsNull (t.ContentWrappers, "#24"); +#if HAS_TYPE_CONVERTER Assert.IsNull (t.TypeConverter, "#25"); +#endif Assert.IsNull (t.ValueSerializer, "#26"); Assert.IsNull (t.ContentProperty, "#27"); //Assert.IsNull (t.DeferringLoader, "#28"); @@ -457,7 +463,9 @@ public void DefaultValuesCustomType () Assert.IsFalse (t.IsAmbient, "#22"); Assert.IsNull (t.AllowedContentTypes, "#23"); Assert.IsNull (t.ContentWrappers, "#24"); +#if HAS_TYPE_CONVERTER Assert.IsNull (t.TypeConverter, "#25"); +#endif Assert.IsNull (t.ValueSerializer, "#26"); Assert.IsNull (t.ContentProperty, "#27"); //Assert.IsNull (t.DeferringLoader, "#28"); @@ -507,7 +515,9 @@ public void DefaultValuesSeverlyAttributed () Assert.IsTrue (t.IsAmbient, "#22"); Assert.IsNull (t.AllowedContentTypes, "#23"); Assert.IsNull (t.ContentWrappers, "#24"); +#if HAS_TYPE_CONVERTER Assert.IsNull (t.TypeConverter, "#25"); +#endif Assert.IsNull (t.ValueSerializer, "#26"); Assert.IsNotNull (t.ContentProperty, "#27"); Assert.AreEqual ("Name", t.ContentProperty.Name, "#27-2"); @@ -544,7 +554,9 @@ public void DefaultValuesArgumentAttributed () Assert.IsFalse (t.IsAmbient, "#22"); Assert.IsNull (t.AllowedContentTypes, "#23"); Assert.IsNull (t.ContentWrappers, "#24"); +#if HAS_TYPE_CONVERTER Assert.IsNull (t.TypeConverter, "#25"); +#endif Assert.IsNull (t.ValueSerializer, "#26"); Assert.IsNull (t.ContentProperty, "#27"); // Assert.IsNull (t.DeferringLoader, "#28"); @@ -558,6 +570,7 @@ public void DefaultValuesArgumentAttributed () Assert.IsTrue (Array.IndexOf (names, member.Name) >= 0, "#32"); } +#if HAS_TYPE_CONVERTER [Test] public void TypeConverter () { @@ -571,7 +584,7 @@ public void TypeConverter () Assert.IsNull (new XamlType (typeof (XamlType), sctx).TypeConverter, "#5"); Assert.IsTrue (new XamlType (typeof (char), sctx).TypeConverter.ConverterInstance is CharConverter, "#6"); } - + [Test] public void TypeConverter_Type () { @@ -605,6 +618,8 @@ void TypeConveter_TypeOrTypeExtension (Type type) } } +#endif + [Test] public void GetXamlNamespaces () { @@ -848,7 +863,9 @@ public void EnumType () Assert.IsFalse (xt.IsNullable, "#2"); Assert.IsFalse (xt.IsUnknown, "#3"); Assert.IsFalse (xt.IsUsableDuringInitialization, "#4"); +#if HAS_TYPE_CONVERTER Assert.IsNotNull (xt.TypeConverter, "#5"); +#endif } [Test] @@ -884,8 +901,10 @@ public void NullableContainer () Assert.AreEqual ("clr-namespace:System;assembly=mscorlib", xm.Type.PreferredXamlNamespace, "#5"); Assert.AreEqual (1, xm.Type.TypeArguments.Count, "#6"); Assert.AreEqual (XamlLanguage.Int32, xm.Type.TypeArguments [0], "#7"); +#if HAS_TYPE_CONVERTER Assert.IsNotNull (xm.Type.TypeConverter, "#8"); Assert.IsNotNull (xm.Type.TypeConverter.ConverterInstance, "#9"); +#endif var obj = new NullableContainer (); xm.Invoker.SetValue (obj, 5); @@ -911,9 +930,11 @@ public void NullableTypeShouldUseProperValueSerializer() Assert.IsTrue(xt.IsNullable, "#1"); Assert.AreEqual(xt.BaseType, sctx.GetXamlType(typeof(ValueType)), "#2"); Assert.IsNull(xt.ValueSerializer, "#3"); +#if HAS_TYPE_CONVERTER Assert.IsNotInstanceOf(xt.TypeConverter.ConverterInstance, "#4"); #if PCL - Assert.IsInstanceOf(xt.TypeConverter.ConverterInstance, "#4"); + Assert.IsInstanceOf(typeof(global::Portable.Xaml.XamlSchemaContext).Assembly.GetType("Portable.Xaml.ComponentModel.DateTimeConverter"), xt.TypeConverter.ConverterInstance, "#4"); +#endif #endif } diff --git a/src/Test/System.Xaml/XamlXmlReaderTest.cs b/src/Test/System.Xaml/XamlXmlReaderTest.cs index 99a0a94..99912ae 100644 --- a/src/Test/System.Xaml/XamlXmlReaderTest.cs +++ b/src/Test/System.Xaml/XamlXmlReaderTest.cs @@ -681,6 +681,13 @@ public void Read_AttachedProperty () Read_AttachedProperty (r); } + [Test] + public void Read_AttachedPropertyWithNamespace() + { + var r = GetReader("AttachedPropertyWithNamespace.xml"); + Read_AttachedProperty(r, true); + } + [Test] public void Read_AbstractWrapper () { diff --git a/src/Test/XmlFiles/AttachedPropertyWithNamespace.xml b/src/Test/XmlFiles/AttachedPropertyWithNamespace.xml new file mode 100644 index 0000000..48758c3 --- /dev/null +++ b/src/Test/XmlFiles/AttachedPropertyWithNamespace.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/src/Test/XmlFiles/Whitespace.xml b/src/Test/XmlFiles/Whitespace.xml new file mode 100644 index 0000000..a936200 --- /dev/null +++ b/src/Test/XmlFiles/Whitespace.xml @@ -0,0 +1,13 @@ + + hello world + hello + world + hello world + + hello world + + hello world + + hello world + + \ No newline at end of file diff --git a/src/Test/packages.config b/src/Test/packages.config deleted file mode 100644 index 0dcb42f..0000000 --- a/src/Test/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file