Ejemplo n.º 1
0
 private void AddRelatedTypesToRetPack(ServicePack retPack, ServicePack propServicePack)
 {
     foreach (var relatedType in propServicePack.RelatedTypes)
     {
         retPack.AddRelatedType(relatedType.Key, relatedType.Value);
     }
 }
Ejemplo n.º 2
0
        public ServicePack Pack()
        {
            var retPack = new ServicePack();

            if (!TryToGetFromGlobalContainer(targetType, out Type matchType))
            {
                matchType = CreateMatchType(retPack);
            }

            retPack.SetMatchType(matchType);

            retPack.AddRelatedType(matchType, targetType);

            return(retPack);
        }
Ejemplo n.º 3
0
        private Type WrapForArraysOrGenerics(Type type, ServicePack retPack, Type matchType)
        {
            Type retType = null;

            if (type.IsGenericType)
            {
                var typeToWrap = matchType ?? type.GetGenericArguments()[0];
                retType = type.GetGenericTypeDefinition().MakeGenericType(new[] { typeToWrap });
            }

            if (type.IsArray)
            {
                var typeToWrap = matchType ?? type.GetElementType();
                retType = typeToWrap.MakeArrayType();
            }

            if (matchType != null && retType != null)
            {
                retPack.AddRelatedType(retType, type);
            }

            return(retType);
        }
Ejemplo n.º 4
0
        private Type MapType(Type type, ServicePack retPack)
        {
            Type matchType = null;

            if (CheckMapPossiblity(type, out Type typeToMap))
            {
                if (retPack.RelatedTypes.Values.Any(sType => sType.Equals(typeToMap)))
                {
                    matchType = retPack.RelatedTypes.Single(kVT => kVT.Value.Equals(typeToMap)).Key;
                }
                else if (TryToGetFromGlobalContainer(type, out Type gottenMatchType))
                {
                    matchType = gottenMatchType;

                    retPack.AddRelatedType(matchType, type);
                }
                else
                {
                    var propMatcher = new ServiceMatcher(typeToMap, TypeCategories.Dto, optimizationPackage: optimizationPackage);

                    SetInvolvedTypesAttributes(propMatcher);

                    SetInvolvedTypeMembersAttributes(propMatcher);

                    var propServicePack = propMatcher.Pack();

                    matchType = propServicePack.MatchType;

                    AddRelatedTypesToRetPack(retPack, propServicePack);
                }
            }

            matchType = WrapForArraysOrGenerics(type, retPack, matchType);

            return(matchType ?? type);
        }