Example #1
0
        /// <summary>
        /// 解析类型参数映射集合(默认以定义参数类型名称为键名)。
        /// </summary>
        /// <param name="accessorTypeImplementation">给定的访问器类型实现。</param>
        /// <param name="accessorMapping">输出访问器 <see cref="TypeParameterMapping"/>。</param>
        /// <returns>返回 <see cref="TypeParameterMappingCollection"/>。</returns>
        public static TypeParameterMappingCollection ParseCollection(Type accessorTypeImplementation,
                                                                     out TypeParameterMapping accessorMapping)
        {
            var accessorTypeDefinition = typeof(IDataAccessor <, , , ,>);

            // 因访问器默认服务类型为 IAccessor,所以不强制实现访问器泛型类型定义
            if (!accessorTypeImplementation.IsImplementedInterfaceType(accessorTypeDefinition, out var resultType))
            {
                accessorMapping = null;
                return(null);
            }

            accessorMapping = new TypeParameterMapping(accessorTypeDefinition, accessorTypeImplementation);

            var mappings = TypeParameterMappingHelper.ParseCollection(accessorTypeDefinition, resultType);

            mappings.TryFindTypeDefinitionFromValuesAndAddMapping(typeof(IGenerativeIdentifier <>));
            mappings.TryFindTypeDefinitionFromValuesAndAddMapping(typeof(IIncrementalIdentifier <>));
            mappings.TryFindTypeDefinitionFromValuesAndAddMapping(typeof(ICreation <,>));

            return(mappings);
        }
Example #2
0
 /// <summary>
 /// 构造一个 <see cref="AccessorTypeParameterMapper"/>。
 /// </summary>
 /// <param name="accessor">给定的访问器 <see cref="TypeParameterMapping"/>。</param>
 /// <param name="mappings">给定的 <see cref="TypeParameterMappingCollection"/>。</param>
 public AccessorTypeParameterMapper(TypeParameterMapping accessor,
                                    TypeParameterMappingCollection mappings)
     : base(mappings)
 {
     Accessor = accessor.NotNull(nameof(accessor));
 }