Exemplo n.º 1
0
 void ReportException(Exception x, XmlNode node)
 {
     if (errorSink != null)
     {
         var lineInfo = node as IXmlLineInfo;
         var msg      = x.Message;
         if (x.InnerException != null)
         {
             msg += " (" + x.InnerException.Message + ")";
         }
         if (lineInfo != null)
         {
             errorSink.ReportError(msg, lineInfo.LineNumber, lineInfo.LinePosition);
         }
         else
         {
             errorSink.ReportError(msg, 0, 0);
         }
         if (currentXamlObject != null)
         {
             currentXamlObject.HasErrors = true;
         }
     }
     else
     {
         throw x;
     }
 }
Exemplo n.º 2
0
 void ReportException(Exception x, XmlNode node)
 {
     if (errorSink != null)
     {
         var lineInfo = node as IXmlLineInfo;
         var msg      = x.Message;
         var inner    = x.InnerException;
         while (inner != null)
         {
             msg  += Environment.NewLine + "\t(" + inner.Message + ")";
             inner = inner.InnerException;
         }
         if (lineInfo != null)
         {
             errorSink.ReportError(msg, lineInfo.LineNumber, lineInfo.LinePosition);
         }
         else
         {
             errorSink.ReportError(msg, 0, 0);
         }
         if (currentXamlObject != null)
         {
             currentXamlObject.HasErrors = true;
         }
     }
     else
     {
         throw x;
     }
 }
Exemplo n.º 3
0
        internal static object CreateObjectFromAttributeText(string valueText, XamlPropertyInfo targetProperty, XamlObject scope)
        {
            try
            {
                if (targetProperty.ReturnType == typeof(Uri))
                {
                    return(scope.OwnerDocument.TypeFinder.ConvertUriToLocalUri(new Uri(valueText, UriKind.RelativeOrAbsolute)));
                }
                else if (targetProperty.ReturnType == typeof(ImageSource))
                {
                    var uri =
                        scope.OwnerDocument.TypeFinder.ConvertUriToLocalUri(new Uri(valueText, UriKind.RelativeOrAbsolute));
                    return(targetProperty.TypeConverter.ConvertFromString(
                               scope.OwnerDocument.GetTypeDescriptorContext(scope), CultureInfo.InvariantCulture, uri.ToString()));
                }
                if (targetProperty.ReturnType == typeof(Brush))
                {
                    return(new BrushConverter().ConvertFromString(valueText) as SolidColorBrush);
                }

                return(targetProperty.TypeConverter.ConvertFromString(
                           scope.OwnerDocument.GetTypeDescriptorContext(scope),
                           CultureInfo.InvariantCulture, valueText));
            }
            catch (Exception e) {
                IXamlErrorSink sink = (IXamlErrorSink)scope.OwnerDocument.ServiceProvider.GetService(typeof(IXamlErrorSink));
                if (sink != null)
                {
                    sink.ReportError(e.Message + " in property: " + targetProperty.FullyQualifiedName, 0, 0);
                }
            }
            return(null);
        }
Exemplo n.º 4
0
 void ReportException(Exception x, XmlNode node)
 {
     if (errorSink != null)
     {
         var lineInfo = node as IXmlLineInfo;
         if (lineInfo != null)
         {
             errorSink.ReportError(x.Message, lineInfo.LineNumber, lineInfo.LinePosition);
         }
         else
         {
             errorSink.ReportError(x.Message, 0, 0);
         }
         if (currentXamlObject != null)
         {
             currentXamlObject.HasErrors = true;
         }
     }
     else
     {
         throw x;
     }
 }
Exemplo n.º 5
0
        internal static object CreateObjectFromAttributeText(string valueText, Type targetType, XamlObject scope)
        {
            try {
                var converter =
                    XamlNormalPropertyInfo.GetCustomTypeConverter(targetType) ??
                    TypeDescriptor.GetConverter(targetType);

                return(converter.ConvertFromInvariantString(
                           scope.OwnerDocument.GetTypeDescriptorContext(scope), valueText));
            }
            catch (Exception e) {
                IXamlErrorSink sink = (IXamlErrorSink)scope.OwnerDocument.ServiceProvider.GetService(typeof(IXamlErrorSink));
                if (sink != null)
                {
                    sink.ReportError(e.Message, 0, 0);
                }
            }
            return(null);
        }