public XamlObjectNodeIterator (object root, XamlSchemaContext schemaContext, IValueSerializerContext vctx, XamlObjectReaderSettings settings)
		{
			ctx = schemaContext;
			this.root = root;
			value_serializer_ctx = vctx;
			this.settings = settings;
		}
		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, this, this);
		}
 public XamlParserContext (XamlSchemaContext schemaContext, Assembly localAssembly)
     : base(schemaContext)
 {
     this._stack = new XamlContextStack<XamlParserFrame>(() => new XamlParserFrame());
     this._prescopeNamespaces = new Dictionary<string, string>();
     base._localAssembly = localAssembly;
 }
		public ParsedMarkupExtensionInfo(ParsedMarkupExtensionInfo info)
		{
			this.value = info.value;
			this.index = info.index;
			this.nsResolver = info.nsResolver;
			this.sctx = info.sctx;
		}
		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);

			// See also Instance property for this weirdness.
			this.root_raw = instance;
			instance = TypeExtensionMethods.GetExtensionWrapped (instance);
			this.root = instance;

			sctx = schemaContext;
			this.settings = settings ?? new XamlObjectReaderSettings();

			// 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).GetRawValue ().GetType ();
				if (!type.GetTypeInfo().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 ().Count == 0 && xt.TypeConverter == null)
					throw new XamlObjectReaderException (String.Format ("instance type '{0}' has no default constructor.", type));
			}

			value_serializer_context = new ValueSerializerContext (new PrefixLookup (sctx), sctx, null, null, null, null);
			new XamlObjectNodeIterator (instance, sctx, value_serializer_context, this.settings).PrepareReading ();
		}
		public XamlNodeQueue (XamlSchemaContext schemaContext)
		{
			if (schemaContext == null)
				throw new ArgumentNullException ("schemaContext");
			this.ctx = schemaContext;
			reader = new XamlNodeQueueReader (this);
			writer = new XamlNodeQueueWriter (this);
		}
