/// <summary>
 /// Returns true if the given transform can be converted into a string
 /// </summary>
 public override bool CanConvertToString(object value, IValueSerializerContext context)
 {
     ImageSource imageSource = value as ImageSource;
     #pragma warning disable 6506
     return imageSource != null && imageSource.CanSerializeToString();
     #pragma warning restore 6506
 }
예제 #2
0
 /// <summary>
 /// Converts a font family to a string.
 /// </summary>
 public override string ConvertToString(object value, IValueSerializerContext context)
 {
     FontFamily fontFamily = value as FontFamily;
     if (fontFamily == null || fontFamily.Source == null)
         throw GetConvertToException(value, typeof(string));
     return fontFamily.Source;
 }
 /// <summary>
 /// Determines whether the specified object can be converted into a <see cref="String"/>.
 /// </summary>
 /// <param name="value">The object to evaluate for conversion.</param>
 /// <param name="context">Context information that is used for conversion.</param>
 /// <returns>
 /// <see langword="true"/> if the <paramref name="value"/> can be converted into a 
 /// <see cref="String"/>; otherwise, <see langword="false"/>.
 /// </returns>
 public override bool CanConvertToString(object value, IValueSerializerContext context)
 {
     var gesture = value as MultiKeyGesture;
     return gesture != null
            && ModifierKeysConverter.IsDefinedModifierKeys(gesture.Modifiers)
            && MultiKeyGestureConverter.IsDefinedKey(gesture.Key);
 }
예제 #4
0
		public override bool CanConvertToString (object value, IValueSerializerContext context)
		{
			if (!(value is DateTime))
				throw new ArgumentException ("Can only convert objects of type 'DateTime'");

			return true;
		}
 /// <summary>
 /// CanConvertToString()
 /// </summary>
 /// <param name="value"></param>
 /// <param name="context"></param>
 /// <returns></returns>
 /// <ExternalAPI/> 
 public override bool CanConvertToString(object value, IValueSerializerContext context) 
 {
     if (!(value is Key))
         return false;
     Key key = (Key)value;
     return ((int)key >= (int)Key.None && (int)key <= (int)Key.OemClear);
 }
		public XamlObjectNodeIterator (object root, XamlSchemaContext schemaContext, IValueSerializerContext vctx, XamlObjectReaderSettings settings)
		{
			ctx = schemaContext;
			this.root = root;
			value_serializer_ctx = vctx;
			this.settings = settings;
		}
		public override object ConvertFromString (string value, IValueSerializerContext context)
		{
			if (value == null)
				throw new NotSupportedException ();
			if (value.Length == 0)
				return DateTime.MinValue;
			return DateTime.Parse (value, CultureInfo.InvariantCulture, styles);
		}
 /// <summary>
 /// Converts a transform into a string.
 /// </summary>
 public override string ConvertToString(object value, IValueSerializerContext context)
 {
     ImageSource imageSource = value as ImageSource;
     if (imageSource != null)
         return imageSource.ConvertToString(null,  System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS);
     else
         return base.ConvertToString(value, context);
 }
 /// <summary>
 /// ConvertFromString()
 /// </summary>
 /// <param name="value"></param>
 /// <param name="context"></param>
 /// <returns></returns>
 public override object ConvertFromString(string value, IValueSerializerContext context) 
 {
     TypeConverter converter = TypeDescriptor.GetConverter(typeof(MouseAction));
     if (converter != null)
         return converter.ConvertFromString(value);
     else
         return base.ConvertFromString(value, context);
 }
 public override bool CanConvertToString(object value, IValueSerializerContext context)
 {
     if (AttachablePropertyServices.GetAttachedPropertyCount(value) > 0)
     {
         return false;
     }
     return (((value != null) && (value is IValueSerializableExpression)) && ((IValueSerializableExpression) value).CanConvertToString(context));
 }
 internal static string ConvertToStringWrapper(object value, IValueSerializerContext context)
 {
     if (valueSerializer == null)
     {
         valueSerializer = new ActivityWithResultValueSerializer();
     }
     return valueSerializer.ConvertToString(value, context);
 }
