Invoke() public méthode

public Invoke ( ) : object
Résultat object
 public void Constructor_MemberInfo_ICollection_Boolean()
 {
     InstanceDescriptor id = new InstanceDescriptor(ci, new object[] { url }, false);
     Assert.Equal(1, id.Arguments.Count);
     Assert.False(id.IsComplete);
     Assert.Same(ci, id.MemberInfo);
     Uri uri = (Uri)id.Invoke();
     Assert.Equal(url, uri.AbsoluteUri);
 }
		public void Constructor0_MemberInfo_Type ()
		{
			Type type = typeof (Uri);
			InstanceDescriptor id = new InstanceDescriptor (type,
				new object [] { url });
			Assert.AreEqual (1, id.Arguments.Count, "#1");
			Assert.IsTrue (id.IsComplete, "#2");
			Assert.AreSame (type, id.MemberInfo, "#3");
			Assert.IsNull (id.Invoke (), "#4");
		}
		public void Constructor_MemberInfo_ICollection ()
		{
			InstanceDescriptor id = new InstanceDescriptor (ci, new object[] { url });
			Assert.AreEqual (1, id.Arguments.Count, "Arguments");
			Assert.IsTrue (id.IsComplete, "IsComplete");
			Assert.AreSame (ci, id.MemberInfo, "MemberInfo");
			Uri uri = (Uri) id.Invoke ();
			Assert.AreEqual (url, uri.AbsoluteUri, "Invoke");
		}
		public void Constructor_Null_ICollection ()
		{
			InstanceDescriptor id = new InstanceDescriptor (null, new object[] { });
			Assert.AreEqual (0, id.Arguments.Count, "#1");
			Assert.IsTrue (id.IsComplete, "#2");
			Assert.IsNull (id.MemberInfo, "#3");
			Assert.IsNull (id.Invoke (), "#4");
		}
		public void Property_Arguments_Null ()
		{
			PropertyInfo pi = typeof (Thread).GetProperty ("CurrentPrincipal");

			InstanceDescriptor id = new InstanceDescriptor (pi, null);
			Assert.AreEqual (0, id.Arguments.Count, "#1");
			Assert.IsTrue (id.IsComplete, "#2");
			Assert.AreSame (pi, id.MemberInfo, "#3");
			Assert.IsNotNull (id.Invoke (), "#4");
		}
		public void Property_Arguments_Mismatch ()
		{
			PropertyInfo pi = typeof (Thread).GetProperty ("CurrentPrincipal");

			InstanceDescriptor id = new InstanceDescriptor (pi, new object [] { url });
			Assert.AreEqual (1, id.Arguments.Count, "#1");
			object [] arguments = new object [id.Arguments.Count];
			id.Arguments.CopyTo (arguments, 0);
			Assert.AreSame (url, arguments [0], "#2");
			Assert.IsTrue (id.IsComplete, "#3");
			Assert.AreSame (pi, id.MemberInfo, "#4");
			try {
				id.Invoke ();
				Assert.Fail ("#5");
			} catch (TargetParameterCountException) {
			}
		}
		public void Field_Arguments_Null ()
		{
			FieldInfo fi = typeof (Uri).GetField ("SchemeDelimiter");

			InstanceDescriptor id = new InstanceDescriptor (fi, null);
			Assert.AreEqual (0, id.Arguments.Count, "#1");
			Assert.IsTrue (id.IsComplete, "#2");
			Assert.AreSame (fi, id.MemberInfo, "#3");
			Assert.IsNotNull (id.Invoke (), "#4");
		}
		private object ReadInstanceDescriptor(XmlNode node, ArrayList errors)
		{
			// First, need to deserialize the member
			//
			XmlAttribute memberAttr = node.Attributes["member"];

			if (memberAttr == null)
			{
				errors.Add("No member attribute on instance descriptor");
				return null;
			}

			byte[] data = Convert.FromBase64String(memberAttr.Value);
			BinaryFormatter formatter = new BinaryFormatter();
			MemoryStream stream = new MemoryStream(data);
			MemberInfo mi = (MemberInfo)formatter.Deserialize(stream);
			object[] args = null;

			// Check to see if this member needs arguments.  If so, gather
			// them from the XML.
			if (mi is MethodBase)
			{
				ParameterInfo[] paramInfos = ((MethodBase)mi).GetParameters();

				args = new object[paramInfos.Length];

				int idx = 0;

				foreach (XmlNode child in node.ChildNodes)
				{
					if (child.Name.Equals("Argument"))
					{
						object value;

						if (!ReadValue(child, TypeDescriptor.GetConverter(paramInfos[idx].ParameterType), errors, out value))
						{
							return null;
						}

						args[idx++] = value;
					}
				}

				if (idx != paramInfos.Length)
				{
					errors.Add(string.Format("Member {0} requires {1} arguments, not {2}.", mi.Name, args.Length, idx));
					return null;
				}
			}

			InstanceDescriptor id = new InstanceDescriptor(mi, args);
			object instance = id.Invoke();

			// Ok, we have our object.  Now, check to see if there are any properties, and if there are, 
			// set them.
			//
			foreach (XmlNode prop in node.ChildNodes)
			{
				if (prop.Name.Equals("Property"))
				{
					ReadProperty(prop, instance, errors);
				}
			}

			return instance;
		}
		public void Property_Arguments_Null ()
		{
#if MOBILE
			// ensure the property is not linked out of the application since it make the test fails
			Assert.NotNull (Thread.CurrentPrincipal, "pre-test");
#endif
			PropertyInfo pi = typeof (Thread).GetProperty ("CurrentPrincipal");

			InstanceDescriptor id = new InstanceDescriptor (pi, null);
			Assert.AreEqual (0, id.Arguments.Count, "#1");
			Assert.IsTrue (id.IsComplete, "#2");
			Assert.AreSame (pi, id.MemberInfo, "#3");
			Assert.IsNotNull (id.Invoke (), "#4");
		}
		public void Property_Arguments_Mismatch ()
		{
#if MOBILE
			// ensure the property is not linked out of the application since it make the test fails
			Assert.NotNull (Thread.CurrentPrincipal, "pre-test");
#endif
			PropertyInfo pi = typeof (Thread).GetProperty ("CurrentPrincipal");

			InstanceDescriptor id = new InstanceDescriptor (pi, new object [] { url });
			Assert.AreEqual (1, id.Arguments.Count, "#1");
			object [] arguments = new object [id.Arguments.Count];
			id.Arguments.CopyTo (arguments, 0);
			Assert.AreSame (url, arguments [0], "#2");
			Assert.IsTrue (id.IsComplete, "#3");
			Assert.AreSame (pi, id.MemberInfo, "#4");
			try {
				id.Invoke ();
				Assert.Fail ("#5");
			} catch (TargetParameterCountException) {
			}
		}
        public void Field_Arguments_Empty()
        {
            FieldInfo fi = typeof(Uri).GetField("SchemeDelimiter");

            InstanceDescriptor id = new InstanceDescriptor(fi, new object[0]);
            Assert.Equal(0, id.Arguments.Count);
            Assert.True(id.IsComplete);
            Assert.Same(fi, id.MemberInfo);
            Assert.NotNull(id.Invoke());
        }
        public void Property_Arguments_Null()
        {
            PropertyInfo pi = typeof(Thread).GetProperty("CurrentThread");

            InstanceDescriptor id = new InstanceDescriptor(pi, null);
            Assert.Equal(0, id.Arguments.Count);
            Assert.True(id.IsComplete);
            Assert.Same(pi, id.MemberInfo);
            Assert.NotNull(id.Invoke());
        }
        public void Property_Arguments_Mismatch()
        {
            PropertyInfo pi = typeof(Thread).GetProperty("CurrentThread");

            InstanceDescriptor id = new InstanceDescriptor(pi, new object[] { url });
            Assert.Equal(1, id.Arguments.Count);
            object[] arguments = new object[id.Arguments.Count];
            id.Arguments.CopyTo(arguments, 0);
            Assert.Same(url, arguments[0]);
            Assert.True(id.IsComplete);
            Assert.Same(pi, id.MemberInfo);

            Assert.Throws<TargetParameterCountException>(() => id.Invoke());
        }