Ejemplo n.º 1
0
            public SyncAsyncDefiner(WhatItShouldBe whatItShouldBe)
            {
                if (whatItShouldBe.HasFlag(WhatItShouldBe.IsSync))
                {
                    BaseGenericDtoType            = typeof(EfGenericDto <,>);
                    _serviceReplaceString         = UpdateServiceReplaceString;
                    _serviceAssemblyQualifiedName = UpdateServiceAssemblyQualifiedName;
                }
                else if (whatItShouldBe.HasFlag(WhatItShouldBe.IsAsync))
                {
                    BaseGenericDtoType            = typeof(EfGenericDtoAsync <,>);
                    _serviceReplaceString         = UpdateServiceAsyncReplaceString;
                    _serviceAssemblyQualifiedName = UpdateServiceAsyncAssemblyQualifiedName;
                }
                else
                {
                    throw new InvalidOperationException("Neither the IsSync or the IsAsync flags were set.");
                }

                //If any type allowed we test against base
                if (!whatItShouldBe.HasFlag(WhatItShouldBe.SpecificDto))
                {
                    BaseGenericDtoType = typeof(EfGenericDtoBase <,>);
                }
            }
Ejemplo n.º 2
0
        /// <summary>
        /// This decodes the type and returns an array of types. If the type is based on a GenericDto
        /// then it returns the Data type and the
        /// </summary>
        /// <typeparam name="TD"></typeparam>
        /// <param name="whatItShouldBe"></param>
        /// <param name="syncAsync"></param>
        /// <returns></returns>
        private static Type[] GetTypesFromInitialType <TD>(WhatItShouldBe whatItShouldBe, SyncAsyncDefiner syncAsync)
            where TD : class
        {
            var classType = typeof(TD);

            Type[] dataTypes;
            if (classType.IsSubclassOf(typeof(EfGenericDtoBase)))
            {
                dataTypes = GetGenericTypesIfCorrectGeneric(classType, syncAsync.BaseGenericDtoType);
                if (dataTypes == null)
                {
                    throw new InvalidOperationException(string.Format("This service needs a class which inherited from {0}.",
                                                                      syncAsync.BaseGenericDtoType.Name));
                }
            }
            else if (!whatItShouldBe.HasFlag(WhatItShouldBe.DataClass))
            {
                throw new InvalidOperationException("This type of service only works with some form of EfGenericDto.");
            }
            else
            {
                //Its a data class
                dataTypes = new[] { typeof(TD) };
            }
            return(dataTypes);
        }