當前位置: 首頁>>代碼示例>>C#>>正文


C# Xaml.XamlObjectReader類代碼示例

本文整理匯總了C#中System.Xaml.XamlObjectReader的典型用法代碼示例。如果您正苦於以下問題:C# XamlObjectReader類的具體用法?C# XamlObjectReader怎麽用?C# XamlObjectReader使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


XamlObjectReader類屬於System.Xaml命名空間,在下文中一共展示了XamlObjectReader類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: SerializeToXaml

 public static string SerializeToXaml(object objectToSerialize, bool fullyQualifiedClrNamespaces = true)
 {
     var stringWriter = new StringWriter();
     var xamlSchemaContextCWithFullyQualifiedNameSupport =
         new XamlSchemaContext(new XamlSchemaContextSettings { FullyQualifyAssemblyNamesInClrNamespaces = fullyQualifiedClrNamespaces });
     using (var xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings { Indent = true, OmitXmlDeclaration = true }))
     using (var xamlWriter = new XamlXmlWriter(xmlWriter, xamlSchemaContextCWithFullyQualifiedNameSupport))
     using (var builderWriter = ActivityXamlServices.CreateBuilderWriter(xamlWriter)) // transform to x:Class representation
     using (var objectReader = new XamlObjectReader(objectToSerialize, xamlSchemaContextCWithFullyQualifiedNameSupport))
     {
         XamlServices.Transform(objectReader, builderWriter);
         return stringWriter.ToString();
     }
 }
開發者ID:barbarossia,項目名稱:CWF,代碼行數:14,代碼來源:XamlService.cs

示例2: InternalPrepareForUpdate

        private static void InternalPrepareForUpdate(object definitionToBeUpdated, bool forImplementation)
        {
            // Clone the definition
            object clone;
            using (XamlObjectReader reader = new XamlObjectReader(definitionToBeUpdated))
            {
                using (XamlObjectWriter writer = new XamlObjectWriter(reader.SchemaContext))
                {
                    XamlServices.Transform(reader, writer);
                    clone = writer.Result;
                }
            }

            // Calculate the match info
            // Set the match info as attached properties so it is serializable,
            // and available when the user calls CreateUpdateMap

            IDictionary<object, DynamicUpdateMapItem> mapItems;
            if (!forImplementation)
            {
                DynamicUpdateInfo.SetOriginalDefinition(definitionToBeUpdated, (Activity)clone);
                mapItems = DynamicUpdateMap.CalculateMapItems((Activity)definitionToBeUpdated);
            }
            else
            {
                DynamicUpdateInfo.SetOriginalActivityBuilder(definitionToBeUpdated, (ActivityBuilder)clone);
                mapItems = DynamicUpdateMap.CalculateImplementationMapItems(GetDynamicActivity((ActivityBuilder)definitionToBeUpdated));                
            }

            foreach (KeyValuePair<object, DynamicUpdateMapItem> objectInfo in mapItems)
            {
                DynamicUpdateInfo.SetMapItem(objectInfo.Key, objectInfo.Value);
            }
        }
開發者ID:iskiselev,項目名稱:JSIL.NetFramework,代碼行數:34,代碼來源:DynamicUpdateServices.cs

示例3: ReadSubtree3

		public void ReadSubtree3 ()
		{
			var xr = new XamlObjectReader (5);
			xr.Read ();
			xr.Read ();
			var sr = xr.ReadSubtree ();
			Assert.AreEqual (XamlNodeType.None, sr.NodeType, "#1-2");
			Assert.AreEqual (XamlNodeType.StartObject, xr.NodeType, "#1-3");
			Assert.IsTrue (sr.Read (), "#2");
			Assert.AreEqual (XamlNodeType.StartObject, sr.NodeType, "#2-2");
			Assert.AreEqual (XamlNodeType.StartObject, xr.NodeType, "#2-3");
			Assert.IsTrue (sr.Read (), "#3");
			Assert.AreEqual (XamlNodeType.StartMember, sr.NodeType, "#3-2");
			Assert.AreEqual (XamlNodeType.StartMember, xr.NodeType, "#3-3");
			Assert.IsTrue (sr.Read (), "#4");
			Assert.AreEqual (XamlNodeType.Value, sr.NodeType, "#4-2");
			Assert.AreEqual (XamlNodeType.Value, xr.NodeType, "#4-3");
			Assert.IsTrue (sr.Read (), "#5");
			Assert.AreEqual (XamlNodeType.EndMember, sr.NodeType, "#5-2");
			Assert.AreEqual (XamlNodeType.EndMember, xr.NodeType, "#5-3");
			Assert.IsTrue (sr.Read (), "#6");
			Assert.AreEqual (XamlNodeType.EndObject, sr.NodeType, "#6-2");
			Assert.AreEqual (XamlNodeType.EndObject, xr.NodeType, "#6-3");
			Assert.IsFalse (sr.Read (), "#7");
			Assert.AreEqual (XamlNodeType.None, xr.NodeType, "#7-2");
		}
