Exemplo n.º 1
0
        public static unsafe ValueType Box <T>(T?nullable) where T : struct
        {
            ValueType scam = new NullableContainer <T>(nullable);

            TypedReference tr         = __makeref(scam);
            IntPtr         typehandle = TypeOf <Nullable <T> > .TypeID.TypeHandle.Value;
            IntPtr *       trstruct   = (IntPtr *)&tr;

            * *((IntPtr **)trstruct[0]) = typehandle;
            return(scam);
        }
Exemplo n.º 2
0
		public void NullableContainer ()
		{
			var xt = sctx.GetXamlType (typeof (NullableContainer));
			Assert.IsFalse (xt.IsGeneric, "#1");
			Assert.IsTrue (xt.IsNullable, "#2");
			var xm = xt.GetMember ("TestProp");
			Assert.IsTrue (xm.Type.IsGeneric, "#3");
			Assert.IsTrue (xm.Type.IsNullable, "#4");
			Assert.AreEqual ("clr-namespace:System;assembly=mscorlib", xm.Type.PreferredXamlNamespace, "#5");
			Assert.AreEqual (1, xm.Type.TypeArguments.Count, "#6");
			Assert.AreEqual (XamlLanguage.Int32, xm.Type.TypeArguments [0], "#7");
			Assert.IsNotNull (xm.Type.TypeConverter, "#8");
			Assert.IsNotNull (xm.Type.TypeConverter.ConverterInstance, "#9");

			var obj = new NullableContainer ();
			xm.Invoker.SetValue (obj, 5);
			xm.Invoker.SetValue (obj, null);
		}
		public void Read_NullableContainer ()
		{
			var obj = new NullableContainer () { TestProp = 5 };
			var xr = new XamlObjectReader (obj);
			Read_NullableContainer (xr);
		}