示例#1
0
        public void HasProperty()
        {
            ExpandoObject expando = new { Foo = "Bar" }.ToExpando();

            Assert.IsTrue(expando.HasProperty("Foo"));
            Assert.IsFalse(expando.HasProperty("X"));
        }
示例#2
0
        public void HasProperty()
        {
            Executing.This(() => TypeUtil.HasProperty(null, "test")).Should().Throw<ArgumentNullException>();
            Executing.This(() => typeof(object).HasProperty(null)).Should().Throw<ArgumentNullException>();

            var type = new { x = 1, y = 2 }.GetType();
            type.HasProperty("x").Should().Be.True();
            type.HasProperty("y").Should().Be.True();
            type.HasProperty("z").Should().Be.False();
        }
示例#3
0
		/// <summary>
		/// Create a <see cref="FieldGetter"/> to <c>get</c> the value of the mapped Property
		/// through a <c>Field</c>.
		/// </summary>
		/// <param name="theClass">The <see cref="System.Type"/> to find the Property in.</param>
		/// <param name="propertyName">The name of the mapped Property to get.</param>
		/// <returns>
		/// The <see cref="FieldGetter"/> to use to get the value of the Property from an
		/// instance of the <see cref="System.Type"/>.</returns>
		/// <exception cref="PropertyNotFoundException" >
		/// Thrown when a Field specified by the <c>propertyName</c> could not
		/// be found in the <see cref="System.Type"/>.
		/// </exception>
		public IGetter GetGetter(System.Type theClass, string propertyName)
		{
			string fieldName = GetFieldName(propertyName);
			if (!Equals(fieldName, propertyName) && !theClass.HasProperty(propertyName))
			{
				// it is a field access that imply the existence of the property
				throw new PropertyNotFoundException(propertyName, fieldName, theClass);
			}
			return new FieldGetter(GetField(theClass, fieldName), theClass, fieldName);
		}
		public void HasProperty_PickNonExisting_ReturnsFalse()
		{
			var input = new[]
		    {
		        ModelGrammar.TokenObjectBeginUnnamed,
		        ModelGrammar.TokenProperty("key1"),
		        ModelGrammar.TokenNull,
		        ModelGrammar.TokenProperty("key2"),
		        ModelGrammar.TokenPrimitive("Hello!"),
		        ModelGrammar.TokenProperty("three"),
		        ModelGrammar.TokenPrimitive(3),
		        ModelGrammar.TokenProperty("4"),
		        ModelGrammar.TokenTrue,
		        ModelGrammar.TokenObjectEnd
		    };

			// test for a specific property
			var actual = input.HasProperty(name => name.LocalName == "five");

			Assert.False(actual);
		}