public override object ConvertFromString(string value, IValueSerializerContext context)
        {
            if (context == null)
            {
                return(base.ConvertFromString(value, context));
            }
            var nsr = (IXamlNamespaceResolver)context.GetService(typeof(IXamlNamespaceResolver));
            var scp = (IXamlSchemaContextProvider)context.GetService(typeof(IXamlSchemaContextProvider));

            return(scp.SchemaContext.GetXamlType(XamlTypeName.Parse(value, nsr)).UnderlyingType);
        }
 public object GetService(Type serviceType)
 {
     if (_baseContext != null)
     {
         return(_baseContext.GetService(serviceType));
     }
     else
     {
         return(null);
     }
 }
        void LookupType(Type type)
        {
            var xamlType = SchemaContext.GetXamlType(type);

            prefixLookup = prefixLookup ?? value_serializer_ctx?.GetService(typeof(INamespacePrefixLookup)) as INamespacePrefixLookup;
            if (prefixLookup == null)
            {
                return;
            }
            prefixLookup.LookupPrefix(xamlType.PreferredXamlNamespace);
            if (xamlType.TypeArguments != null)
            {
                for (int i = 0; i < xamlType.TypeArguments.Count; i++)
                {
                    prefixLookup.LookupPrefix(xamlType.TypeArguments[i].PreferredXamlNamespace);
                }
            }
        }
        public static string GetStringValue(XamlType xt, XamlMember xm, object obj, IValueSerializerContext vsctx)
        {
            if (obj == null)
            {
                return(String.Empty);
            }
            if (obj is Type)
            {
                return(new XamlTypeName(xt.SchemaContext.GetXamlType((Type)obj)).ToString(vsctx?.GetService(typeof(INamespacePrefixLookup)) as INamespacePrefixLookup));
            }

            var vs = xm?.ValueSerializer ?? xt.ValueSerializer;

            if (vs != null)
            {
                return(vs.ConverterInstance.ConvertToString(obj, vsctx));
            }

            // FIXME: does this make sense?
            var vc = xm?.TypeConverter ?? xt.TypeConverter;
            var tc = vc?.ConverterInstance;

            if (tc != null && tc.CanConvertTo((ITypeDescriptorContext)vsctx, typeof(string)))
            {
                return((string)tc.ConvertTo((ITypeDescriptorContext)vsctx, CultureInfo.InvariantCulture, obj, typeof(string)));
            }
            if (obj is string || obj == null)
            {
                return((string)obj);
            }
            throw new InvalidCastException(String.Format("Cannot cast object '{0}' to string", obj.GetType()));
        }
		public override object ConvertFromString (string value, IValueSerializerContext context)
		{
			if (context == null)
				return base.ConvertFromString (value, context);
			var nsr = (IXamlNamespaceResolver) context.GetService (typeof (IXamlNamespaceResolver));
			var scp = (IXamlSchemaContextProvider) context.GetService (typeof (IXamlSchemaContextProvider));
			return scp.SchemaContext.GetXamlType (XamlTypeName.Parse (value, nsr)).UnderlyingType;
		}