object IExtendedTypeConverter.ConvertFromInvariantString(string value, IServiceProvider serviceProvider) { if (serviceProvider == null) { throw new ArgumentNullException(nameof(serviceProvider)); } var targetRD = (serviceProvider.GetService(typeof(Xaml.IProvideValueTarget)) as Xaml.IProvideValueTarget)?.TargetObject as ResourceDictionary; if (targetRD == null) { return(null); } var rootObjectType = (serviceProvider.GetService(typeof(Xaml.IRootObjectProvider)) as Xaml.IRootObjectProvider)?.RootObject.GetType(); if (rootObjectType == null) { return(null); } var lineInfo = (serviceProvider.GetService(typeof(Xaml.IXmlLineInfoProvider)) as Xaml.IXmlLineInfoProvider)?.XmlLineInfo; var rootTargetPath = XamlResourceIdAttribute.GetPathForType(rootObjectType); var uri = new Uri(value, UriKind.Relative); //we don't want file:// uris, even if they start with '/' var resourcePath = GetResourcePath(uri, rootTargetPath); targetRD.SetAndLoadSource(uri, resourcePath, rootObjectType.GetTypeInfo().Assembly, lineInfo); return(uri); }
public void XamlResourceIdAttributeGetPathForType() { tlog.Debug(tag, $"XamlResourceIdAttributeGetPathForType START"); try { var ret = XamlResourceIdAttribute.GetPathForType(typeof(TotalSample)); Assert.IsNotNull(ret, "Shouldn't be null"); } catch (Exception e) { Tizen.Log.Error(tag, "Caught Exception" + e.ToString()); Assert.Fail("Caught Exception" + e.ToString()); } tlog.Debug(tag, $"XamlResourceIdAttributeGetPathForType END"); }
public void XamlResourceIdAttributeGetPathForType() { tlog.Debug(tag, $"XamlResourceIdAttributeGetPathForType START"); try { XamlResourceIdAttribute.GetPathForType(typeof(string)); } catch (Exception e) { Tizen.Log.Error(tag, "Caught Exception" + e.ToString()); Assert.Fail("Caught Exception" + e.ToString()); } tlog.Debug(tag, $"XamlResourceIdAttributeGetPathForType END (OK)"); Assert.Pass("XamlResourceIdAttributeGetPathForType"); }
object IExtendedTypeConverter.ConvertFromInvariantString(string value, IServiceProvider serviceProvider) { if (serviceProvider == null) { throw new ArgumentNullException(nameof(serviceProvider)); } if (!((serviceProvider.GetService(typeof(Xaml.IProvideValueTarget)) as Xaml.IProvideValueTarget)?.TargetObject is ResourceDictionary targetRD)) { return(null); } var rootObjectType = (serviceProvider.GetService(typeof(Xaml.IRootObjectProvider)) as Xaml.IRootObjectProvider)?.RootObject.GetType(); if (rootObjectType == null) { return(null); } var lineInfo = (serviceProvider.GetService(typeof(Xaml.IXmlLineInfoProvider)) as Xaml.IXmlLineInfoProvider)?.XmlLineInfo; var rootTargetPath = XamlResourceIdAttribute.GetPathForType(rootObjectType); var assembly = rootObjectType.GetTypeInfo().Assembly; #if !NETSTANDARD1_0 if (value.Contains(";assembly=")) { var parts = value.Split(new[] { ";assembly=" }, StringSplitOptions.RemoveEmptyEntries); value = parts[0]; var asmName = parts[1]; assembly = Assembly.Load(asmName); } #endif var uri = new Uri(value, UriKind.Relative); //we don't want file:// uris, even if they start with '/' var resourcePath = GetResourcePath(uri, rootTargetPath); //Re-add the assembly= in all cases, so HotReload doesn't have to make assumptions uri = new Uri($"{value};assembly={assembly.GetName().Name}", UriKind.Relative); targetRD.SetAndLoadSource(uri, resourcePath, assembly, lineInfo); return(uri); }