public static bool TypesMatch(this ITypePair typePair, IList <Type> contextTypes) { var sourceType = contextTypes[0]; var targetType = contextTypes[1]; return((typePair.SourceType.IsAssignableTo(sourceType) || sourceType.IsAssignableTo(typePair.SourceType)) && (typePair.TargetType.IsAssignableTo(targetType) || targetType.IsAssignableTo(typePair.TargetType))); }
bool ITypePair.IsForSourceType(ITypePair typePair) { if (_isForSourceTypeOnly) { return(this.IsForAllSourceTypes() || HasSameSourceTypeAs(typePair)); } return(Get <SourceTypeComparer>()?.Invoke(this, typePair) ?? this.IsForSourceType(typePair)); }
private static bool TargetMemberTypeComparer(ITypePair typePair, ITypePair otherTypePair) { if (TypePairExtensions.IsForTargetType(typePair, otherTypePair)) { return(true); } return((otherTypePair is IQualifiedMemberContext context) && (context.TargetMember?.HasCompatibleType(typePair.TargetType) == true)); }
private static ConstructorInfo GetDictionaryCloneConstructor(ITypePair mapperData) { var dictionaryTypes = mapperData.TargetType.GetDictionaryTypes(); var dictionaryInterfaceType = typeof(IDictionary <,>).MakeGenericType(dictionaryTypes.Key, dictionaryTypes.Value); var comparerProperty = mapperData.SourceType.GetPublicInstanceProperty("Comparer"); return(FindDictionaryConstructor( mapperData.TargetType, dictionaryInterfaceType, (comparerProperty != null) ? 2 : 1)); }
private static bool SourceDictionaryTypeComparer <TValue>(ITypePair typePair, ITypePair otherTypePair) { if (!TypePairExtensions.IsForSourceType(typePair, otherTypePair)) { return(false); } if (typeof(TValue) == Constants.AllTypes) { return(true); } if ((otherTypePair as IQualifiedMemberContext)?.SourceMember is DictionarySourceMember dictionaryMember) { return(typeof(TValue).IsAssignableTo(dictionaryMember.ValueType)); } return(false); }
public static bool HasCompatibleTypes <TOtherTypePair>( this ITypePair typePair, TOtherTypePair otherTypePair, IQualifiedMember sourceMember = null, QualifiedMember targetMember = null) where TOtherTypePair : ITypePair { var sourceTypesMatch = typePair.IsForSourceType(otherTypePair.SourceType) || (sourceMember?.HasCompatibleType(typePair.SourceType) == true); if (!sourceTypesMatch) { return(false); } var targetTypesMatch = (targetMember?.HasCompatibleType(typePair.TargetType) == true) || otherTypePair.TargetType.IsAssignableTo(typePair.TargetType); return(targetTypesMatch); }
public static bool IsForSourceType(this ITypePair typePair, ITypePair otherTypePair) => typePair.IsForSourceType(otherTypePair.SourceType);
public virtual bool HasCompatibleTypes(ITypePair typePair) => typePair.HasCompatibleTypes(this, SourceMember, TargetMember);
public override bool HasCompatibleTypes(ITypePair typePair) => typePair.HasCompatibleTypes(this, SourceMember, TargetMember);
private static bool IsForStandaloneMapping(ITypePair mapperData) => mapperData.SourceType.RuntimeTypeNeeded() || mapperData.TargetType.RuntimeTypeNeeded();
public static bool HasTypesCompatibleWith(this ITypePair typePair, ITypePair otherTypePair) => typePair.IsForSourceType(otherTypePair) && typePair.IsForTargetType(otherTypePair);
public static bool IsForAllSourceTypes(this ITypePair typePair) => typePair.SourceType == Constants.AllTypes;
public static bool IsForAllTargetTypes(this ITypePair typePair) => typePair.TargetType == typeof(object);
bool ITypePair.IsForTargetType(ITypePair typePair) => this.IsForTargetType(typePair);
bool ITypePair.IsForSourceType(ITypePair typePair) => this.IsForSourceType(typePair);
public virtual bool HasCompatibleTypes(ITypePair typePair) => typePair.HasTypesCompatibleWith(this);
public override bool HasCompatibleTypes(ITypePair typePair) { return(_useParentForTypeCheck ? Parent.HasCompatibleTypes(typePair) : base.HasCompatibleTypes(typePair)); }
bool ITypePair.IsForTargetType(ITypePair typePair) { return(Get <TargetTypeComparer>()?.Invoke(this, typePair) ?? this.IsForTargetType(typePair)); }
public static bool IsForSourceType(this ITypePair typePair, ITypePair otherTypePair) => IsForAllSourceTypes(typePair) || otherTypePair.SourceType.IsAssignableTo(typePair.SourceType);
private static bool IsForSourceType(this ITypePair typePair, Type sourceType) => IsForAllSourceTypes(typePair) || sourceType.IsAssignableTo(typePair.SourceType);
public static bool IsForTargetType(this ITypePair typePair, ITypePair otherTypePair) => otherTypePair.TargetType.IsAssignableTo(typePair.TargetType);
private bool HasSameSourceTypeAs(ITypePair typePair) => typePair.SourceType == SourceType;
public override bool HasCompatibleTypes(ITypePair typePair) { return(_useParentForTypeCheck ? Parent.HasCompatibleTypes(typePair) : typePair.HasCompatibleTypes(this, SourceMember, TargetMember)); }
private void LookForDerivedTypePairs(ITypePair typePair) { var rootSourceType = GetRootType(typePair.SourceType); var rootTargetType = GetRootType(typePair.TargetType); var typesKey = new SourceAndTargetTypesKey(rootSourceType, rootTargetType); if (TypesChecked(typesKey, 0)) { return; } // ReSharper disable once InconsistentlySynchronizedField var currentTypeCount = CheckedTypesCount; lock (_lookupSync) { if ((CheckedTypesCount > currentTypeCount) && TypesChecked(typesKey, startIndex: currentTypeCount)) { return; } Store(typesKey); if (rootSourceType == rootTargetType) { AddSameRootTypePairs(rootSourceType); return; } if (SkipDerivedTypePairsLookup( rootSourceType, rootTargetType, out var derivedTargetTypeNameFactory)) { return; } var derivedSourceTypes = GlobalContext.Instance.DerivedTypes.GetTypesDerivedFrom(rootSourceType); if (derivedSourceTypes.None()) { return; } var derivedTargetTypes = GlobalContext.Instance.DerivedTypes.GetTypesDerivedFrom(rootTargetType); if (derivedTargetTypes.None()) { return; } var candidatePairsData = derivedSourceTypes.ProjectToArray(derivedTargetTypeNameFactory, (dttnf, t) => new { DerivedSourceType = t, DerivedTargetTypeName = dttnf.Invoke(t) }); foreach (var candidatePairData in candidatePairsData) { var derivedTargetType = derivedTargetTypes .FirstOrDefault(candidatePairData, (cpd, t) => t.Name == cpd.DerivedTargetTypeName); if (derivedTargetType == null) { continue; } var derivedTypePair = CreatePairFor( rootSourceType, candidatePairData.DerivedSourceType, rootTargetType, derivedTargetType); Add(derivedTypePair); } } }
public override bool HasCompatibleTypes(ITypePair typePair) => Parent.HasCompatibleTypes(typePair);
public bool HasCompatibleTypes(ITypePair otherTypePair) => this.HasTypesCompatibleWith(otherTypePair);