[X] resilience on markup (#5532)
let the previewer intercepts and recover from misformatted markups - fixes #5508 - closes #5527
This commit is contained in:
Родитель
362a9b200a
Коммит
263c9a9d6a
|
@ -564,23 +564,22 @@ namespace Xamarin.Forms.Xaml.UnitTests
|
|||
<StackLayout>
|
||||
<ListView ItemsSource=""{x:Static Foo}"" />
|
||||
<ListView ItemsSource=""{local:Missing Test}"" />
|
||||
<Label Text=""{Binding Foo"" />
|
||||
</StackLayout>
|
||||
</ContentPage>";
|
||||
|
||||
var exceptions = new List<Exception>();
|
||||
Xamarin.Forms.Internals.ResourceLoader.ExceptionHandler = exceptions.Add;
|
||||
Assert.DoesNotThrow(() => XamlLoader.Create(xaml, true));
|
||||
Assert.That(exceptions.Count, Is.GreaterThan(1));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Test]
|
||||
public void CanResolveRootNode()
|
||||
{
|
||||
string assemblyName = null;
|
||||
string clrNamespace = null;
|
||||
string typeName = null;
|
||||
|
||||
|
||||
XamlLoader.FallbackTypeResolver = (fallbackTypeInfos, type) =>
|
||||
{
|
||||
assemblyName = fallbackTypeInfos?[1].AssemblyName;
|
||||
|
|
|
@ -78,17 +78,28 @@ namespace Xamarin.Forms.Xaml
|
|||
if (expression.StartsWith("{}", StringComparison.Ordinal))
|
||||
return new ValueNode(expression.Substring(2), null);
|
||||
|
||||
if (expression[expression.Length - 1] != '}')
|
||||
throw new Exception("Expression must end with '}'");
|
||||
if (expression[expression.Length - 1] != '}') {
|
||||
var ex = new XamlParseException("Expression must end with '}'", xmlLineInfo);
|
||||
if (Context.ExceptionHandler != null) {
|
||||
Context.ExceptionHandler(ex);
|
||||
return null;
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
|
||||
int len;
|
||||
string match;
|
||||
if (!MarkupExpressionParser.MatchMarkup(out match, expression, out len))
|
||||
if (!MarkupExpressionParser.MatchMarkup(out var match, expression, out var len))
|
||||
throw new Exception();
|
||||
expression = expression.Substring(len).TrimStart();
|
||||
if (expression.Length == 0)
|
||||
throw new Exception("Expression did not end in '}'");
|
||||
|
||||
expression = expression.Substring(len).TrimStart();
|
||||
if (expression.Length == 0) {
|
||||
var ex = new XamlParseException("Expression did not end in '}'", xmlLineInfo);
|
||||
if (Context.ExceptionHandler != null)
|
||||
{
|
||||
Context.ExceptionHandler(ex);
|
||||
return null;
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
var serviceProvider = new XamlServiceProvider(node, Context);
|
||||
serviceProvider.Add(typeof (IXmlNamespaceResolver), nsResolver);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче