public XamlWriterInternalBase (XamlSchemaContext schemaContext, XamlWriterStateManager manager)
		{
			this.sctx = schemaContext;
			this.manager = manager;
			var p = new PrefixLookup (sctx) { IsCollectingNamespaces = true }; // it does not raise unknown namespace error.
			service_provider = new ValueSerializerContext (p, schemaContext, AmbientProvider);
		}
        public static ValueSerializerContext Create(PrefixLookup prefixLookup, XamlSchemaContext schemaContext, Func <IAmbientProvider> ambientProvider, IProvideValueTarget provideValue, IRootObjectProvider rootProvider, IDestinationTypeProvider destinationProvider, IXamlObjectWriterFactory objectWriterFactory)
        {
            var context = new ValueSerializerContext();

            context.Initialize(prefixLookup, schemaContext, ambientProvider, provideValue, rootProvider, destinationProvider, objectWriterFactory);
            return(context);
        }
 void Initialize(PrefixLookup prefixLookup, XamlSchemaContext schemaContext, Func <IAmbientProvider> ambientProvider, IProvideValueTarget provideValue, IRootObjectProvider rootProvider, IDestinationTypeProvider destinationProvider, IXamlObjectWriterFactory objectWriterFactory)
 {
     prefix_lookup            = prefixLookup ?? throw new ArgumentNullException("prefixLookup");
     sctx                     = schemaContext ?? throw new ArgumentNullException("schemaContext");
     _ambientProviderProvider = ambientProvider;
     this.provideValue        = provideValue;
     this.rootProvider        = rootProvider;
     this.destinationProvider = destinationProvider;
     this.objectWriterFactory = objectWriterFactory;
 }
Exemple #4
0
		public XamlObjectWriter (XamlSchemaContext schemaContext, XamlObjectWriterSettings settings)
		{
			if (schemaContext == null)
				throw new ArgumentNullException ("schemaContext");
			this.sctx = schemaContext;
			this.settings = settings ?? new XamlObjectWriterSettings ();

			var p = new PrefixLookup (sctx);
			service_provider = new ValueSerializerContext (p, sctx);
			namespaces = p.Namespaces;
		}
		public ValueSerializerContext (PrefixLookup prefixLookup, XamlSchemaContext schemaContext)
		{
			if (prefixLookup == null)
				throw new ArgumentNullException ("prefixLookup");
			if (schemaContext == null)
				throw new ArgumentNullException ("schemaContext");
			prefix_lookup = prefixLookup;
			namespace_resolver = new NamespaceResolver (prefix_lookup.Namespaces);
			type_resolver = new XamlTypeResolver (namespace_resolver, schemaContext);
			sctx = schemaContext;
		}
Exemple #6
0
        protected XamlWriterInternalBase(XamlSchemaContext schemaContext, XamlWriterStateManager manager, IAmbientProvider parentAmbientProvider = null)
        {
            this.object_states = new ObjectStateStack(parentAmbientProvider);
            this.sctx          = schemaContext;
            this.manager       = manager;
            var p = new PrefixLookup(sctx)
            {
                IsCollectingNamespaces = true
            };                                                                            // it does not raise unknown namespace error.

            service_provider = ValueSerializerContext.Create(p, schemaContext, object_states.GetAmbientProvider, this, this, this, this as IXamlObjectWriterFactory);
        }
Exemple #7
0
 void LookupNamespacesInType(XamlType xt)
 {
     PrefixLookup.LookupPrefix(xt.PreferredXamlNamespace);
     if (xt.TypeArguments != null)
     {
         // It is for x:TypeArguments
         PrefixLookup.LookupPrefix(XamlLanguage.Xaml2006Namespace);
         foreach (var targ in xt.TypeArguments)
         {
             LookupNamespacesInType(targ);
         }
     }
 }
Exemple #8
0
 public ValueSerializerContext(PrefixLookup prefixLookup, XamlSchemaContext schemaContext)
 {
     if (prefixLookup == null)
     {
         throw new ArgumentNullException("prefixLookup");
     }
     if (schemaContext == null)
     {
         throw new ArgumentNullException("schemaContext");
     }
     prefix_lookup      = prefixLookup;
     namespace_resolver = new NamespaceResolver(prefix_lookup.Namespaces);
     type_resolver      = new XamlTypeResolver(namespace_resolver, schemaContext);
     sctx = schemaContext;
 }
