Exemplo n.º 1
0
    public TableMemberModel(
        ITypeModel propertyModel,
        PropertyInfo propertyInfo,
        FlatBufferItemAttribute attribute) : base(propertyModel, propertyInfo, attribute)
    {
        this.DefaultValue   = attribute.DefaultValue;
        this.IsSortedVector = attribute.SortedVector;
        this.IsKey          = attribute.Key;
        this.IsDeprecated   = attribute.Deprecated;
        this.ForceWrite     = attribute.ForceWrite;
        this.IsSharedString = attribute.SharedString;

        if (!propertyModel.IsValidTableMember)
        {
            throw new InvalidFlatBufferDefinitionException($"Table property '{this.FriendlyName}' cannot be part of a flatbuffer table.");
        }

        if (this.DefaultValue is not null && !propertyModel.ValidateDefaultValue(this.DefaultValue))
        {
            throw new InvalidFlatBufferDefinitionException($"Table property '{this.FriendlyName}' declared default value of type {propertyModel.ClrType.Name}, but the value was of type {this.DefaultValue.GetType().GetCompilableTypeName()}. Please ensure that the property is allowed to have a default value and that the types match.");
        }
Exemplo n.º 2
0
        public TableMemberModel(
            ITypeModel propertyModel,
            PropertyInfo propertyInfo,
            ushort index,
            object?defaultValue,
            bool isSortedVector,
            bool isKey,
            bool isDeprecated) : base(propertyModel, propertyInfo, index)
        {
            this.DefaultValue   = defaultValue;
            this.IsSortedVector = isSortedVector;
            this.IsKey          = isKey;
            this.IsDeprecated   = isDeprecated;

            if (!propertyModel.IsValidTableMember)
            {
                throw new InvalidFlatBufferDefinitionException($"Table property {propertyInfo.Name} with type {propertyInfo.PropertyType.Name} cannot be part of a flatbuffer table.");
            }

            if (this.DefaultValue is not null && !propertyModel.ValidateDefaultValue(this.DefaultValue))
            {
                throw new InvalidFlatBufferDefinitionException($"Table property {propertyInfo.Name} declared default value of type {propertyModel.ClrType.Name}, but the value was of type {defaultValue?.GetType()?.Name}. Please ensure that the property is allowed to have a default value and that the types match.");
            }
        }