/// <summary> /// Gets the CLR property with the specified "signature" /// corresponding to the specified slim property representation. /// This method has built-in data model awareness to map properties /// based on their mapped identity using MappingAttribute. /// </summary> /// <param name="propertySlim"> /// Slim property representation to convert to the corresponding /// CLR property. /// </param> /// <param name="declaringType"> /// Declaring type to locate the property on. /// </param> /// <param name="propertyType">Type of the property.</param> /// <param name="indexParameterTypes"> /// Parameter types of the indexer, if any. /// </param> /// <returns> /// CLR property corresponding to the specified slim property /// representation. /// </returns> /// <exception cref="ArgumentNullException"> /// <c>declaringType</c> is null</exception> protected override PropertyInfo GetPropertyCore(PropertyInfoSlim propertySlim, Type declaringType, Type propertyType, Type[] indexParameterTypes) { if (propertySlim.DeclaringType.Kind == TypeSlimKind.Structural) { var propertyMatch = declaringType.GetProperties().SingleOrDefault(prop => { var attribute = prop.GetCustomAttribute <MappingAttribute>(inherit: false); if (attribute == null) { return(prop.Name == propertySlim.Name); } else { return(attribute.Uri == propertySlim.Name || prop.Name == propertySlim.Name); } }); if (propertyMatch == default) { throw new InvalidOperationException( string.Format( CultureInfo.InvariantCulture, "No property with name or mapping attribute '{0}' was found on type '{1}'.", propertySlim.Name, declaringType)); } return(propertyMatch); } return(base.GetPropertyCore(propertySlim, declaringType, propertyType, indexParameterTypes)); }
protected override PropertyInfo GetPropertyCore(PropertyInfoSlim propertySlim, Type declaringType, Type propertyType, Type[] indexParameterTypes) { if (propertySlim.DeclaringType.Kind == TypeSlimKind.Structural) { return(declaringType.GetProperties().Single(prop => prop.GetCustomAttribute <MappingAttribute>(inherit: false).Uri == propertySlim.Name || prop.Name == propertySlim.Name)); } return(base.GetPropertyCore(propertySlim, declaringType, propertyType, indexParameterTypes)); }
public void MemberInfoSlimEqualityComparer_Property_Index() { var tq = new TypeSlimEqualityComparer(); var eq = new MemberInfoSlimEqualityComparer(tq); var asm = new AssemblySlim("foo"); var tp1 = TypeSlim.Simple(asm, "bar"); var i4 = typeof(int).ToTypeSlim(); var i8 = typeof(long).ToTypeSlim(); var indxs0 = new List <TypeSlim> { i4 }.AsReadOnly(); var indxs1 = new List <TypeSlim> { i8 }.AsReadOnly(); var indxs2 = new List <TypeSlim> { i4, i8 }.AsReadOnly(); var indxs3 = new List <TypeSlim> { i8, i4 }.AsReadOnly(); var prp_i4_0_0 = PropertyInfoSlim.Make(tp1, "Item", i4, indxs0, canWrite: true); var prp_i4_0_1 = PropertyInfoSlim.Make(tp1, "Item", i4, indxs0, canWrite: true); var prp_i4_1_0 = PropertyInfoSlim.Make(tp1, "Item", i4, indxs1, canWrite: true); var prp_i4_2_0 = PropertyInfoSlim.Make(tp1, "Item", i4, indxs2, canWrite: true); var prp_i4_3_0 = PropertyInfoSlim.Make(tp1, "Item", i4, indxs3, canWrite: true); var prp_i4_3_1 = PropertyInfoSlim.Make(tp1, "Item", i4, indxs3, canWrite: true); var prp_i8_0_0 = PropertyInfoSlim.Make(tp1, "Item", i8, indxs0, canWrite: true); var prp_i8_1_0 = PropertyInfoSlim.Make(tp1, "Item", i8, indxs1, canWrite: true); var prp_i8_2_0 = PropertyInfoSlim.Make(tp1, "Item", i8, indxs2, canWrite: true); var prp_i8_3_0 = PropertyInfoSlim.Make(tp1, "Item", i8, indxs3, canWrite: true); Assert.IsTrue(eq.Equals(prp_i4_0_0, prp_i4_0_0)); Assert.IsTrue(eq.Equals(prp_i4_0_0, prp_i4_0_1)); Assert.IsTrue(eq.Equals(prp_i4_0_1, prp_i4_0_0)); Assert.IsTrue(eq.Equals(prp_i4_3_0, prp_i4_3_1)); Assert.IsTrue(eq.Equals(prp_i4_3_1, prp_i4_3_0)); Assert.IsFalse(eq.Equals(prp_i4_0_0, prp_i4_1_0)); Assert.IsFalse(eq.Equals(prp_i4_1_0, prp_i4_0_0)); Assert.IsFalse(eq.Equals(prp_i4_2_0, prp_i4_3_0)); Assert.IsFalse(eq.Equals(prp_i4_3_0, prp_i4_2_0)); Assert.IsFalse(eq.Equals(prp_i4_0_0, prp_i8_0_0)); Assert.IsFalse(eq.Equals(prp_i4_1_0, prp_i8_1_0)); Assert.IsFalse(eq.Equals(prp_i4_2_0, prp_i8_2_0)); Assert.IsFalse(eq.Equals(prp_i4_3_0, prp_i8_3_0)); Assert.AreEqual(eq.GetHashCode(prp_i4_0_0), eq.GetHashCode(prp_i4_0_1)); Assert.AreEqual(eq.GetHashCode(prp_i4_3_0), eq.GetHashCode(prp_i4_3_1)); }
public static string GetName(this MemberInfoSlim m) { return(m switch { SimpleMethodInfoSlimBase smtd => smtd.Name, GenericMethodInfoSlim gmtd => gmtd.GenericMethodDefinition.GetName(), PropertyInfoSlim prp => prp.Name, FieldInfoSlim fld => fld.Name, _ => "<unknown>", });
public void MemberInfoSlimEqualityComparer_Property_NoIndex() { var tq = new TypeSlimEqualityComparer(); var eq = new MemberInfoSlimEqualityComparer(tq); var asm = new AssemblySlim("foo"); var tp1 = TypeSlim.Simple(asm, "bar"); var tp2 = TypeSlim.Simple(asm, "baz"); var i4 = typeof(int).ToTypeSlim(); var i8 = typeof(long).ToTypeSlim(); var indxs = Array.Empty <TypeSlim>().ToList().AsReadOnly(); var prp11_0 = PropertyInfoSlim.Make(tp1, "qux1", i4, indxs, canWrite: true); var prp12_0 = PropertyInfoSlim.Make(tp1, "qux2", i4, indxs, canWrite: true); var prp13_0 = PropertyInfoSlim.Make(tp1, "qux3", i8, indxs, canWrite: true); var prp11_1 = PropertyInfoSlim.Make(tp1, "qux1", i4, indxs, canWrite: true); var prp12_1 = PropertyInfoSlim.Make(tp1, "qux2", i4, indxs, canWrite: true); var prp13_1 = PropertyInfoSlim.Make(tp1, "qux3", i8, indxs, canWrite: true); var prp21_0 = PropertyInfoSlim.Make(tp2, "qux1", i4, indxs, canWrite: true); Assert.IsTrue(eq.Equals(prp11_0, prp11_0)); Assert.IsTrue(eq.Equals(prp11_0, prp11_1)); Assert.IsTrue(eq.Equals(prp11_1, prp11_0)); Assert.IsTrue(eq.Equals(prp11_1, prp11_1)); Assert.IsTrue(eq.Equals(prp12_0, prp12_0)); Assert.IsTrue(eq.Equals(prp12_0, prp12_1)); Assert.IsTrue(eq.Equals(prp12_1, prp12_0)); Assert.IsTrue(eq.Equals(prp12_1, prp12_1)); Assert.IsTrue(eq.Equals(prp13_0, prp13_0)); Assert.IsTrue(eq.Equals(prp13_0, prp13_1)); Assert.IsTrue(eq.Equals(prp13_1, prp13_0)); Assert.IsTrue(eq.Equals(prp13_1, prp13_1)); Assert.IsFalse(eq.Equals(prp11_0, prp12_0)); Assert.IsFalse(eq.Equals(prp12_0, prp11_0)); Assert.IsFalse(eq.Equals(prp11_0, prp21_0)); Assert.IsFalse(eq.Equals(prp21_0, prp11_0)); Assert.AreEqual(eq.GetHashCode(prp11_0), eq.GetHashCode(prp11_1)); Assert.AreEqual(eq.GetHashCode(prp12_0), eq.GetHashCode(prp12_1)); Assert.AreEqual(eq.GetHashCode(prp13_0), eq.GetHashCode(prp13_1)); }
public void MemberInfoSlimEqualityComparer_Trivialities() { var tq = new TypeSlimEqualityComparer(); var eq = new MemberInfoSlimEqualityComparer(tq); var i4 = typeof(int).ToTypeSlim(); var fl = new FieldInfoSlim(i4, "foo", i4); var pr = PropertyInfoSlim.Make(i4, "bar", i4, new List <TypeSlim>().AsReadOnly(), canWrite: true); Assert.IsTrue(eq.Equals(null, null)); Assert.AreEqual(eq.GetHashCode(null), eq.GetHashCode(null)); Assert.IsFalse(eq.Equals(fl, null)); Assert.IsFalse(eq.Equals(null, fl)); Assert.IsFalse(eq.Equals(fl, pr)); Assert.IsFalse(eq.Equals(pr, fl)); }
protected override int VisitProperty(PropertyInfoSlim property) => Combine((int)property.MemberType, Visit(property.DeclaringType), Visit(property.PropertyType), Visit(property.Name), Visit(property.IndexParameterTypes));
protected override int VisitProperty(PropertyInfoSlim property) => throw new NotImplementedException();
internal IndexExpressionSlim(ExpressionSlim instance, PropertyInfoSlim indexer, ReadOnlyCollection <ExpressionSlim> arguments) { Indexer = indexer; Object = instance; Arguments = arguments; }
private static void AssertAreSameProperty(PropertyInfo propertyInfo, PropertyInfoSlim propertyInfoSlim) { Assert.AreEqual(propertyInfo.Name, propertyInfoSlim.Name); Assert.IsTrue(TypeSlimExtensions.Equals(propertyInfo.DeclaringType.ToTypeSlim(), propertyInfoSlim.DeclaringType)); Assert.IsTrue(TypeSlimExtensions.Equals(propertyInfo.PropertyType.ToTypeSlim(), propertyInfoSlim.PropertyType)); }
public PropertyDef(TypeRef declaringType, PropertyInfoSlim property) : base(declaringType) { _property = property; }