예제 #12
0
 /// <summary>
 /// Creates a FontFamily from a string
 /// </summary>
 public override object ConvertFromString(string value, IValueSerializerContext context)
 {
     if (string.IsNullOrEmpty(value))
     {
         throw GetConvertFromException(value);
     }
     return new FontFamily(value);
 }
        /// <summary>
        /// Converts a <see cref="String"/> to an instance of the type that the implementation of
        /// <see cref="ValueSerializer"/> supports.
        /// </summary>
        /// <param name="value">The string to convert.</param>
        /// <param name="context">Context information that is used for conversion.</param>
        /// <returns>
        /// A new instance of the type that the implementation of <see cref="ValueSerializer"/>
        /// supports based on the supplied <paramref name="value"/>.
        /// </returns>
        /// <exception cref="NotSupportedException">
        /// <paramref name="value"/> cannot be converted.
        /// </exception>
        public override object ConvertFromString(string value, IValueSerializerContext context)
        {
            var converter = TypeDescriptor.GetConverter(typeof(KeyGesture));
            if (converter != null)
                return converter.ConvertFromString(value);

            return base.ConvertFromString(value, context);
        }
 /// <summary>
 /// ConvertToString()
 /// </summary>
 /// <param name="value"></param>
 /// <param name="context"></param>
 /// <returns></returns>
 public override string ConvertToString(object value, IValueSerializerContext context) 
 {
     TypeConverter converter = TypeDescriptor.GetConverter(typeof(Key));
     if (converter != null)
         return converter.ConvertToInvariantString(value);
     else
         return base.ConvertToString(value, context);
 }
예제 #15
0
		public override object ConvertFromString(string value, IValueSerializerContext context)
		{
			if (value != null)
			{
				return DataRect.Parse(value);
			}
			return base.ConvertFromString(value, context);
		}
 public override string ConvertToString(object value, IValueSerializerContext context)
 {
     VisualBasicSettings settings = value as VisualBasicSettings;
     if ((settings != null) && settings.SuppressXamlSerialization)
     {
         return "Assembly references and imported namespaces for internal implementation";
     }
     return "Assembly references and imported namespaces serialized as XML namespaces";
 }
 public static ValueSerializer GetSerializerFor(Type type, IValueSerializerContext context)
 {
     ValueSerializer s = context.GetValueSerializerFor (type);
     if (s == null) {
         DefaultValueSerializerContext defaultContext = new DefaultValueSerializerContext();
         s = defaultContext.GetValueSerializerFor (type);
     }
     return s;
 }
 public override string ConvertToString(object value, IValueSerializerContext context)
 {
     Argument argument = value as Argument;
     if (argument == null)
     {
         throw FxTrace.Exception.Argument("value", System.Activities.SR.CannotSerializeExpression(value.GetType()));
     }
     return argument.ConvertToString(context);
 }
 public static ValueSerializer GetSerializerFor(PropertyDescriptor descriptor, IValueSerializerContext context)
 {
     ValueSerializer s = context.GetValueSerializerFor (descriptor);
     if (s == null) {
         DefaultValueSerializerContext defaultContext = new DefaultValueSerializerContext();
         s = defaultContext.GetValueSerializerFor (descriptor);
     }
     return s;
 }
		void SetupReaderService ()
		{
			Context = null;
			var obj = new TestValueSerialized ();
			var xr = new XamlObjectReader (obj);
			while (!xr.IsEof && Context == null)
				xr.Read ();
			Assert.IsNotNull (Context, "SetupReader #1");
		}
 public override bool CanConvertToString(object value, IValueSerializerContext context)
 {
     Argument argument = value as Argument;
     if (argument == null)
     {
         return false;
     }
     return argument.CanConvertToString(context);
 }
 public override string ConvertToString(object value, IValueSerializerContext context)
 {
     IValueSerializableExpression expression = value as IValueSerializableExpression;
     if (expression == null)
     {
         throw FxTrace.Exception.AsError(new InvalidOperationException(System.Activities.SR.CannotSerializeExpression(value.GetType())));
     }
     return expression.ConvertToString(context);
 }
예제 #23
0
        /// <summary>
        /// Returns true if the FontFamily is a named font family.
        /// </summary>
        public override bool CanConvertToString(object value, IValueSerializerContext context)
        {
            FontFamily fontFamily = value as FontFamily;

            // Suppress PRESharp warning that fontFamily can be null; apparently PRESharp
            // doesn't understand short circuit evaluation of operator &&.
#pragma warning suppress 56506
            return fontFamily != null && fontFamily.Source != null && fontFamily.Source.Length != 0;           
        }
