зеркало из https://github.com/AvaloniaUI/OmniXAML.git
Simplified interfaces.
This commit is contained in:
Родитель
026fe8d506
Коммит
fb4d796451
26
OmniXaml.sln
26
OmniXaml.sln
|
@ -15,18 +15,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OmniXaml.Tests.Classes", "S
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xaml.Tests.Resources", "Source\Tests\Xaml.Tests.Resources\Xaml.Tests.Resources.csproj", "{9B517520-4D99-4BF5-8219-A643F718F6DD}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OmniXaml.Services", "Source\OmniXaml.AppServices\OmniXaml.Services.csproj", "{B207C0CB-2BDF-4105-9E1D-1C5B98E98381}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OmniXaml.Services.DotNetFx.Tests", "Source\Tests\OmniXaml.AppServices.NetCore.Tests\OmniXaml.Services.DotNetFx.Tests.csproj", "{6DC9D410-E8CA-48A4-8725-697D75F33388}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OmniXaml.Services.Tests", "Source\Tests\OmniXaml.AppServices.Tests\OmniXaml.Services.Tests.csproj", "{BB3EEE9D-9962-4ADB-954A-E070B0C03CC8}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OmniXaml.Services.DotNetFx", "Source\OmniXaml.AppServices.NetCore\OmniXaml.Services.DotNetFx.csproj", "{70B12EBB-E332-402E-BAF0-C55F38A6B753}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OmniXaml.Services.DotNetFx", "Source\OmniXaml.Services.DotNetFx\OmniXaml.Services.DotNetFx.csproj", "{70B12EBB-E332-402E-BAF0-C55F38A6B753}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OmniXaml.Tests.Common", "Source\Tests\OmniXaml.Tests.Common\OmniXaml.Tests.Common.csproj", "{03EFD393-33D1-43E6-8835-1450459697F3}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OmniXaml.Services.Mvvm", "Source\OmniXaml.AppServices.Mvvm\OmniXaml.Services.Mvvm.csproj", "{7784DA26-90C9-402E-8AAE-6D4D59C22D74}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OmniXaml.Wpf", "Source\OmniXaml.Wpf\OmniXaml.Wpf.csproj", "{3F5DEBE4-D1D2-4190-9AEA-FDD4065FDED7}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OmniXaml.Wpf.Tests", "Source\Tests\OmniXaml.Wpf.Tests\OmniXaml.Wpf.Tests.csproj", "{952C2CB6-BB38-471A-AD55-D68FCAC4A5CF}"
|
||||
|
@ -41,6 +37,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OmniXaml.Tests.Common.DotNe
|
|||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{A3E121C9-F1A5-468B-940E-BF09C0414DB5}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OmniXaml.Services", "Source\OmniXaml.Services\OmniXaml.Services.csproj", "{B207C0CB-2BDF-4105-9E1D-1C5B98E98381}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OmniXaml.Services.Mvvm", "Source\OmniXaml.Services.Mvvm\OmniXaml.Services.Mvvm.csproj", "{7784DA26-90C9-402E-8AAE-6D4D59C22D74}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -67,10 +67,6 @@ Global
|
|||
{9B517520-4D99-4BF5-8219-A643F718F6DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9B517520-4D99-4BF5-8219-A643F718F6DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9B517520-4D99-4BF5-8219-A643F718F6DD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B207C0CB-2BDF-4105-9E1D-1C5B98E98381}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B207C0CB-2BDF-4105-9E1D-1C5B98E98381}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B207C0CB-2BDF-4105-9E1D-1C5B98E98381}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B207C0CB-2BDF-4105-9E1D-1C5B98E98381}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{6DC9D410-E8CA-48A4-8725-697D75F33388}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6DC9D410-E8CA-48A4-8725-697D75F33388}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6DC9D410-E8CA-48A4-8725-697D75F33388}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
|
@ -87,10 +83,6 @@ Global
|
|||
{03EFD393-33D1-43E6-8835-1450459697F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{03EFD393-33D1-43E6-8835-1450459697F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{03EFD393-33D1-43E6-8835-1450459697F3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{7784DA26-90C9-402E-8AAE-6D4D59C22D74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7784DA26-90C9-402E-8AAE-6D4D59C22D74}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7784DA26-90C9-402E-8AAE-6D4D59C22D74}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7784DA26-90C9-402E-8AAE-6D4D59C22D74}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{3F5DEBE4-D1D2-4190-9AEA-FDD4065FDED7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{3F5DEBE4-D1D2-4190-9AEA-FDD4065FDED7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3F5DEBE4-D1D2-4190-9AEA-FDD4065FDED7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
|
@ -111,6 +103,14 @@ Global
|
|||
{35EBCD38-4ADA-4860-8F23-6D564C0E4C68}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{35EBCD38-4ADA-4860-8F23-6D564C0E4C68}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{35EBCD38-4ADA-4860-8F23-6D564C0E4C68}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B207C0CB-2BDF-4105-9E1D-1C5B98E98381}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B207C0CB-2BDF-4105-9E1D-1C5B98E98381}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B207C0CB-2BDF-4105-9E1D-1C5B98E98381}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B207C0CB-2BDF-4105-9E1D-1C5B98E98381}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{7784DA26-90C9-402E-8AAE-6D4D59C22D74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7784DA26-90C9-402E-8AAE-6D4D59C22D74}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7784DA26-90C9-402E-8AAE-6D4D59C22D74}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7784DA26-90C9-402E-8AAE-6D4D59C22D74}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
@ -33,5 +33,5 @@ using System.Runtime.InteropServices;
|
|||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.4.8.0")]
|
||||
[assembly: AssemblyVersion("1.5.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
namespace OmniXaml.AppServices.NetCore
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
public static class Types
|
||||
{
|
||||
public static IEnumerable<Type> FromCurrentAppDomain => Assemblies.AppDomainAssemblies.Where(assembly => !assembly.IsDynamic).SelectMany(assembly => assembly.ExportedTypes);
|
||||
public static IEnumerable<Type> FromReferencedAssemblies => Assemblies.ReferencedAssemblies.SelectMany(assembly => assembly.ExportedTypes);
|
||||
public static IEnumerable<Type> FromAppFolder => Assemblies.AssembliesInAppFolder.SelectMany(assembly => assembly.ExportedTypes);
|
||||
}
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
namespace OmniXaml.AppServices
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
public class AutoInflatingTypeFactory : ITypeFactory
|
||||
{
|
||||
private readonly ITypeFactory coreTypeFactory;
|
||||
private readonly IInflatableTranslator inflatableTranslator;
|
||||
private readonly Func<ITypeFactory, IXamlLoader> loaderFactory;
|
||||
|
||||
public virtual IEnumerable<Type> Inflatables { get; } = new Collection<Type>();
|
||||
|
||||
public AutoInflatingTypeFactory(ITypeFactory coreTypeFactory,
|
||||
IInflatableTranslator inflatableTranslator,
|
||||
Func<ITypeFactory, IXamlLoader> loaderFactory)
|
||||
{
|
||||
this.coreTypeFactory = coreTypeFactory;
|
||||
this.inflatableTranslator = inflatableTranslator;
|
||||
this.loaderFactory = loaderFactory;
|
||||
}
|
||||
|
||||
public object Create(Type type)
|
||||
{
|
||||
return Create(type, null);
|
||||
}
|
||||
|
||||
public object Create(Type type, object[] args)
|
||||
{
|
||||
if (IsInflatable(type))
|
||||
{
|
||||
using (var stream = inflatableTranslator.GetStream(type))
|
||||
{
|
||||
var instance = coreTypeFactory.Create(type, args);
|
||||
var loader = loaderFactory(this);
|
||||
var inflated = loader.Load(stream, instance);
|
||||
return inflated;
|
||||
}
|
||||
}
|
||||
|
||||
return coreTypeFactory.Create(type, args);
|
||||
}
|
||||
|
||||
private bool IsInflatable(Type type) => HasSomeInflatableThatIsCompatible(type);
|
||||
|
||||
private bool HasSomeInflatableThatIsCompatible(Type type)
|
||||
{
|
||||
return Inflatables.Any(t => t.GetTypeInfo().IsAssignableFrom(type.GetTypeInfo()));
|
||||
}
|
||||
|
||||
public bool CanLocate(Type type)
|
||||
{
|
||||
return coreTypeFactory.CanLocate(type);
|
||||
}
|
||||
|
||||
public object Create(Uri uri)
|
||||
{
|
||||
var type = inflatableTranslator.GetTypeFor(uri);
|
||||
return Create(type);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -28,6 +28,9 @@ namespace OmniXaml.AppServices.NetCore
|
|||
{
|
||||
assemblies.Add(Assembly.LoadFile(fileName));
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
}
|
||||
catch (FileLoadException)
|
||||
{
|
||||
}
|
||||
|
@ -40,12 +43,12 @@ namespace OmniXaml.AppServices.NetCore
|
|||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<string> FilterFiles(string path, params string[] exts)
|
||||
public static IEnumerable<string> FilterFiles(string path, params string[] extensionsWithNoWildcard)
|
||||
{
|
||||
return
|
||||
Directory
|
||||
.EnumerateFiles(path, "*.*")
|
||||
.Where(file => exts.Any(x => file.EndsWith(x, StringComparison.OrdinalIgnoreCase)));
|
||||
.Where(file => extensionsWithNoWildcard.Any(x => file.EndsWith(x, StringComparison.OrdinalIgnoreCase)));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@ namespace OmniXaml.AppServices.NetCore
|
|||
|
||||
public class InflatableTranslator : IInflatableTranslator
|
||||
{
|
||||
public Stream GetStream(Type type)
|
||||
public Stream GetInflationSourceStream(Type type)
|
||||
{
|
||||
var uri = GetUriFor(type);
|
||||
var absoluteUri = new Uri(Assembly.GetExecutingAssembly().Location, UriKind.Absolute);
|
||||
|
@ -15,23 +15,6 @@ namespace OmniXaml.AppServices.NetCore
|
|||
return new FileStream(finalUri.LocalPath, FileMode.Open);
|
||||
}
|
||||
|
||||
private static Uri GetUriFor(Type type)
|
||||
{
|
||||
if (type.Namespace != null)
|
||||
{
|
||||
var toRemove = type.Assembly.GetName().Name;
|
||||
var substracted = toRemove.Length < type.Namespace.Length ? type.Namespace.Remove(0, toRemove.Length + 1) : "";
|
||||
var replace = substracted.Replace('.', Path.PathSeparator);
|
||||
if (replace != string.Empty)
|
||||
{
|
||||
replace = replace + "/";
|
||||
}
|
||||
return new Uri(replace + type.Name + ".xaml", UriKind.Relative);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Type GetTypeFor(Uri uri)
|
||||
{
|
||||
var withExt = uri.OriginalString;
|
||||
|
@ -51,6 +34,23 @@ namespace OmniXaml.AppServices.NetCore
|
|||
return type.First();
|
||||
}
|
||||
|
||||
private static Uri GetUriFor(Type type)
|
||||
{
|
||||
if (type.Namespace != null)
|
||||
{
|
||||
var toRemove = type.Assembly.GetName().Name;
|
||||
var substracted = toRemove.Length < type.Namespace.Length ? type.Namespace.Remove(0, toRemove.Length + 1) : "";
|
||||
var replace = substracted.Replace('.', Path.PathSeparator);
|
||||
if (replace != string.Empty)
|
||||
{
|
||||
replace = replace + "/";
|
||||
}
|
||||
return new Uri(replace + type.Name + ".xaml", UriKind.Relative);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static string GetName(Assembly assembly, string innerNs, string className)
|
||||
{
|
||||
var ns = assembly.GetName().Name + "." + innerNs;
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
|
@ -48,7 +48,7 @@
|
|||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OmniXaml.AppServices\OmniXaml.Services.csproj">
|
||||
<ProjectReference Include="..\OmniXaml.Services\OmniXaml.Services.csproj">
|
||||
<Project>{B207C0CB-2BDF-4105-9E1D-1C5B98E98381}</Project>
|
||||
<Name>OmniXaml.Services</Name>
|
||||
</ProjectReference>
|
||||
|
@ -61,4 +61,4 @@
|
|||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
</Project>
|
|
@ -1,15 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>OmniXaml.AppServices.NetCore</id>
|
||||
<id>OmniXaml.Services.DotNetFx</id>
|
||||
<version>$version$</version>
|
||||
<title>OmniXaml.AppServices.NetCore</title>
|
||||
<title>OmniXaml Application Services for Full .NET Framework</title>
|
||||
<authors>José Manuel Nieto (@SuperJMN)</authors>
|
||||
<owners>José Manuel Nieto (@SuperJMN)</owners>
|
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||
<description>Description</description>
|
||||
<dependencies>
|
||||
<dependency id="OmniXaml.AppServices" version="$version$" />
|
||||
<dependency id="OmniXaml.Services" version="$version$" />
|
||||
</dependencies>
|
||||
</metadata>
|
||||
</package>
|
|
@ -0,0 +1,21 @@
|
|||
namespace OmniXaml.AppServices.NetCore
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
public static class Types
|
||||
{
|
||||
public static IEnumerable<Type> FromCurrentAppDomain => GetTypesFromNonDynamicAssemblies(Assemblies.AppDomainAssemblies);
|
||||
|
||||
public static IEnumerable<Type> FromReferencedAssemblies => GetTypesFromNonDynamicAssemblies(Assemblies.ReferencedAssemblies);
|
||||
|
||||
public static IEnumerable<Type> FromAppFolder => GetTypesFromNonDynamicAssemblies(Assemblies.AssembliesInAppFolder);
|
||||
|
||||
private static IEnumerable<Type> GetTypesFromNonDynamicAssemblies(IEnumerable<Assembly> assemblies)
|
||||
{
|
||||
return assemblies.Where(assembly => !assembly.IsDynamic).SelectMany(assembly => assembly.ExportedTypes);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>OmniXaml.AppServices.Mvvm</id>
|
||||
<id>OmniXaml.Services.Mvvm</id>
|
||||
<version>$version$</version>
|
||||
<title>OmniXaml.AppServices.Mvvm</title>
|
||||
<title>OmniXaml.Services.Mvvm</title>
|
||||
<authors>José Manuel Nieto (@SuperJMN)</authors>
|
||||
<owners>José Manuel Nieto (@SuperJMN)</owners>
|
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
|
@ -0,0 +1,65 @@
|
|||
namespace OmniXaml.AppServices
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
public class AutoInflatingTypeFactory : ITypeFactory
|
||||
{
|
||||
private readonly ITypeFactory innerTypeFactory;
|
||||
private readonly IInflatableTranslator inflatableTranslator;
|
||||
private readonly Func<ITypeFactory, IXamlLoader> xamlLoaderFactory;
|
||||
|
||||
public virtual IEnumerable<Type> Inflatables { get; } = new Collection<Type>();
|
||||
|
||||
public AutoInflatingTypeFactory(ITypeFactory innerTypeFactory,
|
||||
IInflatableTranslator inflatableTranslator,
|
||||
Func<ITypeFactory, IXamlLoader> xamlLoaderFactory)
|
||||
{
|
||||
this.innerTypeFactory = innerTypeFactory;
|
||||
this.inflatableTranslator = inflatableTranslator;
|
||||
this.xamlLoaderFactory = xamlLoaderFactory;
|
||||
}
|
||||
|
||||
public object Create(Type type, object[] args)
|
||||
{
|
||||
return IsInflatable(type) ? CreateAndInflate(type, args) : CreateWithNoInflate(type, args);
|
||||
}
|
||||
|
||||
private object CreateWithNoInflate(Type type, object[] args)
|
||||
{
|
||||
return innerTypeFactory.Create(type, args);
|
||||
}
|
||||
|
||||
private object CreateAndInflate(Type type, object[] args)
|
||||
{
|
||||
using (var stream = inflatableTranslator.GetInflationSourceStream(type))
|
||||
{
|
||||
var instance = innerTypeFactory.Create(type, args);
|
||||
var loader = xamlLoaderFactory(this);
|
||||
var inflated = loader.Load(stream, instance);
|
||||
return inflated;
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsInflatable(Type type) => HasSomeInflatableThatIsCompatible(type);
|
||||
|
||||
private bool HasSomeInflatableThatIsCompatible(Type type)
|
||||
{
|
||||
return Inflatables.Any(t => t.GetTypeInfo().IsAssignableFrom(type.GetTypeInfo()));
|
||||
}
|
||||
|
||||
public bool CanCreate(Type type)
|
||||
{
|
||||
return innerTypeFactory.CanCreate(type);
|
||||
}
|
||||
|
||||
public object Create(Uri uri)
|
||||
{
|
||||
var type = inflatableTranslator.GetTypeFor(uri);
|
||||
return this.Create(type);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,6 +6,6 @@ namespace OmniXaml.AppServices
|
|||
public interface IInflatableTranslator
|
||||
{
|
||||
Type GetTypeFor(Uri uri);
|
||||
Stream GetStream(Type type);
|
||||
Stream GetInflationSourceStream(Type type);
|
||||
}
|
||||
}
|
|
@ -1,13 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>OmniXaml.AppServices</id>
|
||||
<id>OmniXaml.Services</id>
|
||||
<version>$version$</version>
|
||||
<title>OmniXaml.AppServices</title>
|
||||
<title>OmniXAML Application Services</title>
|
||||
<authors>José Manuel Nieto (@SuperJMN)</authors>
|
||||
<owners>José Manuel Nieto (@SuperJMN)</owners>
|
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||
<description>Provides services for applications using OmniXAML</description>
|
||||
<description>Provides services for applications using OmniXAML like "AutoInflate"</description>
|
||||
<dependencies>
|
||||
<dependency id="OmniXaml" version="$version$" />
|
||||
</dependencies>
|
|
@ -7,7 +7,7 @@
|
|||
private readonly ITypeFactory forRoot;
|
||||
private readonly ITypeFactory forNonRoot;
|
||||
|
||||
public AlternateOnRootTypeFactory(ITypeFactory forRoot, ITypeFactory forNonRoot)
|
||||
protected AlternateOnRootTypeFactory(ITypeFactory forRoot, ITypeFactory forNonRoot)
|
||||
{
|
||||
this.forRoot = forRoot;
|
||||
this.forNonRoot = forNonRoot;
|
||||
|
@ -15,17 +15,6 @@
|
|||
|
||||
private bool RootIsRead { get; set; }
|
||||
|
||||
public object Create(Type type)
|
||||
{
|
||||
if (RootIsRead)
|
||||
{
|
||||
return forNonRoot.Create(type);
|
||||
}
|
||||
|
||||
RootIsRead = true;
|
||||
return forRoot.Create(type);
|
||||
}
|
||||
|
||||
public object Create(Type type, params object[] args)
|
||||
{
|
||||
if (RootIsRead)
|
||||
|
@ -37,9 +26,9 @@
|
|||
return forRoot.Create(type, args);
|
||||
}
|
||||
|
||||
public bool CanLocate(Type type)
|
||||
public bool CanCreate(Type type)
|
||||
{
|
||||
return forNonRoot.CanLocate(type);
|
||||
return forNonRoot.CanCreate(type);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,13 +10,13 @@ namespace OmniXaml.Wpf
|
|||
using Parsers.XamlNodes;
|
||||
using Typing;
|
||||
|
||||
internal class Hydrater
|
||||
internal class Hydrator
|
||||
{
|
||||
private readonly IEnumerable<Type> inflatables;
|
||||
private readonly IWiringContext wiringContext;
|
||||
private readonly XamlInstructionBuilder instructionBuilder;
|
||||
|
||||
public Hydrater(IEnumerable<Type> inflatables, IWiringContext wiringContext)
|
||||
public Hydrator(IEnumerable<Type> inflatables, IWiringContext wiringContext)
|
||||
{
|
||||
this.inflatables = inflatables;
|
||||
this.wiringContext = wiringContext;
|
||||
|
@ -83,7 +83,7 @@ namespace OmniXaml.Wpf
|
|||
{
|
||||
var resourceProvider = new InflatableTranslator();
|
||||
|
||||
using (var stream = resourceProvider.GetStream(underlyingType))
|
||||
using (var stream = resourceProvider.GetInflationSourceStream(underlyingType))
|
||||
{
|
||||
var wiringContext = (IWiringContext) new WpfWiringContext(new TypeFactory());
|
||||
var loader = new XamlInstructionParser(wiringContext);
|
|
@ -54,7 +54,7 @@
|
|||
<Compile Include="DependencyObjectHelper.cs" />
|
||||
<Compile Include="DynamicResourceExtension.cs" />
|
||||
<Compile Include="Extensions.cs" />
|
||||
<Compile Include="Hydrater.cs" />
|
||||
<Compile Include="Hydrator.cs" />
|
||||
<Compile Include="MarkupExtensionXamlType.cs" />
|
||||
<Compile Include="DirectiveAdapter.cs" />
|
||||
<Compile Include="AlternateOnRootTypeFactory.cs" />
|
||||
|
@ -65,6 +65,7 @@
|
|||
<Compile Include="WpfWindow.cs" />
|
||||
<Compile Include="WpfWiringContext.cs" />
|
||||
<Compile Include="WpfXamlAttachableMember.cs" />
|
||||
<Compile Include="WpfXamlLoaderTypeFactory.cs" />
|
||||
<Compile Include="XamlMemberAdapter.cs" />
|
||||
<Compile Include="TemplateContentToWpfXamlReaderAdapter.cs" />
|
||||
<Compile Include="WpfTypeFactory.cs" />
|
||||
|
@ -90,15 +91,15 @@
|
|||
<Compile Include="WpfXamlTypeRepository.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OmniXaml.AppServices.Mvvm\OmniXaml.Services.Mvvm.csproj">
|
||||
<Project>{7784DA26-90C9-402E-8AAE-6D4D59C22D74}</Project>
|
||||
<Name>OmniXaml.Services.Mvvm</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\OmniXaml.AppServices.NetCore\OmniXaml.Services.DotNetFx.csproj">
|
||||
<ProjectReference Include="..\OmniXaml.Services.DotNetFx\OmniXaml.Services.DotNetFx.csproj">
|
||||
<Project>{70B12EBB-E332-402E-BAF0-C55F38A6B753}</Project>
|
||||
<Name>OmniXaml.Services.DotNetFx</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\OmniXaml.AppServices\OmniXaml.Services.csproj">
|
||||
<ProjectReference Include="..\OmniXaml.Services.Mvvm\OmniXaml.Services.Mvvm.csproj">
|
||||
<Project>{7784DA26-90C9-402E-8AAE-6D4D59C22D74}</Project>
|
||||
<Name>OmniXaml.Services.Mvvm</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\OmniXaml.Services\OmniXaml.Services.csproj">
|
||||
<Project>{B207C0CB-2BDF-4105-9E1D-1C5B98E98381}</Project>
|
||||
<Name>OmniXaml.Services</Name>
|
||||
</ProjectReference>
|
||||
|
|
|
@ -9,9 +9,9 @@
|
|||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||
<description>Description</description>
|
||||
<dependencies>
|
||||
<dependency id="OmniXaml.AppServices" version="$version$" />
|
||||
<dependency id="OmniXaml.AppServices.NetCore" version="$version$" />
|
||||
<dependency id="OmniXaml.AppServices.Mvvm" version="$version$" />
|
||||
<dependency id="OmniXaml.Services" version="$version$" />
|
||||
<dependency id="OmniXaml.Services.NetCore" version="$version$" />
|
||||
<dependency id="OmniXaml.Services.Mvvm" version="$version$" />
|
||||
</dependencies>
|
||||
</metadata>
|
||||
</package>
|
|
@ -19,10 +19,10 @@ namespace OmniXaml.Wpf
|
|||
XamlSchemaContext xamlSchemaContext)
|
||||
{
|
||||
this.templateContent = templateContent;
|
||||
this.SchemaContext = xamlSchemaContext;
|
||||
SchemaContext = xamlSchemaContext;
|
||||
|
||||
var hydrater = new Hydrater(autoInflatingTypeFactory.Inflatables, templateContent.Context);
|
||||
var hydratedNodes = hydrater.Hydrate(templateContent.Nodes);
|
||||
var hydrator = new Hydrator(autoInflatingTypeFactory.Inflatables, templateContent.Context);
|
||||
var hydratedNodes = hydrator.Hydrate(templateContent.Nodes);
|
||||
|
||||
nodeStream = hydratedNodes.GetEnumerator();
|
||||
}
|
||||
|
|
|
@ -8,8 +8,7 @@ namespace OmniXaml.Wpf
|
|||
|
||||
public WpfXamlLoader()
|
||||
{
|
||||
var typeFactory = new TypeFactory();
|
||||
innerLoader = new XamlLoader(new WpfParserFactory(new AlternateOnRootTypeFactory(typeFactory, new WpfTypeFactory(typeFactory))));
|
||||
innerLoader = new XamlLoader(new WpfParserFactory(new WpfXamlLoaderTypeFactory()));
|
||||
}
|
||||
|
||||
public object Load(Stream stream)
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
namespace OmniXaml.Wpf
|
||||
{
|
||||
public class WpfXamlLoaderTypeFactory : AlternateOnRootTypeFactory
|
||||
{
|
||||
public WpfXamlLoaderTypeFactory() : base(new TypeFactory(), new WpfTypeFactory())
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,10 +5,9 @@
|
|||
public interface ITypeFactory
|
||||
{
|
||||
// ReSharper disable once UnusedMember.Global
|
||||
object Create(Type type);
|
||||
// ReSharper disable once UnusedMember.Global
|
||||
object Create(Type type, params object[] args);
|
||||
// ReSharper disable once UnusedMember.Global
|
||||
bool CanLocate(Type type);
|
||||
bool CanCreate(Type type);
|
||||
}
|
||||
}
|
|
@ -1,23 +1,15 @@
|
|||
namespace OmniXaml
|
||||
{
|
||||
using System;
|
||||
using Glass;
|
||||
|
||||
public class TypeFactory : ITypeFactory
|
||||
{
|
||||
public object Create(Type type)
|
||||
{
|
||||
Guard.ThrowIfNull(type, nameof(type));
|
||||
|
||||
return Create(type, null);
|
||||
}
|
||||
|
||||
public object Create(Type type, object[] args)
|
||||
{
|
||||
return Activator.CreateInstance(type, args);
|
||||
}
|
||||
|
||||
public bool CanLocate(Type type)
|
||||
public bool CanCreate(Type type)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,14 @@
|
|||
namespace OmniXaml
|
||||
{
|
||||
using System;
|
||||
|
||||
public static class TypeFactoryMixin
|
||||
{
|
||||
public static object Create(this ITypeFactory typeFactory, Type type)
|
||||
{
|
||||
return typeFactory.Create(type, null);
|
||||
}
|
||||
|
||||
public static T Create<T>(this ITypeFactory typeFactory)
|
||||
{
|
||||
return (T)typeFactory.Create(typeof (T));
|
||||
|
|
|
@ -62,11 +62,11 @@
|
|||
<Folder Include="TestModel\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\OmniXaml.AppServices.NetCore\OmniXaml.Services.DotNetFx.csproj">
|
||||
<ProjectReference Include="..\..\OmniXaml.Services.DotNetFx\OmniXaml.Services.DotNetFx.csproj">
|
||||
<Project>{70B12EBB-E332-402E-BAF0-C55F38A6B753}</Project>
|
||||
<Name>OmniXaml.Services.DotNetFx</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\OmniXaml.AppServices\OmniXaml.Services.csproj">
|
||||
<ProjectReference Include="..\..\OmniXaml.Services\OmniXaml.Services.csproj">
|
||||
<Project>{B207C0CB-2BDF-4105-9E1D-1C5B98E98381}</Project>
|
||||
<Name>OmniXaml.Services</Name>
|
||||
</ProjectReference>
|
||||
|
|
|
@ -7,8 +7,8 @@ namespace OmniXaml.AppServices.Tests
|
|||
|
||||
public class DummyAutoInflatingTypeFactory : AutoInflatingTypeFactory
|
||||
{
|
||||
public DummyAutoInflatingTypeFactory(ITypeFactory typeFactory, IInflatableTranslator inflatableTranslator, Func<ITypeFactory, IXamlLoader> loaderFactory)
|
||||
: base(typeFactory, inflatableTranslator, loaderFactory)
|
||||
public DummyAutoInflatingTypeFactory(ITypeFactory typeFactory, IInflatableTranslator inflatableTranslator, Func<ITypeFactory, IXamlLoader> xamlLoaderFactory)
|
||||
: base(typeFactory, inflatableTranslator, xamlLoaderFactory)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -59,6 +59,10 @@
|
|||
<Compile Include="InflatableTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\OmniXaml.Services\OmniXaml.Services.csproj">
|
||||
<Project>{B207C0CB-2BDF-4105-9E1D-1C5B98E98381}</Project>
|
||||
<Name>OmniXaml.Services</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\OmniXaml.Test.Common.NetCore\OmniXaml.Tests.Common.DotNetFx.csproj">
|
||||
<Project>{35EBCD38-4ADA-4860-8F23-6D564C0E4C68}</Project>
|
||||
<Name>OmniXaml.Tests.Common.DotNetFx</Name>
|
||||
|
@ -67,14 +71,10 @@
|
|||
<Project>{b719ff91-bc7a-4145-8597-811d504fcfef}</Project>
|
||||
<Name>Glass</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\OmniXaml.AppServices.NetCore\OmniXaml.Services.DotNetFx.csproj">
|
||||
<ProjectReference Include="..\..\OmniXaml.Services.DotNetFx\OmniXaml.Services.DotNetFx.csproj">
|
||||
<Project>{70B12EBB-E332-402E-BAF0-C55F38A6B753}</Project>
|
||||
<Name>OmniXaml.Services.DotNetFx</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\OmniXaml.AppServices\OmniXaml.Services.csproj">
|
||||
<Project>{B207C0CB-2BDF-4105-9E1D-1C5B98E98381}</Project>
|
||||
<Name>OmniXaml.Services</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\OmniXaml\OmniXaml.csproj">
|
||||
<Project>{0D9CC1DE-84C3-40D7-9CC5-B7751E0B25D1}</Project>
|
||||
<Name>OmniXaml</Name>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
|
@ -51,7 +51,7 @@
|
|||
<Project>{b719ff91-bc7a-4145-8597-811d504fcfef}</Project>
|
||||
<Name>Glass</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\OmniXaml.AppServices.NetCore\OmniXaml.Services.DotNetFx.csproj">
|
||||
<ProjectReference Include="..\..\OmniXaml.Services.DotNetFx\OmniXaml.Services.DotNetFx.csproj">
|
||||
<Project>{70b12ebb-e332-402e-baf0-c55f38a6b753}</Project>
|
||||
<Name>OmniXaml.Services.DotNetFx</Name>
|
||||
</ProjectReference>
|
||||
|
@ -76,4 +76,4 @@
|
|||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
</Project>
|
|
@ -100,7 +100,7 @@
|
|||
<Project>{B719FF91-BC7A-4145-8597-811D504FCFEF}</Project>
|
||||
<Name>Glass</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\OmniXaml.AppServices.NetCore\OmniXaml.Services.DotNetFx.csproj">
|
||||
<ProjectReference Include="..\..\OmniXaml.Services.DotNetFx\OmniXaml.Services.DotNetFx.csproj">
|
||||
<Project>{70B12EBB-E332-402E-BAF0-C55F38A6B753}</Project>
|
||||
<Name>OmniXaml.Services.DotNetFx</Name>
|
||||
</ProjectReference>
|
||||
|
|
|
@ -4,17 +4,12 @@ namespace OmniXaml.Tests
|
|||
|
||||
public class TypeFactoryDummy : ITypeFactory
|
||||
{
|
||||
public object Create(Type type)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public object Create(Type type, object[] args)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool CanLocate(Type type)
|
||||
public bool CanCreate(Type type)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
|
|
@ -15,22 +15,17 @@ namespace SampleWpfApp
|
|||
this.container = container;
|
||||
}
|
||||
|
||||
public object Create(Type type)
|
||||
{
|
||||
return container.Locate(type);
|
||||
}
|
||||
|
||||
public object Create(Type type, object[] args)
|
||||
{
|
||||
if (typeof(ViewModel).IsAssignableFrom(type))
|
||||
{
|
||||
return Create(type);
|
||||
return container.Locate(type);
|
||||
}
|
||||
|
||||
return defaultTypeFactory.Create(type, args);
|
||||
}
|
||||
|
||||
public bool CanLocate(Type type)
|
||||
public bool CanCreate(Type type)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
|
@ -120,17 +120,13 @@
|
|||
<Project>{b719ff91-bc7a-4145-8597-811d504fcfef}</Project>
|
||||
<Name>Glass</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\OmniXaml.AppServices.Mvvm\OmniXaml.Services.Mvvm.csproj">
|
||||
<Project>{7784da26-90c9-402e-8aae-6d4d59c22d74}</Project>
|
||||
<Name>OmniXaml.Services.Mvvm</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\OmniXaml.AppServices.NetCore\OmniXaml.Services.DotNetFx.csproj">
|
||||
<ProjectReference Include="..\..\..\OmniXaml.Services.DotNetFx\OmniXaml.Services.DotNetFx.csproj">
|
||||
<Project>{70b12ebb-e332-402e-baf0-c55f38a6b753}</Project>
|
||||
<Name>OmniXaml.Services.DotNetFx</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\OmniXaml.AppServices\OmniXaml.Services.csproj">
|
||||
<Project>{b207c0cb-2bdf-4105-9e1d-1c5b98e98381}</Project>
|
||||
<Name>OmniXaml.Services</Name>
|
||||
<ProjectReference Include="..\..\..\OmniXaml.Services.Mvvm\OmniXaml.Services.Mvvm.csproj">
|
||||
<Project>{7784DA26-90C9-402E-8AAE-6D4D59C22D74}</Project>
|
||||
<Name>OmniXaml.Services.Mvvm</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\OmniXaml.Wpf\OmniXaml.Wpf.csproj">
|
||||
<Project>{3F5DEBE4-D1D2-4190-9AEA-FDD4065FDED7}</Project>
|
||||
|
@ -171,4 +167,4 @@
|
|||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
</Project>
|
|
@ -199,22 +199,18 @@
|
|||
<Project>{B719FF91-BC7A-4145-8597-811D504FCFEF}</Project>
|
||||
<Name>Glass</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\OmniXaml.AppServices.Mvvm\OmniXaml.Services.Mvvm.csproj">
|
||||
<Project>{7784da26-90c9-402e-8aae-6d4d59c22d74}</Project>
|
||||
<Name>OmniXaml.Services.Mvvm</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\OmniXaml.AppServices.NetCore\OmniXaml.Services.DotNetFx.csproj">
|
||||
<ProjectReference Include="..\..\..\OmniXaml.Services.DotNetFx\OmniXaml.Services.DotNetFx.csproj">
|
||||
<Project>{70b12ebb-e332-402e-baf0-c55f38a6b753}</Project>
|
||||
<Name>OmniXaml.Services.DotNetFx</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\OmniXaml.Services.Mvvm\OmniXaml.Services.Mvvm.csproj">
|
||||
<Project>{7784DA26-90C9-402E-8AAE-6D4D59C22D74}</Project>
|
||||
<Name>OmniXaml.Services.Mvvm</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\OmniXaml.Wpf\OmniXaml.Wpf.csproj">
|
||||
<Project>{3f5debe4-d1d2-4190-9aea-fdd4065fded7}</Project>
|
||||
<Name>OmniXaml.Wpf</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\OmniXaml.AppServices\OmniXaml.Services.csproj">
|
||||
<Project>{B207C0CB-2BDF-4105-9E1D-1C5B98E98381}</Project>
|
||||
<Name>OmniXaml.Services</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\OmniXaml\OmniXaml.csproj">
|
||||
<Project>{0D9CC1DE-84C3-40D7-9CC5-B7751E0B25D1}</Project>
|
||||
<Name>OmniXaml</Name>
|
||||
|
|
Загрузка…
Ссылка в новой задаче