Exemple #7
0
		public XamlNodeList(XamlSchemaContext schemaContext, int size)
		{
			if (schemaContext == null)
				throw new ArgumentNullException("schemaContext");
			Writer = new XamlNodeListWriter(this);
			SchemaContext = schemaContext;
			nodes = new List<XamlNodeInfo>(size);
		}
		public ParsedMarkupExtensionInfo(string value, IXamlNamespaceResolver nsResolver, XamlSchemaContext sctx)
		{
			if (value == null)
				throw new ArgumentNullException ("value");
			this.value = value;
			this.nsResolver = nsResolver;
			this.sctx = sctx;
		}
		public XamlObjectWriter (XamlSchemaContext schemaContext, XamlObjectWriterSettings settings)
		{
			if (schemaContext == null)
				throw new ArgumentNullException ("schemaContext");
			this.sctx = schemaContext;
			this.settings = settings ?? new XamlObjectWriterSettings ();
			var manager = new XamlWriterStateManager<XamlObjectWriterException, XamlObjectWriterException> (false);
			intl = new XamlObjectWriterInternal (this, sctx, manager);
		}
		public ValueSerializerContext (PrefixLookup prefixLookup, XamlSchemaContext schemaContext, IAmbientProvider ambientProvider, IProvideValueTarget provideValue, IRootObjectProvider rootProvider)
		{
			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;
			ambient_provider = ambientProvider;
			this.provideValue = provideValue;
			this.rootProvider = rootProvider;
		}
		public static ParsedMarkupExtensionInfo Parse (string raw, IXamlNamespaceResolver nsResolver, XamlSchemaContext sctx)
		{
			if (raw == null)
				throw new ArgumentNullException ("raw");
			if (raw.Length == 0 || raw [0] != '{')
				throw Error ("Invalid markup extension attribute. It should begin with '{{', but was {0}", raw);
			var ret = new ParsedMarkupExtensionInfo ();
			int idx = raw.IndexOf ('}');
			if (idx < 0)
				throw Error ("Expected '}}' in the markup extension attribute: '{0}'", raw);
			raw = raw.Substring (1, idx - 1);
			idx = raw.IndexOf (' ');
			string name = idx < 0 ? raw : raw.Substring (0, idx);

			XamlTypeName xtn;
			if (!XamlTypeName.TryParse (name, nsResolver, out xtn))
				throw Error ("Failed to parse type name '{0}'", name);
			var xt = sctx.GetXamlType (xtn);
			ret.Type = xt;

			if (idx < 0)
				return ret;

			string [] vpairs = raw.Substring (idx + 1, raw.Length - idx - 1).Split (',');
			List<string> posPrms = null;
			foreach (string vpair in vpairs) {
				idx = vpair.IndexOf ('=');
				// FIXME: unescape string (e.g. comma)
				if (idx < 0) {
					if (posPrms == null) {
						posPrms = new List<string> ();
						ret.Arguments.Add (XamlLanguage.PositionalParameters, posPrms);
					}
					posPrms.Add (UnescapeValue (vpair.Trim ()));
				} else {
					var key = vpair.Substring (0, idx).Trim ();
					// FIXME: is unknown member always isAttacheable = false?
					var xm = xt.GetMember (key) ?? new XamlMember (key, xt, false);
					ret.Arguments.Add (xm, UnescapeValue (vpair.Substring (idx + 1).Trim ()));
				}
			}
			return ret;
		}
		public XamlXmlParser (XmlReader xmlReader, XamlSchemaContext schemaContext, XamlXmlReaderSettings settings)
		{
			if (xmlReader == null)
				throw new ArgumentNullException ("xmlReader");
			if (schemaContext == null)
				throw new ArgumentNullException ("schemaContext");

			sctx = schemaContext;
			this.settings = settings ?? new XamlXmlReaderSettings ();

			// filter out some nodes.
			var xrs = new XmlReaderSettings () {
				CloseInput = this.settings.CloseInput,
				IgnoreComments = true,
				IgnoreProcessingInstructions = true,
				IgnoreWhitespace = true };

			r = XmlReader.Create (xmlReader, xrs);
			line_info = r as IXmlLineInfo;
			xaml_namespace_resolver = new NamespaceResolver (r as IXmlNamespaceResolver);
		}
		public XamlXmlReader (TextReader textReader, XamlSchemaContext schemaContext, XamlXmlReaderSettings settings)
			: this (XmlReader.Create (textReader), schemaContext, settings)
		{
		}
		public XamlXmlReader (XmlReader xmlReader, XamlSchemaContext schemaContext, XamlXmlReaderSettings settings)
		{
			parser = new XamlXmlParser (xmlReader, schemaContext, settings);
		}
		public XamlXmlReader (string fileName, XamlSchemaContext schemaContext, XamlXmlReaderSettings settings)
		{
			throw new NotSupportedException ("Cannot load directly from a file with this profile");
		}
		public XamlXmlReader (string fileName, XamlSchemaContext schemaContext, XamlXmlReaderSettings settings)
			: this (XmlReader.Create (fileName, file_reader_settings), schemaContext, settings)
		{
		}
		public XamlTypeResolver (NamespaceResolver namespaceResolver, XamlSchemaContext schemaContext)
		{
			ns_resolver = namespaceResolver;
			schema_context = schemaContext;
		}
Exemple #18
0
 protected XamlContext (XamlSchemaContext schemaContext)
 {
     this._schemaContext = schemaContext;
 }
			public DeferredWriter(XamlSchemaContext context, XamlDeferringLoader loader)
			{
				List = new XamlNodeList(context);
				Loader = loader;
			}
		public XamlObjectWriterInternal (XamlObjectWriter source, XamlSchemaContext schemaContext, XamlWriterStateManager manager)
			: base (schemaContext, manager)
		{
			this.source = source;
			this.sctx = schemaContext;
			var ext = source.Settings.ExternalNameScope;
			name_scope = ext != null && source.Settings.RegisterNamesOnExternalNamescope ? ext : new NameScope (ext);
		}