예제 #24
0
		public override string ConvertToString(object value, IValueSerializerContext context)
		{
			if (value is DataRect)
			{
				DataRect rect = (DataRect)value;
				return rect.ConvertToString(null, CultureInfo.GetCultureInfo("en-us"));
			}
			return base.ConvertToString(value, context);
		}
 public override bool CanConvertToString(object value, IValueSerializerContext context)
 {
     VisualBasicSettings settings = value as VisualBasicSettings;
     if (settings != null)
     {
         settings.GenerateXamlReferences(context);
     }
     return true;
 }
        /// <summary>
        /// CanConvertToString() 
        /// </summary>
        /// <param name="value"></param>
        /// <param name="context"></param>
        /// <returns></returns> 
        /// <ExternalAPI/>
        public override bool CanConvertToString(object value, IValueSerializerContext context) 
        { 
            KeyGesture keyGesture = value as KeyGesture;
 
            #pragma warning disable 6506
            return (keyGesture != null)
                && ModifierKeysConverter.IsDefinedModifierKeys(keyGesture.Modifiers)
                && KeyGestureConverter.IsDefinedKey(keyGesture.Key); 
            #pragma warning restore 6506
        } 
        public override string ConvertToString(object value, IValueSerializerContext context)
        {
            VisualBasicSettings settings = value as VisualBasicSettings;

            if (settings != null && settings.SuppressXamlSerialization)
            {
                return ImplementationVisualBasicSettingsValue;
            }
            return VisualBasicSettingsValue;
        }
예제 #28
0
		public override string ConvertToString (object value, IValueSerializerContext context)
		{
			if (value == null)
				throw new NotSupportedException ("Cannot convert null value to string.");

			if (!(value is DateTime))
				throw new NotSupportedException ("only objects of type 'DateTime' can be converted.");

			return ((DateTime)value).ToString("s", CultureInfo.InvariantCulture);
		}
        public override string ConvertToString(object value, IValueSerializerContext context)
        {
            Argument argument = value as Argument;
            if (argument == null)
            {
                // expect CanConvertToString() always comes before ConvertToString()
                throw FxTrace.Exception.Argument("value", SR.CannotSerializeExpression(value.GetType()));                   
            }

            return argument.ConvertToString(context);
        }
        public override string ConvertToString(object value, IValueSerializerContext context)
        {
            IValueSerializableExpression ivsExpr;

            ivsExpr = value as IValueSerializableExpression;
            if (ivsExpr == null)
            {
                throw FxTrace.Exception.AsError(new InvalidOperationException(SR.CannotSerializeExpression(value.GetType())));
            }
            return ivsExpr.ConvertToString(context);
        }
예제 #31
0
 public override bool CanConvertFromString(string value, IValueSerializerContext context) => Converter.CanConvertFrom(typeof(string));
예제 #32
0
 public override bool CanConvertToString(object value, IValueSerializerContext context) => Converter.CanConvertTo(typeof(string));
예제 #33
0
파일: Font.cs 프로젝트: ivan95603/xwt
 public override bool CanConvertToString(object value, IValueSerializerContext context)
 {
     return(true);
 }
예제 #34
0
 public override object ConvertFromString(string value, IValueSerializerContext context) => double.TryParse(value, out var result) ? result : 0;
예제 #35
0
 public override string ConvertToString(object value, IValueSerializerContext context) => ((double)value).ToString(CultureInfo.InvariantCulture);
예제 #36
0
 public override object ConvertFromString(string value, IValueSerializerContext context) => TypeHelper.ParseType(value);
예제 #37
0
 public override IEnumerable <Type> TypeReferences(object value, IValueSerializerContext context)
 {
     yield break;
 }
예제 #38
0
 public override string ConvertToString(object value, IValueSerializerContext context) => Converter.ConvertToInvariantString(value);
예제 #39
0
 public override bool CanConvertFromString(string value, IValueSerializerContext context) => true;
예제 #40
0
 public override object ConvertFromString(string value, IValueSerializerContext context) => null;
 public override string ConvertToString(object value, IValueSerializerContext context)
 {
     throw new NotImplementedException();
 }
예제 #42
0
 public override object ConvertFromString(string value, IValueSerializerContext context)
 {
     return(value);
 }
예제 #43
0
 public override string ConvertToString(object value, IValueSerializerContext context) => value.ToString();
예제 #44
0
 public override object ConvertFromString(string value, IValueSerializerContext context) => CultureInfo.GetCultureInfo(value);
예제 #45
0
 public override object ConvertFromString(string value, IValueSerializerContext context) => Enum.TryParse <T>(value, out var result) ? result : default(T);
