public static bool IsMatchFor( this PropertyOrField master, PropertyOrField other ) { return(master.IsMatchFor(other, false)); }
public void PropertyOrField_Get_Set_4() { CanaryClass canary = new CanaryClass { Int32Property = 123 }; Type type = canary.GetType(); PropertyInfo info = type.GetProperty("Int32Property"); Assert.IsNotNull(info); PropertyOrField property = new PropertyOrField(info); Assert.AreSame(info, property.PropertyInfo); Assert.IsNull(property.FieldInfo); Assert.AreEqual("Int32Property", property.Name); Assert.IsTrue(property.MemberType == typeof(int)); Assert.IsTrue(property.IsProperty); Assert.IsFalse(property.IsIndexed); Assert.IsFalse(property.ReadOnly); Assert.AreEqual(123, property.GetValue(canary)); property.SetValue(canary, 321); Assert.AreEqual(321, canary.Int32Property); Assert.IsTrue(property.HaveAttribute <DisplayNameAttribute>(false)); DisplayNameAttribute attribute = property.GetCustomAttribute <DisplayNameAttribute>(false); Assert.IsNotNull(attribute); Assert.AreEqual("CanaryProperty", attribute.DisplayName); Assert.AreEqual("Int32Property", property.ToString()); }
public static bool IsAssignmentMatchFor( this PropertyOrField master, PropertyOrField other ) { return(master.IsAssignmentMatchFor(other, true)); }
private Expression GetAreEqualPropertyValuesExpression( PropertyOrField property, Expression lhsParameterExpression, Expression rhsParameterExpression, IEnumerable <Type> typesCurrentlyUnderConstruction) { var lhsPropertyValueExpression = BoxIfNecessary(Expression.PropertyOrField(lhsParameterExpression, property.Name)); var rhsPropertyValueExpression = BoxIfNecessary(Expression.PropertyOrField(rhsParameterExpression, property.Name)); if (property.PropertyOrFieldType.IsSealed && !CanCreateEqualsCycle(property.PropertyOrFieldType, typesCurrentlyUnderConstruction)) { var equalsFunc = GetOptimizedEqualsFunc(property.PropertyOrFieldType, Type.EmptyTypes); return (Expression.Invoke( Expression.Constant(equalsFunc), lhsPropertyValueExpression, rhsPropertyValueExpression)); } var thisClosure = Expression.Constant(this); var equalsMethod = typeof(IEqualityComparer).GetMethod("Equals"); return (Expression.Call( thisClosure, equalsMethod, lhsPropertyValueExpression, rhsPropertyValueExpression)); }
public void PropertyOrField_Get_Set_3() { CanaryClass canary = new CanaryClass { StringField = "Text" }; Type type = canary.GetType(); FieldInfo info = type.GetField("StringField"); Assert.IsNotNull(info); PropertyOrField field = new PropertyOrField(info); Assert.AreSame(info, field.FieldInfo); Assert.IsNull(field.PropertyInfo); Assert.AreEqual("StringField", field.Name); Assert.IsTrue(field.MemberType == typeof(string)); Assert.IsFalse(field.IsProperty); Assert.IsFalse(field.IsIndexed); Assert.IsFalse(field.ReadOnly); Assert.AreEqual("Text", field.GetValue(canary)); field.SetValue(canary, "Text2"); Assert.AreEqual("Text2", canary.StringField); Assert.IsFalse(field.HaveAttribute <DisplayNameAttribute>(false)); Assert.AreEqual("StringField", field.ToString()); }
public void PropertyOrField_Get_Set_1() { CanaryClass canary = new CanaryClass { Int32Field = 123 }; Type type = canary.GetType(); FieldInfo info = type.GetField("Int32Field"); Assert.IsNotNull(info); PropertyOrField field = new PropertyOrField(info); Assert.AreSame(info, field.FieldInfo); Assert.IsNull(field.PropertyInfo); Assert.AreEqual("Int32Field", field.Name); Assert.IsTrue(field.MemberType == typeof(int)); Assert.IsFalse(field.IsProperty); Assert.IsFalse(field.IsIndexed); Assert.IsFalse(field.ReadOnly); Assert.AreEqual(123, field.GetValue(canary)); field.SetValue(canary, 321); Assert.AreEqual(321, canary.Int32Field); Assert.IsFalse(field.HaveAttribute <DisplayNameAttribute>(false)); Assert.AreEqual("Int32Field", field.ToString()); }
public void PropertyOrField_Get_Set_2() { CanaryClass canary = new CanaryClass { BooleanField = true }; Type type = canary.GetType(); FieldInfo info = type.GetField("BooleanField"); Assert.IsNotNull(info); PropertyOrField field = new PropertyOrField(info); Assert.AreSame(info, field.FieldInfo); Assert.IsNull(field.PropertyInfo); Assert.AreEqual("BooleanField", field.Name); Assert.IsTrue(field.MemberType == typeof(bool)); Assert.IsFalse(field.IsProperty); Assert.IsFalse(field.IsIndexed); Assert.IsFalse(field.ReadOnly); Assert.AreEqual(true, field.GetValue(canary)); field.SetValue(canary, false); Assert.AreEqual(false, canary.BooleanField); Assert.IsFalse(field.HaveAttribute <DisplayNameAttribute>(false)); Assert.AreEqual("BooleanField", field.ToString()); }
public override void SetRandomValue( PropertyOrField propInfo, ref object target) { var value = GetRandomInt(100, 1024); propInfo.SetValue(target, value); }
private static bool AccessMatches( this PropertyOrField master, PropertyOrField other ) { return(master.CanRead == other.CanRead && master.CanWrite == other.CanWrite); }
public void PropertyOrField_Construction_2() { Type type = typeof(CanaryClass); MemberInfo member = type.GetMethod("MethodOne"); Assert.IsNotNull(member); PropertyOrField property = new PropertyOrField(member); Assert.IsNotNull(property); }
public void PropertyOrField_Construction_1() { Type type = typeof(CanaryClass); MemberInfo member = type.GetProperty("Int32Property"); Assert.IsNotNull(member); PropertyOrField property = new PropertyOrField(member); Assert.IsNotNull(property); }
/// <summary> /// Tests if this PropertyOrField is a match for another /// </summary> /// <param name="master"></param> /// <param name="other"></param> /// <param name="mustMatchMemberType"></param> /// <returns></returns> public static bool IsMatchFor( this PropertyOrField master, PropertyOrField other, bool mustMatchMemberType ) { return(master.Name == other.Name && master.Type == other.Type && master.AccessMatches(other) && (!mustMatchMemberType || master.MemberType == other.MemberType)); }
public static bool IsAssignmentMatchFor( this PropertyOrField master, PropertyOrField other, bool mustMatchMemberType ) { #pragma warning disable S1067 return(master.Name == other.Name && other.Type.IsAssignableOrUpcastableTo(master.Type) && master.AccessMatches(other) && (!mustMatchMemberType || master.MemberType == other.MemberType)); #pragma warning restore S1067 }
public void PropertyOrField_CompareTo_1() { Type type = typeof(CanaryClass); FieldInfo info = type.GetField("Int32Field"); Assert.IsNotNull(info); PropertyOrField first = new PropertyOrField(info); PropertyOrField second = new PropertyOrField(info); Assert.IsTrue(((IComparable <PropertyOrField>)first).CompareTo(second) == 0); info = type.GetField("BooleanField"); Assert.IsNotNull(info); second = new PropertyOrField(info); Assert.IsTrue(((IComparable <PropertyOrField>)first).CompareTo(second) != 0); }
/// <summary> /// Actually invoked when attempting to set a random value on the /// named property /// </summary> /// <param name="propInfo"></param> /// <param name="target"></param> public abstract void SetRandomValue( PropertyOrField propInfo, ref object target);
/// <inheritdoc /> public override void SetRandomValue(PropertyOrField propInfo, ref object target) { propInfo.SetValue(target, RandomValueGen.GetRandomInt(1)); }
/// <inheritdoc /> public override void SetRandomValue(PropertyOrField propInfo, ref object target) { /* intentionally left blank */ }
/// <summary> /// Prints out a pretty representation of this PropertyOrField /// </summary> /// <param name="item"></param> /// <returns></returns> // ReSharper disable once UnusedMember.Global public static string PrettyPrint(this PropertyOrField item) { return($"{item.Name} ({item.Type}) [{item.PrintAccess()}]"); }
public static string PrintAccess(this PropertyOrField item) { return(AccessNames .First(t => t.Item1 == item.CanRead && t.Item2 == item.CanWrite) .Item3); }
/// <inheritdoc /> public override void SetRandomValue(PropertyOrField propInfo, ref object target) { propInfo.SetValue(target, _generator.NextObjectValue()); }