Exemple #21
0
 public EmptyXamlMember(EventInfo eventInfo, XamlSchemaContext context)
     : base(eventInfo, context)
 {
 }
		public XamlXmlReader (string fileName, XamlSchemaContext schemaContext)
			: this (fileName, schemaContext, null)
		{
		}
		public XamlXmlReader (XmlReader xmlReader, XamlSchemaContext schemaContext)
			: this (xmlReader, schemaContext, null)
		{
		}
		public XamlObjectReader (object instance, XamlSchemaContext schemaContext)
			: this (instance, schemaContext, null)
		{
		}
		public XamlNodeList (XamlSchemaContext schemaContext, int size)
		{
			throw new NotImplementedException ();
		}
		void ProcessAttributesToMember (XamlSchemaContext sctx, StartTagInfo sti, XamlType xt)
		{
			foreach (var p in sti.Attributes) {
				int idx = p.Key.IndexOf (':');
				string prefix = idx > 0 ? p.Key.Substring (0, idx) : String.Empty;
				string aname = idx > 0 ? p.Key.Substring (idx + 1) : p.Key;
				idx = aname.IndexOf ('.');
				if (idx > 0) {
					string apns = prefix.Length > 0 ? r.LookupNamespace (prefix) : r.NamespaceURI;
					var apname = aname.Substring (0, idx);
					var axtn = new XamlTypeName (apns, apname, null);
					var at = sctx.GetXamlType (axtn);
					var am = at.GetAttachableMember (aname.Substring (idx + 1));
					if (am != null)
						sti.Members.Add (new Pair (am, p.Value));
					// ignore unknown attribute
				}
				var xm = xt.GetMember (aname);
				if (xm != null)
					sti.Members.Add (new Pair (xm, p.Value));
				// ignore unknown attribute
			}
		}
		public XamlObjectWriter (XamlSchemaContext schemaContext)
			: this (schemaContext, null)
		{
		}
		public XamlXmlReader (Stream stream, XamlSchemaContext schemaContext)
			: this (stream, schemaContext, null)
		{
		}
		public XamlObjectNodeIterator (object root, XamlSchemaContext schemaContext, IValueSerializerContext vctx)
		{
			ctx = schemaContext;
			this.root = root;
			value_serializer_ctx = vctx;
		}
		public XamlXmlReader (TextReader textReader, XamlSchemaContext schemaContext)
			: this (textReader, schemaContext, null)
		{
		}
Exemple #31
0
 public EtoXamlType(Type underlyingType, XamlSchemaContext schemaContext)
     : base(underlyingType, schemaContext)
 {
 }
		public XamlXmlReader (Stream stream, XamlSchemaContext schemaContext, XamlXmlReaderSettings settings)
			: this (XmlReader.Create (stream), schemaContext, settings)
		{
		}
Exemple #33
0
 internal static XamlMember ReplaceXamlMemberInvoker(this XamlMember originalXamlMember, XamlSchemaContext schemaContext, XamlMemberInvoker newInvoker)
 {
     if (originalXamlMember.IsEvent)
     {
         if (originalXamlMember.IsAttachable)
         {
             UnitTestUtility.Assert(originalXamlMember.UnderlyingMember is MethodInfo, "Guaranteed by XamlMember.");
             return(new XamlMember(originalXamlMember.Name, originalXamlMember.UnderlyingMember as MethodInfo, schemaContext, newInvoker));
         }
         else
         {
             UnitTestUtility.Assert(originalXamlMember.UnderlyingMember is EventInfo, "Guaranteed by XamlMember.");
             return(new XamlMember(originalXamlMember.UnderlyingMember as EventInfo, schemaContext, newInvoker));
         }
     }
     else if (originalXamlMember.IsDirective)
     {
         return(originalXamlMember);
     }
     else if (originalXamlMember.IsUnknown)
     {
         return(originalXamlMember);
     }
     else
     {
         if (originalXamlMember.IsAttachable)
         {
             var attachablePropertyMethod = originalXamlMember.UnderlyingMember as MethodInfo;
             if (attachablePropertyMethod.ReturnType == typeof(void))
             {
                 return(new XamlMember(originalXamlMember.Name, null, originalXamlMember.UnderlyingMember as MethodInfo, schemaContext, newInvoker));
             }
             else
             {
                 return(new XamlMember(originalXamlMember.Name, originalXamlMember.UnderlyingMember as MethodInfo, null, schemaContext, newInvoker));
             }
         }
         else
         {
             var propertyInfo = originalXamlMember.UnderlyingMember as PropertyInfo;
             if (propertyInfo != null)
             {
                 return(new XamlMember(propertyInfo, schemaContext, newInvoker));
             }
             else
             {
                 return(originalXamlMember);
             }
         }
     }
 }