public ScalarPropertyBuilder CopyFrom(ScalarProperty source)
        {
            this.ValueGeneration = source.ValueGeneration;
            this.Nullable        = source.Nullable;
            this.PropertyType    = new ClrTypeInfo(source.PropertyType);

            CopyValues(source);

            return(this);
        }
        public ScalarPropertyBuilder CopyFrom(ScalarPropertyBuilder source)
        {
            this.IsExcluded      = source.IsExcluded;
            this.ValueGeneration = source.ValueGeneration;
            this.Nullable        = source.Nullable;
            this.PropertyType    = source.PropertyType;

            CopyValues(source);

            return(this);
        }
Example #3
0
        protected override void CopyValues(ScalarProperty source)
        {
            var enumSource = source as EnumProperty;

            if (enumSource == null)
            {
                throw new NotSupportedException("The provided source was not a EnumPropertyBuilder.");
            }

            EnumTypeInfo          = new ClrTypeInfo(enumSource.EnumType);
            UnderlyingNumericType = enumSource.UnderlyingNumericType;
        }
        public static ScalarPropertyBuilder CreateScalar(string propertyName, Type propertyType)
        {
            var nullable = System.Nullable.GetUnderlyingType(propertyType);

            var typeInfo = new ClrTypeInfo(propertyType);

            var type    = nullable ?? propertyType;
            var numeric = NumericProperty.GetNumericTypeFromClrType(type);

            if (type == typeof(string))
            {
                return(new TextPropertyBuilder {
                    PropertyType = typeInfo, Name = propertyName, Nullable = true, Unicode = true
                });
            }
            else if (numeric.HasValue)
            {
                return(new NumericPropertyBuilder {
                    PropertyType = typeInfo, Name = propertyName, Nullable = nullable != null, NumericType = numeric.Value
                });
            }
            else if (type == typeof(bool))
            {
                return(new BooleanPropertyBuilder {
                    PropertyType = typeInfo, Name = propertyName, Nullable = nullable != null
                });
            }
            else if (type == typeof(byte[]))
            {
                return(new BlobPropertyBuilder {
                    PropertyType = typeInfo, Name = propertyName, Nullable = true
                });
            }
            else if (type == typeof(DateTime))
            {
                return(new DateTimePropertyBuilder {
                    PropertyType = typeInfo, Name = propertyName, Nullable = nullable != null, DateTimeType = DateTimePropertyType.DateTime
                });
            }
            else if (type == typeof(DateTimeOffset))
            {
                return(new DateTimePropertyBuilder {
                    PropertyType = typeInfo, Name = propertyName, Nullable = nullable != null, DateTimeType = DateTimePropertyType.DateTimeOffset
                });
            }
            else if (type == typeof(Guid))
            {
                return(new GuidPropertyBuilder {
                    PropertyType = typeInfo, Name = propertyName, Nullable = nullable != null
                });
            }
            else if (type.GetTypeInfo().IsEnum)
            {
                return(new EnumPropertyBuilder
                {
                    Name = propertyName,
                    PropertyType = typeInfo,
                    Nullable = nullable != null,
                    EnumTypeInfo = new ClrTypeInfo(type),
                    UnderlyingNumericType = NumericProperty.GetNumericTypeFromClrType(Enum.GetUnderlyingType(type)).GetValueOrDefault()
                });
            }

            throw new InvalidOperationException($"PropertyType {type} not supported.");
        }