private static void CheckParameters(TypeMismatchSearcher searcher, IEnumerable <ParameterInfo> ps, Type[] ts) { foreach (var _ in ps.Select(p => p.ParameterType).Zip(ts, searcher.Equals)) { // // NB: Evaluated for the side-effect of adding mismatches to the TypeMismatchSearcher instance. // } }
/// <summary> /// Reports failure of resolving a field after retargeting types, offering a last chance opportunity to resolve the field. /// </summary> /// <param name="originalField">Original field.</param> /// <param name="declaringType">Retargeted declaring type.</param> /// <param name="fieldType">Retargeted field type.</param> /// <returns>New field to use. By default, this method throws an exception to report the resolution failure.</returns> /// <exception cref="InvalidOperationException">Thrown to report the resolution failure.</exception> protected override MemberInfo FailResolveField(FieldInfo originalField, Type declaringType, Type fieldType) { var searchMismatches = new TypeMismatchSearcher(); searchMismatches.Equals(originalField.DeclaringType, declaringType); searchMismatches.Equals(originalField.FieldType, fieldType); var ts = searchMismatches._results.Keys.Select(t => t.ToString()).ToArray(); var err = string.Format(CultureInfo.InvariantCulture, "Usage of type(s) {0} in the declaration of field '{1}' are not allowed during entity type erasure. Did you declare a field that may not be known by the target system and relies on entity types?", string.Join(", ", ts), originalField); throw new InvalidOperationException(err); }
/// <summary> /// Reports failure of resolving a constructor after retargeting types, offering a last chance opportunity to resolve the constructor. /// </summary> /// <param name="originalConstructor">Original constructor.</param> /// <param name="declaringType">Retargeted declaring type.</param> /// <param name="parameters">Retargeted parameter types.</param> /// <returns>New constructor to use. By default, this method throws an exception to report the resolution failure.</returns> /// <exception cref="InvalidOperationException">Thrown to report the resolution failure.</exception> protected override ConstructorInfo FailResolveConstructor(ConstructorInfo originalConstructor, Type declaringType, Type[] parameters) { var searchMismatches = new TypeMismatchSearcher(); searchMismatches.Equals(originalConstructor.DeclaringType, declaringType); CheckParameters(searchMismatches, originalConstructor.GetParameters(), parameters); var ts = searchMismatches._results.Keys.Select(t => t.ToString()).ToArray(); var err = string.Format(CultureInfo.InvariantCulture, "Usage of type(s) {0} in the signature of constructor '{1}' are not allowed during entity type erasure. Did you declare a constructor that may not be known by the target system and relies on entity types?", string.Join(", ", ts), originalConstructor); throw new InvalidOperationException(err); }
/// <summary> /// Reports failure of resolving a property after retargeting types, offering a last chance opportunity to resolve the property. /// </summary> /// <param name="originalProperty">Original property.</param> /// <param name="declaringType">Retargeted declaring type.</param> /// <param name="propertyType">Retargeted property type.</param> /// <param name="indexerParameters">Retargeted indexer parameter types.</param> /// <returns>New property to use. By default, this method throws an exception to report the resolution failure.</returns> /// <exception cref="InvalidOperationException">Thrown to report the resolution failure.</exception> protected override MemberInfo FailResolveProperty(PropertyInfo originalProperty, Type declaringType, Type propertyType, Type[] indexerParameters) { var searchMismatches = new TypeMismatchSearcher(); searchMismatches.Equals(originalProperty.DeclaringType, declaringType); searchMismatches.Equals(originalProperty.PropertyType, propertyType); if (indexerParameters != null) { CheckParameters(searchMismatches, originalProperty.GetIndexParameters(), indexerParameters); } var ts = searchMismatches._results.Keys.Select(t => t.ToString()).ToArray(); var err = string.Format(CultureInfo.InvariantCulture, "Usage of type(s) {0} in the declaration of property '{1}' are not allowed during entity type erasure. Did you declare a property that may not be known by the target system and relies on entity types?", string.Join(", ", ts), originalProperty); throw new InvalidOperationException(err); }