public StructMemberModel( ITypeModel propertyModel, PropertyInfo propertyInfo, FlatBufferItemAttribute attribute, int offset, int length) : base(propertyModel, propertyInfo, attribute) { this.Offset = offset; this.Length = length; if (!this.IsVirtual && this.IsWriteThrough) { throw new InvalidFlatBufferDefinitionException($"Struct member '{this.FriendlyName}' declared the WriteThrough attribute, but WriteThrough is only supported on virtual fields."); } if (propertyModel.SerializeMethodRequiresContext) { throw new InvalidFlatBufferDefinitionException($"The type model for struct member '{this.FriendlyName}' requires a serialization context, but Structs do not have one."); } if (attribute.Required) { throw new InvalidFlatBufferDefinitionException($"Struct member '{this.FriendlyName}' declared the Required attribute. Required is not valid inside structs."); } if (attribute.SharedString) { throw new InvalidFlatBufferDefinitionException($"Struct member '{this.FriendlyName}' declared the SharedString attribute. SharedString is not valid inside structs."); } }
protected ItemMemberModel( ITypeModel propertyModel, PropertyInfo propertyInfo, FlatBufferItemAttribute attribute) { var getMethod = propertyInfo.GetMethod; var setMethod = propertyInfo.SetMethod; this.ItemTypeModel = propertyModel; this.PropertyInfo = propertyInfo; this.Index = attribute.Index; this.CustomGetter = attribute.CustomGetter; string declaringType = ""; if (propertyInfo.DeclaringType is not null) { declaringType = CSharpHelpers.GetCompilableTypeName(propertyInfo.DeclaringType); } declaringType = $"{declaringType}.{propertyInfo.Name} (Index {attribute.Index})"; if (getMethod == null) { throw new InvalidFlatBufferDefinitionException($"Property {declaringType} on did not declare a getter."); } if (!getMethod.IsPublic && string.IsNullOrEmpty(this.CustomGetter)) { throw new InvalidFlatBufferDefinitionException($"Property {declaringType} must declare a public getter."); } if (CanBeOverridden(getMethod)) { this.IsVirtual = true; if (!ValidateVirtualPropertyMethod(getMethod, false)) { throw new InvalidFlatBufferDefinitionException($"Property {declaringType} did not declare a public/protected virtual getter."); } if (!ValidateVirtualPropertyMethod(setMethod, true)) { throw new InvalidFlatBufferDefinitionException($"Property {declaringType} declared a set method, but it was not public/protected and virtual."); } } else { if (!ValidateNonVirtualMethod(getMethod)) { throw new InvalidFlatBufferDefinitionException($"Non-virtual property {declaringType} must declare a public and non-abstract getter."); } if (!ValidateNonVirtualMethod(setMethod)) { throw new InvalidFlatBufferDefinitionException($"Non-virtual property {declaringType} must declare a public/protected and non-abstract setter."); } } }
public StructMemberModel( ITypeModel propertyModel, PropertyInfo propertyInfo, FlatBufferItemAttribute attribute, int offset, int length) : base(propertyModel, propertyInfo, attribute) { this.Offset = offset; this.Length = length; }
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."); }