Exemple #9
0
        public static ValueSerializerContext Create(PrefixLookup prefixLookup, XamlSchemaContext schemaContext, Func <IAmbientProvider> ambientProvider, IProvideValueTarget provideValue, IRootObjectProvider rootProvider, IDestinationTypeProvider destinationProvider, IXamlObjectWriterFactory objectWriterFactory)
        {
#if !HAS_TYPE_CONVERTER
            ValueSerializerContext context;
            var type = GetValueSerializerType();
            if (type != null)
            {
                context = Activator.CreateInstance(type) as ValueSerializerContext;
            }
            else
            {
                context = new ValueSerializerContext();
            }
#else
            var context = new ValueSerializerContext();
#endif
            context.Initialize(prefixLookup, schemaContext, ambientProvider, provideValue, rootProvider, destinationProvider, objectWriterFactory);
            return(context);
        }
Exemple #10
0
 // Namespace and Reference retrieval.
 // It is iterated before iterating the actual object nodes,
 // and results are cached for use in XamlObjectReader.
 public void PrepareReading()
 {
     PrefixLookup.IsCollectingNamespaces = true;
     NameResolver.IsCollectingReferences = true;
     foreach (var xn in GetNodes())
     {
         if (xn.NodeType == XamlNodeType.GetObject)
         {
             continue;                     // it is out of consideration here.
         }
         if (xn.NodeType == XamlNodeType.StartObject)
         {
             LookupNamespacesInType(xn.Object.Type);
         }
         else if (xn.NodeType == XamlNodeType.StartMember)
         {
             var xm = xn.Member;
             // This filtering is done as a black list so far. There does not seem to be any usable property on XamlDirective.
             if (ReferenceEquals(xm, XamlLanguage.Items) ||
                 ReferenceEquals(xm, XamlLanguage.PositionalParameters) ||
                 ReferenceEquals(xm, XamlLanguage.Initialization))
             {
                 continue;
             }
             PrefixLookup.LookupPrefix(xn.Member.PreferredXamlNamespace);
         }
         else
         {
             if (xn.NodeType == XamlNodeType.Value && xn.Value is Type)
             {
                 // this tries to lookup existing prefix, and if there isn't any, then adds a new declaration.
                 LookupType((Type)xn.Value);
             }
             //TypeExtensionMethods.GetStringValue (XamlLanguage.Type, xn.Member, xn.Value, value_serializer_ctx);
             continue;
         }
     }
     PrefixLookup.Namespaces.Sort((nd1, nd2) => String.CompareOrdinal(nd1.Prefix, nd2.Prefix));
     PrefixLookup.IsCollectingNamespaces = false;
     NameResolver.IsCollectingReferences = false;
     NameResolver.NameScopeInitializationCompleted(this);
 }
		public XamlObjectNodeIterator (object root, XamlSchemaContext schemaContext, PrefixLookup prefixLookup)
		{
			ctx = schemaContext;
			this.root = root;
			value_serializer_ctx = new ValueSerializerContext (prefixLookup, ctx);
		}
Exemple #12
0
		public XamlObjectReader (object instance, XamlSchemaContext schemaContext, XamlObjectReaderSettings settings)
		{
			if (schemaContext == null)
				throw new ArgumentNullException ("schemaContext");
			// FIXME: special case? or can it be generalized? In .NET, For Type instance Instance returns TypeExtension at root StartObject, while for Array it remains to return Array.
			if (instance is Type)
				instance = new TypeExtension ((Type) instance);

			this.root = instance;
			sctx = schemaContext;
			this.settings = settings;

			prefix_lookup = new PrefixLookup (sctx);

			// check type validity. Note that some checks also needs done at Read() phase. (it is likely FIXME:)
			if (instance != null) {
				var type = new InstanceContext (instance).GetWrappedValue ().GetType ();
				if (!type.IsPublic)
					throw new XamlObjectReaderException (String.Format ("instance type '{0}' must be public and non-nested.", type));
				var xt = SchemaContext.GetXamlType (type);
				if (xt.ConstructionRequiresArguments && !xt.GetConstructorArguments ().Any () && xt.TypeConverter == null)
					throw new XamlObjectReaderException (String.Format ("instance type '{0}' has no default constructor.", type));
			}

			new XamlObjectNodeIterator (instance, sctx, prefix_lookup).CollectNamespaces ();
		}