Esempio n. 1
0
		public void AddInconsistent2 ()
		{
			var x = new ArrayExtension (new int [] {1, 3});
			Assert.AreEqual (typeof (int), x.Type, "#1");
			x.AddChild (new object ());
			Assert.AreEqual (typeof (int), x.Type, "#2");
		}
		public void AddChild2 ()
		{
			var x = new ArrayExtension (new int [0]);
			x.AddChild (new object ());
			x.AddChild (5);
			x.AddChild ("test");
		}
		public void AddInconsistent ()
		{
			var x = new ArrayExtension (typeof (int));
			Assert.AreEqual (typeof (int), x.Type, "#1");
			// adding inconsistent items is not rejected, while calling ProvideValue() results in an error.
			x.AddChild (new object ());
			Assert.AreEqual (typeof (int), x.Type, "#2");
		}
		public void AddTextInconsistent ()
		{
			var x = new ArrayExtension (new int [] {1, 3});
			Assert.AreEqual (typeof (int), x.Type, "#1");
			x.AddText ("test");
			x.AddText (null); // allowed
			Assert.AreEqual (4, x.Items.Count);
			Assert.AreEqual (typeof (int), x.Type, "#2");
		}
		public void ProvideValue ()
		{
			var x = new ArrayExtension (new int [] {1, 3});
			x.AddChild (5);
			Assert.AreEqual (3, x.Items.Count);
			var ret = x.ProvideValue (null);
			Assert.IsNotNull (ret, "#1");
			var arr = ret as int [];
			Assert.IsNotNull (arr, "#2");
			Assert.AreEqual (3, arr.Length, "#3");
			Assert.AreEqual (5, arr [2], "#4");
		}
		public void ProvideValueInconsistent2 ()
		{
			var x = new ArrayExtension (new int [] {1, 3});
			x.AddChild (new object ());
			x.AddChild (null); // allowed
			Assert.AreEqual (4, x.Items.Count);
			Assert.Throws<InvalidOperationException> (() => x.ProvideValue (null));
		}
		public void ProvideValueEmpty ()
		{
			var x = new ArrayExtension (typeof (int));
			x.ProvideValue (null); // allowed.
		}
		public void AddToCollectionArrayExtension ()
		{
			var i = XamlLanguage.Array.Invoker;
			var ax = new ArrayExtension ();
			Assert.Throws<NotSupportedException> (() => i.AddToCollection (ax, 5));
		}
Esempio n. 9
0
		public void Read_ArrayExtension ()
		{
			var obj = new ArrayExtension (new int [] {5, -3, 0});
			var r = new XamlObjectReader (obj);
			Read_ArrayOrArrayExtension (r, obj);
		}
		public void ProvideValueInconsistent2 ()
		{
			var x = new ArrayExtension (new int [] {1, 3});
			x.AddChild (new object ());
			x.AddChild (null); // allowed
			Assert.AreEqual (4, x.Items.Count);
			x.ProvideValue (null);
		}
		public void ProvideValueWithoutType ()
		{
			var x = new ArrayExtension ();
			x.ProvideValue (null); // Type must be set first.
		}
Esempio n. 12
0
		public void AddToCollectionArrayInstance ()
		{
			var i = new XamlTypeInvoker (new XamlType (typeof (int []), sctx));
			var ax = new ArrayExtension ();
			i.AddToCollection (ax, 5);
		}
Esempio n. 13
0
		public void AddToCollectionArrayExtension ()
		{
			var i = XamlLanguage.Array.Invoker;
			var ax = new ArrayExtension ();
			i.AddToCollection (ax, 5);
		}
		public void AddToCollectionArrayInstance ()
		{
			var i = new XamlTypeInvoker (new XamlType (typeof (int []), sctx));
			var ax = new ArrayExtension ();
			Assert.Throws<NotSupportedException> (() => i.AddToCollection (ax, 5));
		}
Esempio n. 15
0
		public void ProvideValueInconsistent3 ()
		{
			var x = new ArrayExtension (new int [] {1, 3});
			x.AddText ("test");
			Assert.Throws<InvalidOperationException> (() => x.ProvideValue (null));
		}
		public void ProvideValueInconsistent3 ()
		{
			var x = new ArrayExtension (new int [] {1, 3});
			x.AddText ("test");
			x.ProvideValue (null);
		}
		public void ProvideValueInconsistent ()
		{
			var x = new ArrayExtension (typeof (int));
			x.AddChild (new object ());
			x.ProvideValue (null);
		}
Esempio n. 18
0
		public void ProvideValueInconsistent ()
		{
			var x = new ArrayExtension (typeof (int));
			x.AddChild (new object ());
			Assert.Throws<InvalidOperationException> (() => x.ProvideValue (null));
		}
Esempio n. 19
0
		public void ProvideValueWithoutType ()
		{
			var x = new ArrayExtension ();
			Assert.Throws<InvalidOperationException> (() => x.ProvideValue (null)); // Type must be set first.
		}
Esempio n. 20
0
			public TestClass ()
			{
				ArrayMember = new ArrayExtension (typeof (int));
				ArrayMember.AddChild (5);
				ArrayMember.AddChild (3);
				ArrayMember.AddChild (-1);
			}
Esempio n. 21
0
        // takes a BamlCollectionHolder and its context and sets the value of the holder's collection to be
        // either the default collection instantiated by the holder's constructor or a newly created
        // collection created based on the expected type. 
        // *** Used when we do not have an explicit tag.
        private void InitPropertyCollection(BamlCollectionHolder holder, ReaderContextStackData context) 
        { 
            // this method should only be called to initialize the collection
            Debug.Assert (holder.Collection == null); 

            if (context.ContextType == ReaderFlags.PropertyArray)
            {
                // arrays are a little different than other collections, because we wrap them in an array extension. 
                // Here we create an array extension and assign the element type based on the property.
 
                ArrayExtension arrayExt = new ArrayExtension(); 
                arrayExt.Type = context.ExpectedType.GetElementType();
                holder.Collection = arrayExt; 
            }
            else if (holder.DefaultCollection != null)
            {
                // if we the property getter returned a default value, then we use that collection to insert 
                // as the property's collection.
 
                holder.Collection = holder.DefaultCollection; 
            }
            else 
            {
                ThrowException(SRID.ParserNullPropertyCollection, holder.PropertyDefinition.Name);
            }
 
            context.ExpectedType = null; // Don't want to receive any other values
        }