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)));
        }
Esempio n. 2
0
        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));
        }
Esempio n. 4
0
        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);
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
 public static bool IsForSourceType(this ITypePair typePair, ITypePair otherTypePair)
 => typePair.IsForSourceType(otherTypePair.SourceType);
Esempio n. 8
0
 public virtual bool HasCompatibleTypes(ITypePair typePair)
 => typePair.HasCompatibleTypes(this, SourceMember, TargetMember);
Esempio n. 9
0
 public override bool HasCompatibleTypes(ITypePair typePair)
 => typePair.HasCompatibleTypes(this, SourceMember, TargetMember);
Esempio n. 10
0
 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);
Esempio n. 12
0
 public static bool IsForAllSourceTypes(this ITypePair typePair)
 => typePair.SourceType == Constants.AllTypes;
Esempio n. 13
0
 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));
 }
Esempio n. 18
0
 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);
Esempio n. 20
0
 private static bool IsForSourceType(this ITypePair typePair, Type sourceType)
 => IsForAllSourceTypes(typePair) || sourceType.IsAssignableTo(typePair.SourceType);
Esempio n. 21
0
 public static bool IsForTargetType(this ITypePair typePair, ITypePair otherTypePair)
 => otherTypePair.TargetType.IsAssignableTo(typePair.TargetType);
Esempio n. 22
0
 private bool HasSameSourceTypeAs(ITypePair typePair) => typePair.SourceType == SourceType;
Esempio n. 23
0
 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);
Esempio n. 26
0
 public bool HasCompatibleTypes(ITypePair otherTypePair)
 => this.HasTypesCompatibleWith(otherTypePair);