開發者ID:nobled,項目名稱:mono,代碼行數:26,代碼來源:XamlReaderTest.cs

示例4: ReadSubtree1

		public void ReadSubtree1 ()
		{
			var xr = new XamlObjectReader (5);
			var sr = xr.ReadSubtree ();
			Assert.AreEqual (XamlNodeType.None, sr.NodeType, "#1-2");
			Assert.AreEqual (XamlNodeType.None, xr.NodeType, "#1-3");
			Assert.IsTrue (sr.Read (), "#2");
			Assert.AreEqual (XamlNodeType.None, sr.NodeType, "#2-2");
			Assert.AreEqual (XamlNodeType.None, xr.NodeType, "#2-3");
			Assert.IsFalse (sr.Read (), "#3");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, xr.NodeType, "#3-2");
		}
開發者ID:nobled,項目名稱:mono,代碼行數:12,代碼來源:XamlReaderTest.cs

示例5: MainWindow

        public MainWindow()
        {
            InitializeComponent();

            using (var reader = new XamlXmlReader("./Button.xaml"))
            using (var writer = new XamlXmlWriter(new FileStream("./Test.xaml", FileMode.Create), reader.SchemaContext))
            {
                while (reader.Read())
                {
                    writer.WriteNode(reader);
                }
            }

            using (var reader = new XamlObjectReader(new Button()))
            using (var writer = new XamlObjectWriter(reader.SchemaContext))
            {
                while (reader.Read())
                {
                    writer.WriteNode(reader);
                }

                var button = (Button)writer.Result;
            }

            using (var reader = new XamlXmlReader(new StringReader("<Button xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">This is a button</Button>")))
            using (var writer = new XamlObjectWriter(reader.SchemaContext))
            {
                while (reader.Read())
                {
                    writer.WriteNode(reader);
                }

                var button = (Button)writer.Result;
            }

            var button1 = (Button)XamlServices.Load("./Button.xaml");
            var button2 = XamlServices.Load(new XamlObjectReader(new Button()));
            var button3 = XamlServices.Load(new StringReader("<Button xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">This is a button</Button>"));
            var button4 = XamlServices.Parse("<Button xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">This is a button</Button>");
            XamlServices.Save("./Test2.xaml", new Button());

            //DispatcherObject methods, hidden from intellisense via the EditorBrowsableAttribute
            button1.CheckAccess();
            button1.VerifyAccess();
        }
開發者ID:jchristian,項目名稱:wpf_experimentation,代碼行數:45,代碼來源:MainWindow.xaml.cs

示例6: GetService

		public void GetService ()
		{
			var obj = new TestValueSerialized ();
			var xr = new XamlObjectReader (obj);
			while (!xr.IsEof)
				xr.Read ();
			Assert.IsNotNull (Context, "premise#1");
			GetServiceCoreReader ();

			Context = null;
			var ctx = new XamlSchemaContext ();
			var xw = new XamlObjectWriter (ctx);
			var xt = ctx.GetXamlType (obj.GetType ());
			xw.WriteStartObject (xt);
			xw.WriteStartMember (XamlLanguage.Initialization);
			xw.WriteValue ("v");
			xw.WriteEndMember ();
			xw.Close ();
			Assert.IsNotNull (Provider, "premise#2"); // cannot get Context, it does not give IValueSerializerContext in the test.
			GetServiceCoreWriter ();
		}
開發者ID:nobled,項目名稱:mono,代碼行數:21,代碼來源:ValueSerializerContextTest.cs

示例7: Read_NamedItems2

		public void Read_NamedItems2 ()
		{
			// i1
			// - i2
			// -- i3
			// - i4
			// -- i3
			var obj = new NamedItem2 ("i1");
			var obj2 = new NamedItem2 ("i2");
			var obj3 = new NamedItem2 ("i3");
			var obj4 = new NamedItem2 ("i4");
			obj.References.Add (obj2);
			obj.References.Add (obj4);
			obj2.References.Add (obj3);
			obj4.References.Add (obj3);

			var xr = new XamlObjectReader (obj);
			Read_NamedItems2 (xr, true);
		}
開發者ID:telurmasin,項目名稱:mono,代碼行數:19,代碼來源:XamlObjectReaderTest.cs

示例8: Read_EventContainer

		public void Read_EventContainer ()
		{
			var obj = new EventContainer ();
			obj.Run += delegate { Console.Error.WriteLine ("done"); };
			var xr = new XamlObjectReader (obj);
			Read_EventContainer (xr);
		}
開發者ID:telurmasin,項目名稱:mono,代碼行數:7,代碼來源:XamlObjectReaderTest.cs

示例9: Read_NamedItems

		public void Read_NamedItems ()
		{
			// foo
			// - bar
			// -- foo
			// - baz
			var obj = new NamedItem ("foo");
			var obj2 = new NamedItem ("bar");
			obj.References.Add (obj2);
			obj.References.Add (new NamedItem ("baz"));
			obj2.References.Add (obj);

			var xr = new XamlObjectReader (obj);
			Read_NamedItems (xr, true);
		}
開發者ID:telurmasin,項目名稱:mono,代碼行數:15,代碼來源:XamlObjectReaderTest.cs

示例10: Read_ArgumentAttributed

		public void Read_ArgumentAttributed ()
		{
			var obj = new ArgumentAttributed ("foo", "bar");
			var r = new XamlObjectReader (obj);
			Read_ArgumentAttributed (r, obj);
		}
開發者ID:telurmasin,項目名稱:mono,代碼行數:6,代碼來源:XamlObjectReaderTest.cs

示例11: Read_TypeExtensionWrapper

		public void Read_TypeExtensionWrapper ()
		{
			var obj = new TypeExtensionWrapper () { Param = new TypeExtension ("Foo") };
			var r = new XamlObjectReader (obj);
			Read_TypeExtensionWrapper (r);
		}
開發者ID:telurmasin,項目名稱:mono,代碼行數:6,代碼來源:XamlObjectReaderTest.cs

示例12: are

		[Test] // List contents are (sort of) treated as top-level too, so it is not serialized as IXmlSerializable(!)
		public void Read_ListXmlSerializable ()
		{
			var obj = new List<XmlSerializable> ();
			obj.Add (new XmlSerializable ("<root/>"));
			var xr = new XamlObjectReader (obj);
			Read_ListXmlSerializable (xr);
		}
開發者ID:telurmasin,項目名稱:mono,代碼行數:8,代碼來源:XamlObjectReaderTest.cs

示例13: Read_CommonXamlType

		// from initial to StartObject
		protected void Read_CommonXamlType (XamlObjectReader r)
		{
			Read_CommonXamlType (r, delegate {
				Assert.IsNull (r.Instance, "ct#4");
				});
		}
開發者ID:imphasing,項目名稱:mono,代碼行數:7,代碼來源:XamlReaderTestBase.cs

示例14: Read_ListWrapper

		public void Read_ListWrapper ()
		{
			var obj = new ListWrapper (new List<int> (new int [] {5, -3, 0}));
			var r = new XamlObjectReader (obj);
			Read_ListWrapper (r);
		}
開發者ID:telurmasin,項目名稱:mono,代碼行數:6,代碼來源:XamlObjectReaderTest.cs

示例15: Read_ListWrapper2

		public void Read_ListWrapper2 () // read-write list member.
		{
			var obj = new ListWrapper2 (new List<int> (new int [] {5, -3, 0}));
			var r = new XamlObjectReader (obj);
			Read_ListWrapper2 (r);
		}
開發者ID:telurmasin,項目名稱:mono,代碼行數:6,代碼來源:XamlObjectReaderTest.cs


注:本文中的System.Xaml.XamlObjectReader類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。