[X] avoid throwing in VisualDiagnostics (#7571)

this fixes a regression introduced in #7474

- fixes #7570
This commit is contained in:
Stephane Delcroix 2019-09-18 16:41:18 +02:00 коммит произвёл GitHub
Родитель f417a8743e
Коммит 66b32f6f04
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 17 добавлений и 7 удалений

Просмотреть файл

@ -346,22 +346,28 @@ namespace Xamarin.Forms.Xaml
//If it's a BindableProberty, SetValue
if (xpe == null && TrySetValue(xamlelement, property, attached, value, lineInfo, serviceProvider, out xpe)) {
VisualDiagnostics.RegisterSourceInfo(value, null, ((IXmlLineInfo)node).LineNumber, ((IXmlLineInfo)node).LinePosition);
VisualDiagnostics.SendVisualTreeChanged(xamlelement, value);
if (!(node is ValueNode) && value != null && !value.GetType().GetTypeInfo().IsValueType && XamlFilePathAttribute.GetFilePathForObject(context.RootElement) is string path) {
VisualDiagnostics.RegisterSourceInfo(value, new Uri(path, UriKind.Relative), ((IXmlLineInfo)node).LineNumber, ((IXmlLineInfo)node).LinePosition);
VisualDiagnostics.SendVisualTreeChanged(xamlelement, value);
}
return;
}
//If we can assign that value to a normal property, let's do it
if (xpe == null && TrySetProperty(xamlelement, localName, value, lineInfo, serviceProvider, context, out xpe)) {
VisualDiagnostics.RegisterSourceInfo(value, null, ((IXmlLineInfo)node).LineNumber, ((IXmlLineInfo)node).LinePosition);
VisualDiagnostics.SendVisualTreeChanged(xamlelement, value);
if (!(node is ValueNode) && value != null && !value.GetType().GetTypeInfo().IsValueType && XamlFilePathAttribute.GetFilePathForObject(context.RootElement) is string path) {
VisualDiagnostics.RegisterSourceInfo(value, new Uri(path, UriKind.Relative), ((IXmlLineInfo)node).LineNumber, ((IXmlLineInfo)node).LinePosition);
VisualDiagnostics.SendVisualTreeChanged(xamlelement, value);
}
return;
}
//If it's an already initialized property, add to it
if (xpe == null && TryAddToProperty(xamlelement, propertyName, value, xKey, lineInfo, serviceProvider, context, out xpe)) {
VisualDiagnostics.RegisterSourceInfo(value, null, ((IXmlLineInfo)node).LineNumber, ((IXmlLineInfo)node).LinePosition);
VisualDiagnostics.SendVisualTreeChanged(xamlelement, value);
if (!(node is ValueNode) && value != null && !value.GetType().GetTypeInfo().IsValueType && XamlFilePathAttribute.GetFilePathForObject(context.RootElement) is string path) {
VisualDiagnostics.RegisterSourceInfo(value, new Uri(path, UriKind.Relative), ((IXmlLineInfo)node).LineNumber, ((IXmlLineInfo)node).LinePosition);
VisualDiagnostics.SendVisualTreeChanged(xamlelement, value);
}
return;
}

Просмотреть файл

@ -7,6 +7,10 @@ namespace Xamarin.Forms.Xaml.Diagnostics
{
static class DebuggerHelper
{
#if DEBUG
static DebuggerHelper() => _mockDebuggerIsAttached = true;
#endif
internal static bool _mockDebuggerIsAttached;
public static bool DebuggerIsAttached => _mockDebuggerIsAttached || Debugger.IsAttached;
}

Просмотреть файл

@ -12,7 +12,7 @@ namespace Xamarin.Forms.Xaml.Diagnostics
static ConditionalWeakTable<object, XamlSourceInfo> sourceInfos = new ConditionalWeakTable<object, XamlSourceInfo>();
internal static void RegisterSourceInfo(object target, Uri uri, int lineNumber, int linePosition)
{
if (DebuggerHelper.DebuggerIsAttached)
if (DebuggerHelper.DebuggerIsAttached && !sourceInfos.TryGetValue(target, out _))
sourceInfos.Add(target, new XamlSourceInfo(uri, lineNumber, linePosition));
}