예제 #1
0
파일: NaturalKey.cs 프로젝트: virajs/dddlib
        /// <summary>
        /// Initializes a new instance of the <see cref="NaturalKey"/> class.
        /// </summary>
        /// <param name="runtimeType">The runtime type.</param>
        /// <param name="propertyName">The property name.</param>
        /// <param name="propertyType">The property type.</param>
        /// <param name="typeAnalyzerService">The type analyzer service.</param>
        //// TODO (Cameron): Should there be another overload?
        public NaturalKey(Type runtimeType, string propertyName, Type propertyType, ITypeAnalyzerService typeAnalyzerService)
            : base(DefaultEqualityComparer)
        {
            Guard.Against.Null(() => runtimeType);
            Guard.Against.Null(() => propertyName); // TODO (Cameron): Or empty!
            Guard.Against.Null(() => propertyType);
            Guard.Against.Null(() => typeAnalyzerService);

            if (!typeAnalyzerService.IsValidEntity(runtimeType))
            {
                throw new BusinessException(
                          string.Format(CultureInfo.InvariantCulture, "The specified runtime type '{0}' is not an entity.", runtimeType));
            }

            if (!typeAnalyzerService.IsValidProperty(runtimeType, propertyName, propertyType))
            {
                throw new BusinessException(
                          string.Format(
                              CultureInfo.InvariantCulture,
                              "Invalid natural key specification. The entity '{0}' does not contain a property named '{1}' of type '{2}'.",
                              runtimeType,
                              propertyName,
                              propertyType));
            }

            this.PropertyName = propertyName;
            this.PropertyType = propertyType;
            this.RuntimeType  = runtimeType;
            this.getValue     = AssignGetValue(runtimeType, propertyName);
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EntityType"/> class.
        /// </summary>
        /// <param name="runtimeType">The runtime type.</param>
        /// <param name="typeAnalyzerService">The type analyzer service.</param>
        public EntityType(Type runtimeType, ITypeAnalyzerService typeAnalyzerService)
            : base(new NaturalKey(typeof(EntityType), "RuntimeType", typeof(Type), DefaultTypeAnalyzerService))
        {
            Guard.Against.Null(() => runtimeType);
            Guard.Against.Null(() => typeAnalyzerService);

            if (!typeAnalyzerService.IsValidEntity(runtimeType))
            {
                throw new BusinessException(
                    string.Format(CultureInfo.InvariantCulture, "The specified runtime type '{0}' is not an entity.", runtimeType));
            }

            this.RuntimeType = runtimeType;
            this.entityNaturalKey = typeAnalyzerService.GetNaturalKey(runtimeType);
            this.Mappings = new MapperCollection();
        }
예제 #3
0
파일: EntityType.cs 프로젝트: virajs/dddlib
        /// <summary>
        /// Initializes a new instance of the <see cref="EntityType"/> class.
        /// </summary>
        /// <param name="runtimeType">The runtime type.</param>
        /// <param name="typeAnalyzerService">The type analyzer service.</param>
        public EntityType(Type runtimeType, ITypeAnalyzerService typeAnalyzerService)
            : base(new NaturalKey(typeof(EntityType), "RuntimeType", typeof(Type), DefaultTypeAnalyzerService))
        {
            Guard.Against.Null(() => runtimeType);
            Guard.Against.Null(() => typeAnalyzerService);

            if (!typeAnalyzerService.IsValidEntity(runtimeType))
            {
                throw new BusinessException(
                          string.Format(CultureInfo.InvariantCulture, "The specified runtime type '{0}' is not an entity.", runtimeType));
            }

            this.RuntimeType      = runtimeType;
            this.entityNaturalKey = typeAnalyzerService.GetNaturalKey(runtimeType);
            this.Mappings         = new MapperCollection();
        }