예제 #46
0
 public override object ConvertFromString(string value, IValueSerializerContext context)
 {
     return(TimeSpan.TryParse(value, out var timeSpan) ? timeSpan : TimeSpan.MaxValue);
 }
예제 #47
0
 public override string ConvertToString(object value, IValueSerializerContext context)
 {
     return(((TimeSpan)value).ToString());
 }
예제 #48
0
 public override object ConvertFromString(string value, IValueSerializerContext context)
 {
     return(DateTime.FromBinary(long.Parse(value)));
 }
예제 #49
0
 public override string ConvertToString(object value, IValueSerializerContext context) => ((CultureInfo)value).Name;
예제 #50
0
 public override string ConvertToString(object value, IValueSerializerContext context) => TypeHelper.FormatBinary((Type)value);
        // Return the type named by the given name
        Type GetTypeFromName(string name, object context)
        {
            // use the parser context, if available.  This allows early resolution.
            // bchapman 5/8/2009 - I believe with System.Xaml there is never an old parserContext here.
            // But cannot be sure.
            ParserContext parserContext = context as ParserContext;

            if (parserContext != null)
            {
                // Find the namespace prefix
                string nsPrefix;
                int    nsIndex = name.IndexOf(':');
                if (nsIndex == -1)
                {
                    nsPrefix = string.Empty;
                }
                else
                {
                    // Found a namespace prefix separator, so create replacement _pathString.
                    // String processing - split "foons" from "BarClass.BazProp"
                    nsPrefix = name.Substring(0, nsIndex).TrimEnd();
                    name     = name.Substring(nsIndex + 1).TrimStart();
                }

                // Find the namespace URI, even if its the default one
                string namespaceURI = parserContext.XmlnsDictionary[nsPrefix];
                if (namespaceURI == null)
                {
                    throw new ArgumentException(SR.Get(SRID.ParserPrefixNSProperty, nsPrefix, name));
                }

                TypeAndSerializer typeAndSerializer = parserContext.XamlTypeMapper.GetTypeOnly(namespaceURI, name);

                return((typeAndSerializer != null) ? typeAndSerializer.ObjectType : null);
            }

            else
            {
                if (context is IServiceProvider)
                {
                    IXamlTypeResolver xtr = (context as IServiceProvider).GetService(typeof(IXamlTypeResolver)) as IXamlTypeResolver;

                    if (xtr != null)
                    {
                        return(xtr.Resolve(name));
                    }
                }

                IValueSerializerContext serializerContext = context as IValueSerializerContext;
                if (serializerContext != null)
                {
                    ValueSerializer typeSerializer = ValueSerializer.GetSerializerFor(typeof(Type), serializerContext);
                    if (typeSerializer != null)
                    {
                        return(typeSerializer.ConvertFromString(name, serializerContext) as Type);
                    }
                }
            }

            // if there's no parser or serializer context, use the tree context
            DependencyObject hostElement = context as DependencyObject;

            if (hostElement == null)
            {
                if (FrameworkCompatibilityPreferences.TargetsDesktop_V4_0)
                {
                    // WPF "OneTime" Data binding can work inconsistently when running
                    // a .NET 4 application on .NET 4.5 compared to running it on .NET 4
                    // app targets 4.0, so return null, for compat
                    return(null);
                }
                else
                {
                    hostElement = new DependencyObject();   // at least pick up the default namespaces
                }
            }

            var  wpfSharedSchemaContext = XamlReader.BamlSharedSchemaContext;
            Type type = wpfSharedSchemaContext.ResolvePrefixedNameWithAdditionalWpfSemantics(name, hostElement);

            return(type);
        }
예제 #52
0
파일: Font.cs 프로젝트: ivan95603/xwt
 public override bool CanConvertFromString(string value, IValueSerializerContext context)
 {
     return(true);
 }
예제 #53
0
 public bool CanConvertToString(IValueSerializerContext context)
 {
     return(true);
 }
예제 #54
0
 public override string ConvertToString(object value, IValueSerializerContext context)
 {
     return(((DateTime)value).ToBinary().ToString());
 }
 public override bool CanConvertFromString(string value, IValueSerializerContext context)
 {
     // seems to return for any value
     return(true);
 }
예제 #56
0
 public override object ConvertFromString(string value, IValueSerializerContext context) => Converter.ConvertFromInvariantString(value);
 public override object ConvertFromString(string value, IValueSerializerContext context)
 {
     throw new NotImplementedException();
 }
예제 #58
0
 public override string ConvertToString(object value, IValueSerializerContext context)
 {
     return((string)value);
 }