diff --git a/.gitmodules b/.gitmodules
index 22a241f120e..10c780c09fd 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,6 +1,3 @@
-[submodule "src/Markup/Avalonia.Markup.Xaml/PortableXaml/portable.xaml.github"]
- path = src/Markup/Avalonia.Markup.Xaml/PortableXaml/portable.xaml.github
- url = https://github.com/AvaloniaUI/Portable.Xaml.git
[submodule "nukebuild/Numerge"]
path = nukebuild/Numerge
url = https://github.com/kekekeks/Numerge.git
diff --git a/src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs b/src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs
index 801ed74ca02..a0e86a53b04 100644
--- a/src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs
+++ b/src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs
@@ -9,7 +9,6 @@
using Avalonia.Remote.Protocol.Designer;
using Avalonia.Remote.Protocol.Viewport;
using Avalonia.Threading;
-using Portable.Xaml;
namespace Avalonia.DesignerSupport.Remote
{
@@ -206,7 +205,6 @@ private static void OnTransportMessage(IAvaloniaRemoteTransportConnection transp
}
catch (Exception e)
{
- var xamlException = e as XamlException;
var xmlException = e as XmlException;
s_transport.Send(new UpdateXamlResultMessage
@@ -216,8 +214,8 @@ private static void OnTransportMessage(IAvaloniaRemoteTransportConnection transp
{
ExceptionType = e.GetType().FullName,
Message = e.Message.ToString(),
- LineNumber = xamlException?.LineNumber ?? xmlException?.LineNumber,
- LinePosition = xamlException?.LinePosition ?? xmlException?.LinePosition,
+ LineNumber = xmlException?.LineNumber,
+ LinePosition = xmlException?.LinePosition,
}
});
}
diff --git a/src/Markup/Avalonia.Markup.Xaml/Avalonia.Markup.Xaml.csproj b/src/Markup/Avalonia.Markup.Xaml/Avalonia.Markup.Xaml.csproj
index 8ce29e5b8ee..996cfdbc525 100644
--- a/src/Markup/Avalonia.Markup.Xaml/Avalonia.Markup.Xaml.csproj
+++ b/src/Markup/Avalonia.Markup.Xaml/Avalonia.Markup.Xaml.csproj
@@ -11,12 +11,8 @@
-
-
-
-
@@ -24,25 +20,12 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -52,7 +35,6 @@
-
@@ -76,11 +58,11 @@
-
+
diff --git a/src/Markup/Avalonia.Markup.Xaml/AvaloniaTypeConverters.cs b/src/Markup/Avalonia.Markup.Xaml/AvaloniaTypeConverters.cs
deleted file mode 100644
index f967bdf0af0..00000000000
--- a/src/Markup/Avalonia.Markup.Xaml/AvaloniaTypeConverters.cs
+++ /dev/null
@@ -1,107 +0,0 @@
-using System;
-using System.ComponentModel;
-using System.Collections.Generic;
-using System.Globalization;
-using Avalonia.Collections;
-using Avalonia.Controls;
-using Avalonia.Markup.Xaml.Converters;
-using Avalonia.Media.Imaging;
-using Avalonia.Styling;
-using Avalonia.Controls.Templates;
-
-namespace Avalonia.Markup.Xaml
-{
- using System.Reflection;
- using Avalonia.Media;
-
- ///
- /// Maintains a repository of s for XAML parsing on top of those
- /// maintained by .
- ///
- ///
- /// The default method of defining type converters using
- /// isn't powerful enough for our purposes:
- ///
- /// - It doesn't handle non-constructed generic types (such as )
- /// - Type converters which require XAML features cannot be defined in non-XAML assemblies and
- /// so can't be referenced using
- /// - Many types have a static `Parse(string)` method which can be used implicitly; this class
- /// detects such methods and auto-creates a type converter
- ///
- public static class AvaloniaTypeConverters
- {
- // When adding item to that list make sure to modify AvaloniaXamlIlLanguage
- private static Dictionary _converters = new Dictionary()
- {
- { typeof(AvaloniaList<>), typeof(AvaloniaListConverter<>) },
- { typeof(AvaloniaProperty), typeof(AvaloniaPropertyTypeConverter) },
- { typeof(IBitmap), typeof(BitmapTypeConverter) },
- { typeof(IList), typeof(PointsListTypeConverter) },
- { typeof(IMemberSelector), typeof(MemberSelectorTypeConverter) },
- { typeof(Selector), typeof(SelectorTypeConverter) },
- { typeof(TimeSpan), typeof(TimeSpanTypeConverter) },
- { typeof(WindowIcon), typeof(IconTypeConverter) },
- { typeof(CultureInfo), typeof(CultureInfoConverter) },
- { typeof(Uri), typeof(AvaloniaUriTypeConverter) },
- { typeof(FontFamily), typeof(FontFamilyTypeConverter) },
- { typeof(EventInfo), typeof(AvaloniaEventConverter) },
- };
-
- internal static Type GetBuiltinTypeConverter(Type type)
- {
- _converters.TryGetValue(type, out var result);
- return result;
- }
-
- ///
- /// Tries to lookup a for a type.
- ///
- /// The type.
- /// The type converter.
- public static Type GetTypeConverter(Type type)
- {
- if (type.IsConstructedGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))
- {
- var inner = GetTypeConverter(type.GetGenericArguments()[0]);
- if (inner == null)
- return null;
- return typeof(NullableTypeConverter<>).MakeGenericType(inner);
- }
-
- if (_converters.TryGetValue(type, out var result))
- {
- return result;
- }
-
- // Converters for non-constructed generic types can't be specified using
- // TypeConverterAttribute. Allow them to be registered here and handle them sanely.
- if (type.IsConstructedGenericType &&
- _converters.TryGetValue(type.GetGenericTypeDefinition(), out result))
- {
- return result?.MakeGenericType(type.GetGenericArguments());
- }
-
- // If the type isn't a primitive or a type that XAML already handles, but has a static
- // Parse method, use that
- if (!type.IsPrimitive &&
- type != typeof(DateTime) &&
- type != typeof(Uri) &&
- ParseTypeConverter.HasParseMethod(type))
- {
- result = typeof(ParseTypeConverter<>).MakeGenericType(type);
- _converters.Add(type, result);
- return result;
- }
-
- _converters.Add(type, null);
- return null;
- }
-
- ///
- /// Registers a type converter for a type.
- ///
- /// The type. Maybe be a non-constructed generic type.
- /// The converter type. Maybe be a non-constructed generic type.
- public static void Register(Type type, Type converterType) => _converters[type] = converterType;
- }
-}
diff --git a/src/Markup/Avalonia.Markup.Xaml/AvaloniaXamlLoader.cs b/src/Markup/Avalonia.Markup.Xaml/AvaloniaXamlLoader.cs
index 45424e67bb2..e8f2439f46a 100644
--- a/src/Markup/Avalonia.Markup.Xaml/AvaloniaXamlLoader.cs
+++ b/src/Markup/Avalonia.Markup.Xaml/AvaloniaXamlLoader.cs
@@ -15,7 +15,6 @@
using Avalonia.Markup.Data;
using Avalonia.Markup.Xaml.PortableXaml;
using Avalonia.Platform;
-using Portable.Xaml;
namespace Avalonia.Markup.Xaml
{
@@ -26,71 +25,14 @@ public class AvaloniaXamlLoader
{
public bool IsDesignMode { get; set; }
- public static bool UseLegacyXamlLoader { get; set; } = false;
-
- ///
- /// Initializes a new instance of the class.
- ///
- public AvaloniaXamlLoader()
- {
- }
-
///
/// Loads the XAML into a Avalonia component.
///
/// The object to load the XAML into.
public static void Load(object obj)
{
- Contract.Requires(obj != null);
-
- var loader = new AvaloniaXamlLoader();
- loader.Load(obj.GetType(), obj);
- }
-
- ///
- /// Loads the XAML for a type.
- ///
- /// The type.
- ///
- /// The optional instance into which the XAML should be loaded.
- ///
- /// The loaded object.
- public object Load(Type type, object rootInstance = null)
- {
- Contract.Requires(type != null);
-
- // HACK: Currently Visual Studio is forcing us to change the extension of xaml files
- // in certain situations, so we try to load .xaml and if that's not found we try .xaml.
- // Ideally we'd be able to use .xaml everywhere
- var assetLocator = AvaloniaLocator.Current.GetService();
-
- if (assetLocator == null)
- {
- throw new InvalidOperationException(
- "Could not create IAssetLoader : maybe Application.RegisterServices() wasn't called?");
- }
-
- foreach (var uri in GetUrisFor(assetLocator, type))
- {
- if (assetLocator.Exists(uri))
- {
- using (var stream = assetLocator.Open(uri))
- {
- var initialize = rootInstance as ISupportInitialize;
- initialize?.BeginInit();
- try
- {
- return Load(stream, type.Assembly, rootInstance, uri);
- }
- finally
- {
- initialize?.EndInit();
- }
- }
- }
- }
-
- throw new FileNotFoundException("Unable to find view for " + type.FullName);
+ throw new XamlLoadException(
+ $"No precompiled XAML found for {obj.GetType()}, make sure to specify x:Class and include your XAML file as AvaloniaResource");
}
///
@@ -100,11 +42,8 @@ public object Load(Type type, object rootInstance = null)
///
/// A base URI to use if is relative.
///
- ///
- /// The optional instance into which the XAML should be loaded.
- ///
/// The loaded object.
- public object Load(Uri uri, Uri baseUri = null, object rootInstance = null)
+ public object Load(Uri uri, Uri baseUri = null)
{
Contract.Requires(uri != null);
@@ -133,7 +72,7 @@ public object Load(Uri uri, Uri baseUri = null, object rootInstance = null)
using (var stream = asset.stream)
{
var absoluteUri = uri.IsAbsoluteUri ? uri : new Uri(baseUri, uri);
- return Load(stream, asset.assembly, rootInstance, absoluteUri);
+ return Load(stream, asset.assembly, null, absoluteUri);
}
}
@@ -166,95 +105,9 @@ public object Load(string xaml, Assembly localAssembly = null, object rootInstan
///
/// The URI of the XAML
/// The loaded object.
- public object Load(Stream stream, Assembly localAssembly, object rootInstance = null, Uri uri = null)
- {
- if (!UseLegacyXamlLoader)
- return AvaloniaXamlIlRuntimeCompiler.Load(stream, localAssembly, rootInstance, uri, IsDesignMode);
-
-
- var readerSettings = new XamlXmlReaderSettings()
- {
- BaseUri = uri,
- LocalAssembly = localAssembly,
- ProvideLineInfo = true,
- };
-
- var context = IsDesignMode ? AvaloniaXamlSchemaContext.DesignInstance : AvaloniaXamlSchemaContext.Instance;
- var reader = new XamlXmlReader(stream, context, readerSettings);
-
- object result = LoadFromReader(
- reader,
- AvaloniaXamlContext.For(readerSettings, rootInstance));
-
- var topLevel = result as TopLevel;
-
- if (topLevel != null)
- {
- DelayedBinding.ApplyBindings(topLevel);
- }
-
- return result;
- }
-
- internal static object LoadFromReader(XamlReader reader, AvaloniaXamlContext context = null, IAmbientProvider parentAmbientProvider = null)
- {
- var writer = AvaloniaXamlObjectWriter.Create(
- (AvaloniaXamlSchemaContext)reader.SchemaContext,
- context,
- parentAmbientProvider);
+ public object Load(Stream stream, Assembly localAssembly, object rootInstance = null, Uri uri = null)
+ => AvaloniaXamlIlRuntimeCompiler.Load(stream, localAssembly, rootInstance, uri, IsDesignMode);
- XamlServices.Transform(reader, writer);
- writer.ApplyAllDelayedProperties();
- return writer.Result;
- }
-
- internal static object LoadFromReader(XamlReader reader)
- {
- //return XamlServices.Load(reader);
- return LoadFromReader(reader, null);
- }
-
-
- private static readonly DataContractSerializer s_xamlInfoSerializer =
- new DataContractSerializer(typeof(AvaloniaResourceXamlInfo));
- ///
- /// Gets the URI for a type.
- ///
- ///
- /// The type.
- /// The URI.
- private static IEnumerable GetUrisFor(IAssetLoader assetLocator, Type type)
- {
- var asm = type.GetTypeInfo().Assembly.GetName().Name;
- var xamlInfoUri = new Uri($"avares://{asm}/!AvaloniaResourceXamlInfo");
- var typeName = type.FullName;
- if (typeName == null)
- throw new ArgumentException("Type doesn't have a FullName");
-
- if (assetLocator.Exists(xamlInfoUri))
- {
- using (var xamlInfoStream = assetLocator.Open(xamlInfoUri))
- {
- var assetDoc = XDocument.Load(xamlInfoStream);
- XNamespace assetNs = assetDoc.Root.Attribute("xmlns").Value;
- XNamespace arrayNs = "http://schemas.microsoft.com/2003/10/Serialization/Arrays";
- Dictionary xamlInfo =
- assetDoc.Root.Element(assetNs + "ClassToResourcePathIndex").Elements(arrayNs + "KeyValueOfstringstring")
- .ToDictionary(entry =>entry.Element(arrayNs + "Key").Value,
- entry => entry.Element(arrayNs + "Value").Value);
-
- if (xamlInfo.TryGetValue(typeName, out var rv))
- {
- yield return new Uri($"avares://{asm}{rv}");
- yield break;
- }
- }
- }
-
- yield return new Uri("resm:" + typeName + ".xaml?assembly=" + asm);
- yield return new Uri("resm:" + typeName + ".paml?assembly=" + asm);
- }
-
public static object Parse(string xaml, Assembly localAssembly = null)
=> new AvaloniaXamlLoader().Load(xaml, localAssembly);
diff --git a/src/Markup/Avalonia.Markup.Xaml/Converters/AvaloniaEventConverter.cs b/src/Markup/Avalonia.Markup.Xaml/Converters/AvaloniaEventConverter.cs
deleted file mode 100644
index 665e71bfeae..00000000000
--- a/src/Markup/Avalonia.Markup.Xaml/Converters/AvaloniaEventConverter.cs
+++ /dev/null
@@ -1,99 +0,0 @@
-using System;
-using System.ComponentModel;
-using System.Globalization;
-using System.Linq;
-using System.Linq.Expressions;
-using System.Reflection;
-using Avalonia.Controls;
-using Avalonia.Markup.Xaml.PortableXaml;
-using Portable.Xaml;
-
-namespace Avalonia.Markup.Xaml.Converters
-{
- internal class AvaloniaEventConverter : TypeConverter
- {
- 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)
- {
- var rootObjectProvider = context.GetService(typeof(IRootObjectProvider)) as IRootObjectProvider;
- var destinationTypeProvider = context.GetService(typeof(IDestinationTypeProvider)) as IDestinationTypeProvider;
- if (rootObjectProvider != null && destinationTypeProvider != null)
- {
- var target = rootObjectProvider.RootObject;
- var eventType = destinationTypeProvider.GetDestinationType();
- var eventParameters = eventType.GetRuntimeMethods().First(r => r.Name == "Invoke").GetParameters();
- // go in reverse to match System.Xaml behaviour
- var methods = target.GetType().GetRuntimeMethods().Reverse();
-
- // find based on exact match parameter types first
- foreach (var method in methods)
- {
- if (method.Name != text)
- continue;
- var parameters = method.GetParameters();
- if (eventParameters.Length != parameters.Length)
- continue;
- if (parameters.Length == 0)
- return method.CreateDelegate(eventType, target);
-
- for (int i = 0; i < parameters.Length; i++)
- {
- var param = parameters[i];
- var eventParam = eventParameters[i];
- if (param.ParameterType != eventParam.ParameterType)
- break;
- if (i == parameters.Length - 1)
- return method.CreateDelegate(eventType, target);
- }
- }
-
- // EnhancedXaml: Find method with compatible base class parameters
- foreach (var method in methods)
- {
- if (method.Name != text)
- continue;
- var parameters = method.GetParameters();
- if (parameters.Length == 0 || eventParameters.Length != parameters.Length)
- continue;
-
- for (int i = 0; i < parameters.Length; i++)
- {
- var param = parameters[i];
- var eventParam = eventParameters[i];
- if (!param.ParameterType.GetTypeInfo().IsAssignableFrom(eventParam.ParameterType.GetTypeInfo()))
- break;
- if (i == parameters.Length - 1)
- return method.CreateDelegate(eventType, target);
- }
- }
-
- var contextProvider = (IXamlSchemaContextProvider)context.GetService(typeof(IXamlSchemaContextProvider));
- var avaloniaContext = (AvaloniaXamlSchemaContext)contextProvider.SchemaContext;
-
- if (avaloniaContext.IsDesignMode)
- {
- // We want to ignore missing events in the designer, so if event handler
- // wasn't found create an empty delegate.
- var lambdaExpression = Expression.Lambda(
- eventType,
- Expression.Empty(),
- eventParameters.Select(x => Expression.Parameter(x.ParameterType)));
- return lambdaExpression.Compile();
- }
- else
- {
- throw new XamlObjectWriterException($"Referenced value method {text} in type {target.GetType()} indicated by event {eventType.FullName} was not found");
- }
- }
- }
- return base.ConvertFrom(context, culture, value);
- }
- }
-}
diff --git a/src/Markup/Avalonia.Markup.Xaml/Converters/AvaloniaPropertyTypeConverter.cs b/src/Markup/Avalonia.Markup.Xaml/Converters/AvaloniaPropertyTypeConverter.cs
index 18a7fe9ab6a..b42bd536191 100644
--- a/src/Markup/Avalonia.Markup.Xaml/Converters/AvaloniaPropertyTypeConverter.cs
+++ b/src/Markup/Avalonia.Markup.Xaml/Converters/AvaloniaPropertyTypeConverter.cs
@@ -11,7 +11,6 @@
using Avalonia.Markup.Xaml.Templates;
using Avalonia.Styling;
using Avalonia.Utilities;
-using Portable.Xaml.ComponentModel;
namespace Avalonia.Markup.Xaml.Converters
{
diff --git a/src/Markup/Avalonia.Markup.Xaml/Converters/BitmapTypeConverter.cs b/src/Markup/Avalonia.Markup.Xaml/Converters/BitmapTypeConverter.cs
index bfee7b953b5..c75c54554e9 100644
--- a/src/Markup/Avalonia.Markup.Xaml/Converters/BitmapTypeConverter.cs
+++ b/src/Markup/Avalonia.Markup.Xaml/Converters/BitmapTypeConverter.cs
@@ -8,8 +8,7 @@
namespace Avalonia.Markup.Xaml.Converters
{
- using Portable.Xaml.ComponentModel;
- using System.ComponentModel;
+ using System.ComponentModel;
public class BitmapTypeConverter : TypeConverter
{
diff --git a/src/Markup/Avalonia.Markup.Xaml/Converters/FontFamilyTypeConverter.cs b/src/Markup/Avalonia.Markup.Xaml/Converters/FontFamilyTypeConverter.cs
index 863e8fbbce0..e92c1557730 100644
--- a/src/Markup/Avalonia.Markup.Xaml/Converters/FontFamilyTypeConverter.cs
+++ b/src/Markup/Avalonia.Markup.Xaml/Converters/FontFamilyTypeConverter.cs
@@ -7,7 +7,6 @@
using Avalonia.Media;
-using Portable.Xaml.ComponentModel;
namespace Avalonia.Markup.Xaml.Converters
{
diff --git a/src/Markup/Avalonia.Markup.Xaml/Converters/IconTypeConverter.cs b/src/Markup/Avalonia.Markup.Xaml/Converters/IconTypeConverter.cs
index f3972ffe188..3a2f41bd3d3 100644
--- a/src/Markup/Avalonia.Markup.Xaml/Converters/IconTypeConverter.cs
+++ b/src/Markup/Avalonia.Markup.Xaml/Converters/IconTypeConverter.cs
@@ -9,7 +9,6 @@
namespace Avalonia.Markup.Xaml.Converters
{
- using Portable.Xaml.ComponentModel;
using System.ComponentModel;
public class IconTypeConverter : TypeConverter
diff --git a/src/Markup/Avalonia.Markup.Xaml/Converters/NullableTypeConverter.cs b/src/Markup/Avalonia.Markup.Xaml/Converters/NullableTypeConverter.cs
deleted file mode 100644
index 5e7a31da560..00000000000
--- a/src/Markup/Avalonia.Markup.Xaml/Converters/NullableTypeConverter.cs
+++ /dev/null
@@ -1,89 +0,0 @@
-using System;
-using System.Collections;
-using System.ComponentModel;
-using System.Globalization;
-
-namespace Avalonia.Markup.Xaml.Converters
-{
- public class NullableTypeConverter : TypeConverter where T : TypeConverter, new()
- {
- private TypeConverter _inner;
-
- public NullableTypeConverter()
- {
- _inner = new T();
- }
-
- public NullableTypeConverter(TypeConverter inner)
- {
- _inner = inner;
- }
-
-
- public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
- {
- if (value == null)
- return null;
- return _inner.ConvertTo(context, culture, value, destinationType);
- }
-
- public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
- {
- if (value == null)
- return null;
- if (value as string == "")
- return null;
- return _inner.ConvertFrom(context, culture, value);
- }
-
- public override object CreateInstance(ITypeDescriptorContext context, IDictionary propertyValues)
- {
- return _inner.CreateInstance(context, propertyValues);
- }
-
- public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
- {
- return _inner.GetStandardValuesSupported(context);
- }
-
- public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
- {
- return _inner.GetStandardValuesExclusive(context);
- }
-
- public override bool GetCreateInstanceSupported(ITypeDescriptorContext context)
- {
- return _inner.GetCreateInstanceSupported(context);
- }
-
- public override bool GetPropertiesSupported(ITypeDescriptorContext context)
- {
- return _inner.GetPropertiesSupported(context);
- }
-
- public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
- {
- return _inner.GetStandardValues(context);
- }
-
- public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
- {
- return _inner.GetProperties(context, value, attributes);
- }
-
- public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
- {
- return _inner.CanConvertTo(context, destinationType);
- }
-
- public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
- {
- return _inner.CanConvertFrom(context, sourceType);
- }
-
- public override bool IsValid(ITypeDescriptorContext context, object value)
- {
- return _inner.IsValid(context, value);
- }
- }
-}
diff --git a/src/Markup/Avalonia.Markup.Xaml/Converters/ParseTypeConverter.cs b/src/Markup/Avalonia.Markup.Xaml/Converters/ParseTypeConverter.cs
deleted file mode 100644
index bfb446fa15c..00000000000
--- a/src/Markup/Avalonia.Markup.Xaml/Converters/ParseTypeConverter.cs
+++ /dev/null
@@ -1,79 +0,0 @@
-using System;
-using System.ComponentModel;
-using System.Globalization;
-using System.Reflection;
-
-namespace Avalonia.Markup.Xaml.Converters
-{
- ///
- /// Base class for type converters which call a static Parse method.
- ///
- public abstract class ParseTypeConverter : TypeConverter
- {
- protected const BindingFlags PublicStatic = BindingFlags.Public | BindingFlags.Static;
- protected static readonly Type[] StringParameter = new[] { typeof(string) };
- protected static readonly Type[] StringIFormatProviderParameters = new[] { typeof(string), typeof(IFormatProvider) };
-
- ///
- /// Checks whether a type has a suitable Parse method.
- ///
- /// The type.
- /// True if the type has a suitable parse method, otherwise false.
- public static bool HasParseMethod(Type type)
- {
- return type.GetMethod("Parse", PublicStatic, null, StringIFormatProviderParameters, null) != null ||
- type.GetMethod("Parse", PublicStatic, null, StringParameter, null) != null;
- }
- }
-
- ///
- /// A type converter which calls a static Parse method.
- ///
- /// The type with the Parse method.
- public class ParseTypeConverter : ParseTypeConverter
- {
- private static Func _parse;
- private static Func _parseWithFormat;
-
- static ParseTypeConverter()
- {
- var method = typeof(T).GetMethod("Parse", PublicStatic, null, StringIFormatProviderParameters, null);
-
- if (method != null)
- {
- _parseWithFormat = (Func)method
- .CreateDelegate(typeof(Func));
- return;
- }
-
- method = typeof(T).GetMethod("Parse", PublicStatic, null, StringParameter, null);
-
- if (method != null)
- {
- _parse = (Func)method.CreateDelegate(typeof(Func));
- }
- }
-
- public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
- {
- return sourceType == typeof(string);
- }
-
- public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
- {
- if (value != null)
- {
- if (_parse != null)
- {
- return _parse(value.ToString());
- }
- else if (_parseWithFormat != null)
- {
- return _parseWithFormat(value.ToString(), culture);
- }
- }
-
- return null;
- }
- }
-}
diff --git a/src/Markup/Avalonia.Markup.Xaml/Converters/SelectorTypeConverter.cs b/src/Markup/Avalonia.Markup.Xaml/Converters/SelectorTypeConverter.cs
deleted file mode 100644
index 54234fe406d..00000000000
--- a/src/Markup/Avalonia.Markup.Xaml/Converters/SelectorTypeConverter.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright (c) The Avalonia Project. All rights reserved.
-// Licensed under the MIT license. See licence.md file in the project root for full license information.
-
-using System;
-using System.Globalization;
-using Avalonia.Markup.Parsers;
-
-namespace Avalonia.Markup.Xaml.Converters
-{
- using Portable.Xaml.ComponentModel;
- using System.ComponentModel;
-
- public class SelectorTypeConverter : TypeConverter
- {
- public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
- {
- return sourceType == typeof(string);
- }
-
- public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
- {
- var parser = new SelectorParser(context.ResolveType);
-
- return parser.Parse((string)value);
- }
- }
-}
\ No newline at end of file
diff --git a/src/Markup/Avalonia.Markup.Xaml/Converters/SetterValueTypeConverter.cs b/src/Markup/Avalonia.Markup.Xaml/Converters/SetterValueTypeConverter.cs
deleted file mode 100644
index 81cda6db1f0..00000000000
--- a/src/Markup/Avalonia.Markup.Xaml/Converters/SetterValueTypeConverter.cs
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright (c) The Avalonia Project. All rights reserved.
-// Licensed under the MIT license. See licence.md file in the project root for full license information.
-
-using Avalonia.Styling;
-using Portable.Xaml;
-using Portable.Xaml.ComponentModel;
-using System.ComponentModel;
-using Portable.Xaml.Markup;
-using System;
-using System.Globalization;
-
-namespace Avalonia.Markup.Xaml.Converters
-{
- public class SetterValueTypeConverter : TypeConverter
- {
- public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
- {
- return sourceType == typeof(string);
- }
-
- public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
- {
- object setter = context.GetService().TargetObject;
- var schemaContext = context.GetService().SchemaContext;
-
- return ConvertSetterValue(context, schemaContext, culture, (setter as Setter), value);
- }
-
- [Obsolete("TODO: try assosiate Setter.Value property with SetterValueTypeConverter, so far coouldn't make it :(")]
- internal static object ConvertSetterValue(ITypeDescriptorContext dcontext, XamlSchemaContext context, CultureInfo info, Setter setter, object value)
- {
- Type targetType = setter?.Property?.PropertyType;
-
- if (targetType == null)
- {
- return value;
- }
-
- var ttConv = context.GetXamlType(targetType)?.TypeConverter?.ConverterInstance;
-
- if (ttConv != null)
- {
- value = ttConv.ConvertFromString(dcontext, info, value as string);
- }
-
- return value;
- }
- }
-}
\ No newline at end of file
diff --git a/src/Markup/Avalonia.Markup.Xaml/Extensions.cs b/src/Markup/Avalonia.Markup.Xaml/Extensions.cs
index c6b914ba72e..fe3fd44c1c4 100644
--- a/src/Markup/Avalonia.Markup.Xaml/Extensions.cs
+++ b/src/Markup/Avalonia.Markup.Xaml/Extensions.cs
@@ -3,8 +3,6 @@
using System.ComponentModel;
using System.Linq;
using Avalonia.Markup.Xaml.XamlIl.Runtime;
-using Portable.Xaml;
-using Portable.Xaml.Markup;
namespace Avalonia.Markup.Xaml
{
@@ -13,42 +11,19 @@ internal static class Extensions
public static T GetService(this IServiceProvider sp) => (T)sp?.GetService(typeof(T));
- public static Uri GetContextBaseUri(this IServiceProvider ctx)
- {
- var properService = ctx.GetService();
- if (properService != null)
- return properService.BaseUri;
- // Ugly hack with casts
- return Portable.Xaml.ComponentModel.TypeDescriptorExtensions.GetBaseUri((ITypeDescriptorContext)ctx);
- }
+ public static Uri GetContextBaseUri(this IServiceProvider ctx) => ctx.GetService().BaseUri;
- public static T GetFirstParent(this IServiceProvider ctx) where T : class
- {
- var parentStack = ctx.GetService();
- if (parentStack != null)
- return parentStack.Parents.OfType().FirstOrDefault();
- return Portable.Xaml.ComponentModel.TypeDescriptorExtensions.GetFirstAmbientValue((ITypeDescriptorContext)ctx);
- }
-
- public static T GetLastParent(this IServiceProvider ctx) where T : class
- {
- var parentStack = ctx.GetService();
- if (parentStack != null)
- return parentStack.Parents.OfType().LastOrDefault();
- return Portable.Xaml.ComponentModel.TypeDescriptorExtensions.GetLastOrDefaultAmbientValue(
- (ITypeDescriptorContext)ctx);
- }
+ public static T GetFirstParent(this IServiceProvider ctx) where T : class
+ => ctx.GetService().Parents.OfType().FirstOrDefault();
+
+ public static T GetLastParent(this IServiceProvider ctx) where T : class
+ => ctx.GetService().Parents.OfType().LastOrDefault();
public static IEnumerable GetParents(this IServiceProvider sp)
{
- var stack = sp.GetService();
- if (stack != null)
- return stack.Parents.OfType();
+ return sp.GetService().Parents.OfType();
+
- var context = (ITypeDescriptorContext)sp;
- var schemaContext = context.GetService().SchemaContext;
- var ambientProvider = context.GetService();
- return ambientProvider.GetAllAmbientValues(schemaContext.GetXamlType(typeof(T))).OfType();
}
public static Type ResolveType(this IServiceProvider ctx, string namespacePrefix, string type)
diff --git a/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/BindingExtension.cs b/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/BindingExtension.cs
index 223716ae3ba..726f4221f80 100644
--- a/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/BindingExtension.cs
+++ b/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/BindingExtension.cs
@@ -10,14 +10,9 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions
using Avalonia.Data.Converters;
using Avalonia.Markup.Data;
using Avalonia.Styling;
- using Portable.Xaml;
- using Portable.Xaml.ComponentModel;
- using Portable.Xaml.Markup;
- using PortableXaml;
using System.ComponentModel;
- [MarkupExtensionReturnType(typeof(IBinding))]
- public class BindingExtension : MarkupExtension
+ public class BindingExtension
{
public BindingExtension()
{
@@ -28,12 +23,7 @@ public BindingExtension(string path)
Path = path;
}
- public override object ProvideValue(IServiceProvider serviceProvider)
- {
- return ProvideTypedValue(serviceProvider);
- }
-
- public Binding ProvideTypedValue(IServiceProvider serviceProvider)
+ public Binding ProvideValue(IServiceProvider serviceProvider)
{
var descriptorContext = (ITypeDescriptorContext)serviceProvider;
diff --git a/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/DynamicResourceExtension.cs b/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/DynamicResourceExtension.cs
index 48e55dc2513..0a9289bec95 100644
--- a/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/DynamicResourceExtension.cs
+++ b/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/DynamicResourceExtension.cs
@@ -7,13 +7,10 @@
using System.Reactive.Linq;
using Avalonia.Controls;
using Avalonia.Data;
-using Portable.Xaml;
-using Portable.Xaml.ComponentModel;
-using Portable.Xaml.Markup;
namespace Avalonia.Markup.Xaml.MarkupExtensions
{
- public class DynamicResourceExtension : MarkupExtension, IBinding
+ public class DynamicResourceExtension : IBinding
{
private IResourceNode _anchor;
@@ -28,9 +25,7 @@ public DynamicResourceExtension(string resourceKey)
public object ResourceKey { get; set; }
- public override object ProvideValue(IServiceProvider serviceProvider) => ProvideTypedValue(serviceProvider);
-
- public IBinding ProvideTypedValue(IServiceProvider serviceProvider)
+ public IBinding ProvideValue(IServiceProvider serviceProvider)
{
var provideTarget = serviceProvider.GetService();
diff --git a/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/RelativeSourceExtension.cs b/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/RelativeSourceExtension.cs
index 2f7256fa22d..f690a5ff0e6 100644
--- a/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/RelativeSourceExtension.cs
+++ b/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/RelativeSourceExtension.cs
@@ -3,11 +3,10 @@
using System;
using Avalonia.Data;
-using Portable.Xaml.Markup;
namespace Avalonia.Markup.Xaml.MarkupExtensions
{
- public class RelativeSourceExtension : MarkupExtension
+ public class RelativeSourceExtension
{
public RelativeSourceExtension()
{
@@ -18,7 +17,7 @@ public RelativeSourceExtension(RelativeSourceMode mode)
Mode = mode;
}
- public override object ProvideValue(IServiceProvider serviceProvider)
+ public RelativeSource ProvideValue(IServiceProvider serviceProvider)
{
return new RelativeSource
{
@@ -38,4 +37,4 @@ public override object ProvideValue(IServiceProvider serviceProvider)
public int AncestorLevel { get; set; } = 1;
}
-}
\ No newline at end of file
+}
diff --git a/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/ResourceInclude.cs b/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/ResourceInclude.cs
index 323a341f6ae..3525628a796 100644
--- a/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/ResourceInclude.cs
+++ b/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/ResourceInclude.cs
@@ -1,15 +1,13 @@
using System;
using System.ComponentModel;
using Avalonia.Controls;
-using Portable.Xaml.ComponentModel;
-using Portable.Xaml.Markup;
namespace Avalonia.Markup.Xaml.MarkupExtensions
{
///
/// Loads a resource dictionary from a specified URL.
///
- public class ResourceInclude : MarkupExtension, IResourceProvider
+ public class ResourceInclude :IResourceProvider
{
private Uri _baseUri;
private IResourceDictionary _loaded;
@@ -52,13 +50,7 @@ bool IResourceProvider.TryGetResource(object key, out object value)
return Loaded.TryGetResource(key, out value);
}
- ///
- public override object ProvideValue(IServiceProvider serviceProvider)
- {
- return ProvideTypedValue(serviceProvider);
- }
-
- public ResourceInclude ProvideTypedValue(IServiceProvider serviceProvider)
+ public ResourceInclude ProvideValue(IServiceProvider serviceProvider)
{
var tdc = (ITypeDescriptorContext)serviceProvider;
_baseUri = tdc?.GetContextBaseUri();
diff --git a/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/StaticResourceExtension.cs b/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/StaticResourceExtension.cs
index ea913db5986..d6b170ae9db 100644
--- a/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/StaticResourceExtension.cs
+++ b/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/StaticResourceExtension.cs
@@ -7,13 +7,10 @@
using System.Reflection;
using Avalonia.Controls;
using Avalonia.Markup.Data;
-using Portable.Xaml;
-using Portable.Xaml.ComponentModel;
-using Portable.Xaml.Markup;
namespace Avalonia.Markup.Xaml.MarkupExtensions
{
- public class StaticResourceExtension : MarkupExtension
+ public class StaticResourceExtension
{
public StaticResourceExtension()
{
@@ -26,26 +23,13 @@ public StaticResourceExtension(string resourceKey)
public string ResourceKey { get; set; }
- public override object ProvideValue(IServiceProvider serviceProvider)
+ public object ProvideValue(IServiceProvider serviceProvider)
{
-
-
// Look upwards though the ambient context for IResourceProviders which might be able
// to give us the resource.
foreach (var resourceProvider in serviceProvider.GetParents())
{
- // We override XamlType.CanAssignTo in BindingXamlType so the results we get back
- // from GetAllAmbientValues aren't necessarily of the correct type.
-
- if (AvaloniaXamlLoader.UseLegacyXamlLoader
- && resourceProvider is IControl control && control.StylingParent != null)
- {
- // If we've got to a control that has a StylingParent then it's probably
- // a top level control and its StylingParent is pointing to the global
- // styles. If this is case just do a FindResource on it.
- return control.FindResource(ResourceKey);
- }
- else if (resourceProvider.TryGetResource(ResourceKey, out var value))
+ if (resourceProvider.TryGetResource(ResourceKey, out var value))
{
return value;
}
diff --git a/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/StyleIncludeExtension.cs b/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/StyleIncludeExtension.cs
index d9345738fcd..a323050c319 100644
--- a/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/StyleIncludeExtension.cs
+++ b/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/StyleIncludeExtension.cs
@@ -3,23 +3,18 @@
using Avalonia.Markup.Xaml.Styling;
using Avalonia.Styling;
-using Portable.Xaml;
-using Portable.Xaml.ComponentModel;
using System.ComponentModel;
-using Portable.Xaml.Markup;
using System;
namespace Avalonia.Markup.Xaml.MarkupExtensions
{
- [MarkupExtensionReturnType(typeof(IStyle))]
- public class StyleIncludeExtension : MarkupExtension
+ public class StyleIncludeExtension
{
public StyleIncludeExtension()
{
}
- public override object ProvideValue(IServiceProvider serviceProvider) => ProvideTypedValue(serviceProvider);
- public IStyle ProvideTypedValue(IServiceProvider serviceProvider)
+ public IStyle ProvideValue(IServiceProvider serviceProvider)
{
return new StyleInclude(serviceProvider.GetContextBaseUri()) { Source = Source };
}
diff --git a/src/Markup/Avalonia.Markup.Xaml/PortableXaml/AttributeExtensions.cs b/src/Markup/Avalonia.Markup.Xaml/PortableXaml/AttributeExtensions.cs
deleted file mode 100644
index 2a23b7e0688..00000000000
--- a/src/Markup/Avalonia.Markup.Xaml/PortableXaml/AttributeExtensions.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-using Avalonia.Markup.Xaml.Templates;
-using avm = Avalonia.Metadata;
-using pm = Portable.Xaml.Markup;
-
-namespace Avalonia.Markup.Xaml.PortableXaml
-{
- internal static class AttributeExtensions
- {
- public static pm.XamlDeferLoadAttribute ToPortableXaml(this avm.TemplateContentAttribute attrib)
- {
- if (attrib == null)
- {
- return null;
- }
-
- return new pm.XamlDeferLoadAttribute(typeof(TemplateLoader), typeof(TemplateContent));
- }
-
- public static pm.AmbientAttribute ToPortableXaml(this avm.AmbientAttribute attrib)
- {
- if (attrib == null)
- {
- return null;
- }
-
- return new pm.AmbientAttribute();
- }
-
- public static pm.DependsOnAttribute ToPortableXaml(this avm.DependsOnAttribute attrib)
- {
- if (attrib == null)
- {
- return null;
- }
-
- return new pm.DependsOnAttribute(attrib.Name);
- }
- }
-}
\ No newline at end of file
diff --git a/src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaMemberAttributeProvider.cs b/src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaMemberAttributeProvider.cs
deleted file mode 100644
index 529cbab9385..00000000000
--- a/src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaMemberAttributeProvider.cs
+++ /dev/null
@@ -1,83 +0,0 @@
-using Avalonia.Markup.Xaml.Converters;
-using Avalonia.Styling;
-using Portable.Xaml.ComponentModel;
-using System.ComponentModel;
-using System;
-using System.Linq;
-using System.Reflection;
-using avm = Avalonia.Metadata;
-using pm = Portable.Xaml.Markup;
-
-namespace Avalonia.Markup.Xaml.PortableXaml
-{
- public class AvaloniaMemberAttributeProvider : ICustomAttributeProvider
- {
- public AvaloniaMemberAttributeProvider(MemberInfo info)
- {
- _info = info;
- }
-
- public object[] GetCustomAttributes(bool inherit)
- {
- throw new NotImplementedException();
- }
-
- public object[] GetCustomAttributes(Type attributeType, bool inherit)
- {
- Attribute result = null;
-
- if (attributeType == typeof(pm.XamlDeferLoadAttribute))
- {
- result = _info.GetCustomAttribute(inherit)
- .ToPortableXaml();
- }
- else if (attributeType == typeof(pm.AmbientAttribute))
- {
- result = _info.GetCustomAttribute(inherit)
- .ToPortableXaml();
- }
- else if (attributeType == typeof(pm.DependsOnAttribute))
- {
- result = _info.GetCustomAttribute(inherit)
- .ToPortableXaml();
- }
- else if (attributeType == typeof(TypeConverterAttribute) &&
- _info.DeclaringType == typeof(Setter) &&
- _info.Name == nameof(Setter.Value))
- {
- //actually it never comes here looks like if property type is object
- //Portable.Xaml is not searching for Type Converter
- result = new TypeConverterAttribute(typeof(SetterValueTypeConverter));
- }
- else if (attributeType == typeof(TypeConverterAttribute) && _info is EventInfo)
- {
- // If a type converter for `EventInfo` is registered, then use that to convert
- // event handler values. This is used by the designer to override the lookup
- // for event handlers with a null handler.
- var eventConverter = AvaloniaTypeConverters.GetTypeConverter(typeof(EventInfo));
-
- if (eventConverter != null)
- {
- result = new TypeConverterAttribute(eventConverter);
- }
- }
-
- if (result == null)
- {
- var attr = _info.GetCustomAttributes(attributeType, inherit);
- return (attr as object[]) ?? attr.ToArray();
- }
- else
- {
- return new object[] { result };
- }
- }
-
- public bool IsDefined(Type attributeType, bool inherit)
- {
- throw new NotImplementedException();
- }
-
- private readonly MemberInfo _info;
- }
-}
diff --git a/src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaNameScope.cs b/src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaNameScope.cs
deleted file mode 100644
index 6f855bafa13..00000000000
--- a/src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaNameScope.cs
+++ /dev/null
@@ -1,56 +0,0 @@
-using System.Collections.Generic;
-using Avalonia.Controls;
-
-namespace Avalonia.Markup.Xaml.PortableXaml
-{
- internal class AvaloniaNameScope : Portable.Xaml.Markup.INameScope
- {
- public object Instance { get; set; }
-
- private Dictionary _names = new Dictionary();
-
- public object FindName(string name)
- {
- object result;
- if (_names.TryGetValue(name, out result))
- return result;
- return null;
- }
-
- public void RegisterName(string name, object scopedElement)
- {
- if (scopedElement != null)
- _names.Add(name, scopedElement);
-
- //TODO: ???
- //var control = scopedElement as Control;
-
- //if (control != null)
- //{
- // var nameScope = (Instance as INameScope) ?? control.FindNameScope();
-
- // if (nameScope != null)
- // {
- // nameScope.Register(name, scopedElement);
- // }
- //}
- }
-
- public void UnregisterName(string name)
- {
- }
-
- public void RegisterOnNameScope(object target)
- {
- var nameScope = target as INameScope;
-
- if (nameScope != null)
- {
- foreach (var v in _names)
- {
- nameScope.Register(v.Key, v.Value);
- }
- }
- }
- }
-}
\ No newline at end of file
diff --git a/src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaRuntimeTypeProvider.cs b/src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaRuntimeTypeProvider.cs
deleted file mode 100644
index eb52e317b86..00000000000
--- a/src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaRuntimeTypeProvider.cs
+++ /dev/null
@@ -1,147 +0,0 @@
-// Copyright (c) The Avalonia Project. All rights reserved.
-// Licensed under the MIT license. See licence.md file in the project root for full license information.
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using Avalonia.Controls;
-using Avalonia.Data;
-using Avalonia.Markup.Xaml.Templates;
-using Avalonia.Media;
-using Avalonia.Metadata;
-using Avalonia.Platform;
-using Avalonia.Styling;
-
-namespace Avalonia.Markup.Xaml.Context
-{
- using ClrNamespaceInfo = Tuple;
-
- public interface IRuntimeTypeProvider
- {
- Type FindType(string xamlNamespace, string name, Type[] genArgs);
-
- IEnumerable ReferencedAssemblies { get; }
- }
-
- public class AvaloniaRuntimeTypeProvider : IRuntimeTypeProvider
- {
- private const string ClrNamespace = "clr-namespace:";
- // private const string AvaloniaNs = "https://github.com/avaloniaui";
-
- private static readonly IEnumerable ForcedAssemblies = new[]
- {
- typeof(AvaloniaObject).GetTypeInfo().Assembly,
- typeof(Animation.Animation).GetTypeInfo().Assembly,
- typeof(Control).GetTypeInfo().Assembly,
- typeof(Style).GetTypeInfo().Assembly,
- typeof(DataTemplate).GetTypeInfo().Assembly,
- typeof(SolidColorBrush).GetTypeInfo().Assembly,
- typeof(Binding).GetTypeInfo().Assembly,
- };
-
- private Dictionary> _namespaces = new Dictionary>();
-
- private List _scanned = new List();
-
- public IEnumerable ReferencedAssemblies => _scanned;
-
- public AvaloniaRuntimeTypeProvider()
- {
- ScanAssemblies(ForcedAssemblies);
- ScanNewAssemblies();
- }
-
- private static bool IsClrNamespace(string ns)
- {
- return ns.StartsWith(ClrNamespace);
- }
-
- private static Assembly GetAssembly(string assemblyName)
- {
- return Assembly.Load(new AssemblyName(assemblyName));
- }
-
- private void ScanAssemblies(IEnumerable assemblies)
- {
- foreach (var assembly in assemblies)
- {
- var namespaces = assembly.GetCustomAttributes()
- .Select(x => new { x.XmlNamespace, x.ClrNamespace })
- .GroupBy(x => x.XmlNamespace);
-
- foreach (var nsa in namespaces)
- {
- HashSet reg;
-
- if (!_namespaces.TryGetValue(nsa.Key, out reg))
- {
- _namespaces[nsa.Key] = reg = new HashSet>();
- }
-
- foreach (var child in nsa)
- {
- reg.Add(new ClrNamespaceInfo(child.ClrNamespace, assembly));
- }
- }
-
- _scanned.Add(assembly);
- }
- }
-
- private void ScanNewAssemblies()
- {
- IEnumerable assemblies = AppDomain.CurrentDomain.GetAssemblies();
-
- if (assemblies != null)
- {
- assemblies = assemblies.Except(_scanned);
- ScanAssemblies(assemblies);
- }
- }
-
- private Dictionary _typeCache = new Dictionary();
-
- public Type FindType(string xamlNamespace, string name, Type[] genArgs)
- {
- if (IsClrNamespace(xamlNamespace))
- {
- //we need to handle only xaml url namespaces for avalonia,
- //the other namespaces are handled well in portable.xaml
- return null;
- }
-
- string key = $"{xamlNamespace}:{name}";
-
- Type type;
-
- if (_typeCache.TryGetValue(key, out type))
- {
- return type;
- }
-
- HashSet reg;
-
- if (!_namespaces.TryGetValue(xamlNamespace, out reg))
- {
- return null;
- }
-
- if (genArgs != null)
- name += "`" + genArgs.Length;
-
- foreach (var ns in reg)
- {
- var n = ns.Item1 + "." + name;
- var t = ns.Item2.GetType(n);
- if (t != null)
- {
- _typeCache[key] = t;
- return t;
- }
- }
-
- return null;
- }
- }
-}
diff --git a/src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaTypeAttributeProvider.cs b/src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaTypeAttributeProvider.cs
deleted file mode 100644
index 7558a5df0bd..00000000000
--- a/src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaTypeAttributeProvider.cs
+++ /dev/null
@@ -1,117 +0,0 @@
-// Copyright (c) The Perspex Project. All rights reserved.
-// Licensed under the MIT license. See licence.md file in the project root for full license information.
-
-using Portable.Xaml.ComponentModel;
-using System.ComponentModel;
-using System;
-using System.Linq;
-using System.Reflection;
-using avm = Avalonia.Metadata;
-using pm = Portable.Xaml.Markup;
-
-namespace Avalonia.Markup.Xaml.PortableXaml
-{
- internal class AvaloniaTypeAttributeProvider : ICustomAttributeProvider
- {
- public AvaloniaTypeAttributeProvider(Type type)
- {
- _type = type;
- }
-
- public object[] GetCustomAttributes(bool inherit)
- {
- throw new NotImplementedException();
- }
-
- public object[] GetCustomAttributes(Type attributeType, bool inherit)
- {
- Attribute result = null;
-
- var ti = _type.GetTypeInfo();
-
- if (attributeType == typeof(pm.ContentPropertyAttribute))
- {
- result = GetContentPropertyAttribute(inherit);
- }
- else if (attributeType == typeof(pm.RuntimeNamePropertyAttribute))
- {
- if (_namedType.IsAssignableFrom(ti))
- {
- result = new pm.RuntimeNamePropertyAttribute(nameof(INamed.Name));
- }
- }
- else if (attributeType == typeof(TypeConverterAttribute))
- {
- var builtin = AvaloniaTypeConverters.GetBuiltinTypeConverter(_type);
- if (builtin != null)
- result = new TypeConverterAttribute(builtin);
- result = result ?? ti.GetCustomAttribute(attributeType, inherit);
-
- if (result == null)
- {
- var convType = AvaloniaTypeConverters.GetTypeConverter(_type);
-
- if (convType != null)
- {
- result = new TypeConverterAttribute(convType);
- }
- }
- }
- else if (attributeType == typeof(pm.AmbientAttribute))
- {
- result = ti.GetCustomAttribute(inherit)
- .ToPortableXaml();
- }
-
- if (result == null)
- {
- var attr = ti.GetCustomAttributes(attributeType, inherit);
- return (attr as object[]) ?? attr.ToArray();
- }
- else
- {
- return new object[] { result };
- }
- }
-
- public bool IsDefined(Type attributeType, bool inherit)
- {
- throw new NotImplementedException();
- }
-
- private readonly TypeInfo _namedType = typeof(INamed).GetTypeInfo();
-
- private readonly Type _type;
-
- private Attribute GetContentPropertyAttribute(bool inherit)
- {
- var type = _type;
-
- while (type != null)
- {
- var properties = type.GetTypeInfo().DeclaredProperties
- .Where(x => x.GetCustomAttribute() != null);
- string result = null;
-
- foreach (var property in properties)
- {
- if (result != null)
- {
- throw new Exception($"Content property defined more than once on {type}.");
- }
-
- result = property.Name;
- }
-
- if (result != null)
- {
- return new pm.ContentPropertyAttribute(result);
- }
-
- type = inherit ? type.GetTypeInfo().BaseType : null;
- }
-
- return null;
- }
- }
-}
diff --git a/src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaXamlContext.cs b/src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaXamlContext.cs
deleted file mode 100644
index c159b551b79..00000000000
--- a/src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaXamlContext.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-using Portable.Xaml;
-using Portable.Xaml.Markup;
-using System;
-using System.Reflection;
-
-namespace Avalonia.Markup.Xaml.PortableXaml
-{
- public class AvaloniaXamlContext : IUriContext
- {
- private AvaloniaXamlContext()
- {
- }
-
- public Assembly LocalAssembly { get; private set; }
-
- public Uri BaseUri { get; set; }
-
- public object RootInstance { get; private set; }
-
- internal static AvaloniaXamlContext For(XamlXmlReaderSettings sett,
- object rootInstance)
- {
- return new AvaloniaXamlContext()
- {
- BaseUri = sett.BaseUri,
- LocalAssembly = sett.LocalAssembly,
- RootInstance = rootInstance
- };
- }
- }
-}
\ No newline at end of file
diff --git a/src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaXamlObjectWriter.cs b/src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaXamlObjectWriter.cs
deleted file mode 100644
index 9fa6c26c351..00000000000
--- a/src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaXamlObjectWriter.cs
+++ /dev/null
@@ -1,222 +0,0 @@
-using Avalonia.Data;
-using Portable.Xaml;
-using Portable.Xaml.ComponentModel;
-using System.ComponentModel;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using Avalonia.Controls;
-using Portable.Xaml.Schema;
-
-namespace Avalonia.Markup.Xaml.PortableXaml
-{
- class AvaloniaXamlObjectWriter : XamlObjectWriter
- {
- private static Dictionary DesignDirectives = new Dictionary
- {
- ["DataContext"] = "DataContext",
- ["DesignWidth"] = "Width", ["DesignHeight"] = "Height", ["PreviewWith"] = "PreviewWith"
- }
- .ToDictionary(p => new XamlDirective(
- new[] {"http://schemas.microsoft.com/expression/blend/2008"}, p.Key,
- XamlLanguage.Object, null, AllowedMemberLocations.Attribute), p => p.Value);
-
- private readonly AvaloniaXamlSchemaContext _schemaContext;
-
- public static AvaloniaXamlObjectWriter Create(
- AvaloniaXamlSchemaContext schemaContext,
- AvaloniaXamlContext context,
- IAmbientProvider parentAmbientProvider = null)
- {
- var nameScope = new AvaloniaNameScope { Instance = context?.RootInstance };
-
- var writerSettings = new XamlObjectWriterSettings()
- {
- ExternalNameScope = nameScope,
- RegisterNamesOnExternalNamescope = true,
- RootObjectInstance = context?.RootInstance
- };
-
- return new AvaloniaXamlObjectWriter(schemaContext,
- writerSettings.WithContext(context),
- nameScope,
- parentAmbientProvider);
- }
-
- private readonly DelayedValuesHelper _delayedValuesHelper = new DelayedValuesHelper();
-
- private AvaloniaNameScope _nameScope;
-
- private AvaloniaXamlObjectWriter(
- AvaloniaXamlSchemaContext schemaContext,
- XamlObjectWriterSettings settings,
- AvaloniaNameScope nameScope,
- IAmbientProvider parentAmbientProvider)
- : base(schemaContext, settings, parentAmbientProvider)
- {
- _nameScope = nameScope;
- _schemaContext = schemaContext;
- }
-
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- if (_nameScope != null && Result != null)
- {
- _nameScope.RegisterOnNameScope(Result);
- }
- }
-
- base.Dispose(disposing);
- }
-
- public void ApplyAllDelayedProperties()
- {
- //HACK: We need this because Begin/EndInit ordering is broken
- _delayedValuesHelper.ApplyAll();
- }
-
- protected internal override void OnAfterProperties(object value)
- {
- _delayedValuesHelper.EndInit(value);
-
- base.OnAfterProperties(value);
- }
-
- protected internal override void OnBeforeProperties(object value)
- {
- if (value != null)
- _delayedValuesHelper.BeginInit(value);
-
- base.OnBeforeProperties(value);
- }
-
- protected internal override bool OnSetValue(object target, XamlMember member, object value)
- {
- if (_delayedValuesHelper.TryAdd(target, member, value))
- {
- return true;
- }
-
- return base.OnSetValue(target, member, value);
- }
-
- public override void WriteStartMember(XamlMember property)
- {
- foreach(var d in DesignDirectives)
- if (property == d.Key && _schemaContext.IsDesignMode)
- {
- base.WriteStartMember(new XamlMember(d.Value,
- typeof(Design).GetMethod("Get" + d.Value, BindingFlags.Static | BindingFlags.Public),
- typeof(Design).GetMethod("Set" + d.Value, BindingFlags.Static | BindingFlags.Public),
- SchemaContext));
- return;
- }
- base.WriteStartMember(property);
- }
-
- private class DelayedValuesHelper
- {
- private int _cnt;
-
- private HashSet
-
+
diff --git a/tests/Avalonia.DesignerSupport.TestApp/MainWindow.xaml b/tests/Avalonia.DesignerSupport.TestApp/MainWindow.xaml
index 6938bd8c49a..f90e5beaa69 100644
--- a/tests/Avalonia.DesignerSupport.TestApp/MainWindow.xaml
+++ b/tests/Avalonia.DesignerSupport.TestApp/MainWindow.xaml
@@ -1,5 +1,7 @@
+ Title="TESTAPP"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ x:Class="Avalonia.DesignerSupport.TestApp.MainWindow">
-
\ No newline at end of file
+
diff --git a/tests/Avalonia.DesignerSupport.Tests/DesignerSupportTests.cs b/tests/Avalonia.DesignerSupport.Tests/DesignerSupportTests.cs
index a01bbe0845a..01fa0e7783d 100644
--- a/tests/Avalonia.DesignerSupport.Tests/DesignerSupportTests.cs
+++ b/tests/Avalonia.DesignerSupport.Tests/DesignerSupportTests.cs
@@ -118,10 +118,21 @@ await conn.Send(new UpdateXamlMessage
cancelled = true;
}
- Assert.True(cancelled, $"Message Not Received.");
- Assert.NotEqual(0, handle);
- proc.Kill();
+ try
+ {
+ proc.Kill();
+ }
+ catch
+ {
+ //
+ }
+
proc.WaitForExit();
+ Assert.True(cancelled,
+ $"Message Not Received.\n" + proc.StandardOutput.ReadToEnd() + "\n" +
+ proc.StandardError.ReadToEnd());
+ Assert.NotEqual(0, handle);
+
}
}
}
diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/Converters/AvaloniaPropertyConverterTest.cs b/tests/Avalonia.Markup.Xaml.UnitTests/Converters/AvaloniaPropertyConverterTest.cs
index f6f56231bc8..d82300b9649 100644
--- a/tests/Avalonia.Markup.Xaml.UnitTests/Converters/AvaloniaPropertyConverterTest.cs
+++ b/tests/Avalonia.Markup.Xaml.UnitTests/Converters/AvaloniaPropertyConverterTest.cs
@@ -8,9 +8,7 @@
using Avalonia.Styling;
using Xunit;
using System.ComponentModel;
-using Portable.Xaml;
-using Portable.Xaml.Markup;
-using Avalonia.Controls;
+using Avalonia.Markup.Xaml.XamlIl.Runtime;
namespace Avalonia.Markup.Xaml.UnitTests.Converters
{
@@ -91,27 +89,23 @@ public void ConvertFrom_Throws_For_Nonexistent_Attached_Property()
Assert.Equal("Could not find property 'AttachedOwner.NonExistent'.", ex.Message);
}
+
+
private ITypeDescriptorContext CreateContext(Style style = null)
{
var tdMock = new Mock();
- var xsc = new Mock();
- var sc = Mock.Of();
- var amb = new Mock();
var tr = new Mock();
+ var ps = new Mock();
- tdMock.Setup(d => d.GetService(typeof(IAmbientProvider)))
- .Returns(amb.Object);
- tdMock.Setup(d => d.GetService(typeof(IXamlSchemaContextProvider)))
- .Returns(xsc.Object);
tdMock.Setup(d => d.GetService(typeof(IXamlTypeResolver)))
.Returns(tr.Object);
- xsc.SetupGet(v => v.SchemaContext)
- .Returns(sc);
- amb.Setup(v => v.GetFirstAmbientValue(It.IsAny()))
- .Returns(style);
- amb.Setup(v => v.GetAllAmbientValues(It.IsAny()))
- .Returns(new object[] { style });
+ tdMock.Setup(d => d.GetService(typeof(IAvaloniaXamlIlParentStackProvider)))
+ .Returns(ps.Object);
+
+ ps.SetupGet(v => v.Parents)
+ .Returns(new object[] {style});
+
tr.Setup(v => v.Resolve(nameof(Class1)))
.Returns(typeof(Class1));
tr.Setup(v => v.Resolve(nameof(AttachedOwner)))
diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BasicTests.cs b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BasicTests.cs
index 359d2521e0d..7fe0fc4a087 100644
--- a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BasicTests.cs
+++ b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BasicTests.cs
@@ -14,7 +14,6 @@
using Avalonia.Media.Immutable;
using Avalonia.Styling;
using Avalonia.UnitTests;
-using Portable.Xaml;
using System.Collections;
using System.ComponentModel;
using System.Linq;
@@ -47,37 +46,6 @@ public void Default_Content_Property_Is_Set()
Assert.Equal("Foo", target.Content);
}
- [Fact]
- public void AvaloniaProperty_Without_Getter_And_Setter_Is_Set()
- {
- // It's not possible to know in compile time if a read-only property has a magic way of being not read-only
- if (!AvaloniaXamlLoader.UseLegacyXamlLoader)
- return;
- var xaml =
- @"";
-
- var target = AvaloniaXamlLoader.Parse(xaml);
-
- Assert.Equal(55, target.GetValue(NonControl.FooProperty));
- }
-
- [Fact]
- public void AvaloniaProperty_With_Getter_And_No_Setter_Is_Set()
- {
- if(!AvaloniaXamlLoader.UseLegacyXamlLoader)
- return;
- var xaml =
-@"";
-
- var target = AvaloniaXamlLoader.Parse(xaml);
-
- Assert.Equal("bar", target.Bar);
- }
-
[Fact]
public void Attached_Property_Is_Set()
{
@@ -159,19 +127,6 @@ public void NonExistent_Property_Throws()
XamlTestHelpers.AssertThrowsXamlException(() => AvaloniaXamlLoader.Parse(xaml));
}
- [Fact]
- public void Non_Attached_Property_With_Attached_Property_Syntax_Throws()
- {
- // 1) It has been allowed in AvaloniaObject.SetValue for ages
- // 2) There is no way to know if AddOwner was called in compile-time
- if (!AvaloniaXamlLoader.UseLegacyXamlLoader)
- return;
- var xaml =
- @"";
-
- XamlTestHelpers.AssertThrowsXamlException(() => AvaloniaXamlLoader.Parse(xaml));
- }
-
[Fact]
public void ContentControl_ContentTemplate_Is_Functional()
{
@@ -595,31 +550,6 @@ public void Simple_Xaml_Binding_Is_Operational()
}
}
- [Fact]
- public void Xaml_Binding_Is_Delayed()
- {
- if (!AvaloniaXamlLoader.UseLegacyXamlLoader)
- return;
-
- using (UnitTestApplication.Start(TestServices.MockWindowingPlatform))
- {
- var xaml =
-@"";
-
- var target = AvaloniaXamlLoader.Parse(xaml);
-
- Assert.Null(target.Content);
-
- target.DataContext = "Foo";
-
- Assert.Null(target.Content);
-
- DelayedBinding.ApplyBindings(target);
-
- Assert.Equal("Foo", target.Content);
- }
- }
-
[Fact]
public void Double_Xaml_Binding_Is_Operational()
{
diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/EventTests.cs b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/EventTests.cs
index dbb34a7eba4..44697f59371 100644
--- a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/EventTests.cs
+++ b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/EventTests.cs
@@ -5,7 +5,6 @@
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
-using Portable.Xaml;
using Xunit;
namespace Avalonia.Markup.Xaml.UnitTests.Xaml
@@ -35,19 +34,6 @@ public void Exception_Is_Thrown_If_Event_Not_Found()
XamlTestHelpers.AssertThrowsXamlException(() => loader.Load(xaml, rootInstance: target));
}
- [Fact]
- public void Exception_Is_Not_Thrown_If_Event_Not_Found_In_Design_Mode()
- {
- // Runtime compiler should properly understand x:Class
- if (!AvaloniaXamlLoader.UseLegacyXamlLoader)
- return;
- var xaml = @"";
- var loader = new AvaloniaXamlLoader { IsDesignMode = true };
- var target = new MyButton();
-
- loader.Load(xaml, rootInstance: target);
- }
-
private void RaiseClick(MyButton target)
{
target.RaiseEvent(new KeyEventArgs
diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/StyleTests.cs b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/StyleTests.cs
index a84ce74a884..8dd1d24dd63 100644
--- a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/StyleTests.cs
+++ b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/StyleTests.cs
@@ -1,13 +1,13 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
+using System.Xml;
using Avalonia.Controls;
using Avalonia.Markup.Data;
using Avalonia.Markup.Xaml.Styling;
using Avalonia.Media;
using Avalonia.Styling;
using Avalonia.UnitTests;
-using Portable.Xaml;
using Xunit;
namespace Avalonia.Markup.Xaml.UnitTests.Xaml
@@ -191,7 +191,7 @@ public void Disallows_Setting_Non_Registered_Property()
";
var loader = new AvaloniaXamlLoader();
- var ex = Assert.Throws(() => loader.Load(xaml));
+ var ex = Assert.Throws(() => loader.Load(xaml));
Assert.Equal(
"Property 'Button.IsDefault' is not registered on 'Avalonia.Controls.TextBlock'.",
diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/XamlTestHelpers.cs b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/XamlTestHelpers.cs
index 1b09ddc1865..c23f01db07d 100644
--- a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/XamlTestHelpers.cs
+++ b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/XamlTestHelpers.cs
@@ -1,6 +1,5 @@
using System;
using System.Xml;
-using Portable.Xaml;
namespace Avalonia.Markup.Xaml.UnitTests.Xaml
{
@@ -14,7 +13,7 @@ public static void AssertThrowsXamlException(Action cb)
}
catch (Exception e)
{
- if(e is XamlObjectWriterException || e is XmlException)
+ if(e is XmlException)
return;
}
throw new Exception("Expected to throw xaml exception");