public GeneratedProperty(FlatBufferSerializerOptions options, int index, PropertyInfo propertyInfo) { this.options = options; this.propertyInfo = propertyInfo; this.HasValueFieldName = options.PropertyCache ? $"__hasIndex{index}" : null; this.BackingFieldName = !options.Lazy ? $"__index{index}" : null; this.ReadValueMethodName = $"__ReadIndex{index}Value"; }
/// <summary> /// Creates a new FlatBufferSerializer using the given options. /// </summary> public FlatBufferSerializer(FlatBufferSerializerOptions options) { if (options == null) { throw new ArgumentNullException(nameof(options)); } this.Options = options; }
internal static string CreateDeserializeClass( string className, Type baseType, IEnumerable <GeneratedProperty> propertyOverrides, FlatBufferSerializerOptions options) { string inputBufferFieldDef = "private readonly TInputBuffer buffer;"; string offsetFieldDef = "private readonly int offset;"; List <string> ctorStatements = new List <string> { "this.buffer = buffer;", "this.offset = offset;" }; if (options.GreedyDeserialize) { inputBufferFieldDef = string.Empty; offsetFieldDef = string.Empty; ctorStatements.Clear(); } foreach (var property in propertyOverrides) { if (property.MemberModel.IsVirtual) { if (options.GreedyDeserialize) { ctorStatements.Add( $"this.{property.BackingFieldName} = {property.ReadValueMethodName}(buffer, offset);"); } } else { ctorStatements.Add( $"base.{property.MemberModel.PropertyInfo.Name} = {property.ReadValueMethodName}(buffer, offset);"); } } return ($@" private sealed class {className}<TInputBuffer> : {GetCompilableTypeName(baseType)} where TInputBuffer : IInputBuffer {{ {inputBufferFieldDef} {offsetFieldDef} public {className}(TInputBuffer buffer, int offset) {{ {string.Join("\r\n", ctorStatements)} }} {string.Join("\r\n", propertyOverrides)} }} "); }
public ParserCodeGenContext( string inputBufferVariableName, string offsetVariableName, string inputBufferTypeName, IReadOnlyDictionary <Type, string> methodNameMap, FlatBufferSerializerOptions options) { this.InputBufferVariableName = inputBufferVariableName; this.OffsetVariableName = offsetVariableName; this.InputBufferTypeName = inputBufferTypeName; this.MethodNameMap = methodNameMap; this.Options = options; }
public GeneratedProperty(FlatBufferSerializerOptions options, int index, ItemMemberModel memberModel) { this.options = options; this.propertyInfo = memberModel.PropertyInfo; this.MemberModel = memberModel; this.ReadValueMethodName = $"__ReadIndex{index}Value"; if (memberModel.IsVirtual) { this.HasValueFieldName = options.PropertyCache ? $"__hasIndex{index}" : null; this.BackingFieldName = !options.Lazy ? $"__index{index}" : null; } }
public SerializationCodeGenContext( string serializationContextVariableName, string spanVariableName, string spanWriterVariableName, string valueVariableName, string offsetVariableName, IReadOnlyDictionary <Type, string> methodNameMap, FlatBufferSerializerOptions options) { this.SerializationContextVariableName = serializationContextVariableName; this.SpanWriterVariableName = spanWriterVariableName; this.SpanVariableName = spanVariableName; this.ValueVariableName = valueVariableName; this.OffsetVariableName = offsetVariableName; this.MethodNameMap = methodNameMap; this.Options = options; }
internal static string CreateDeserializeClass( string className, Type baseType, IEnumerable <GeneratedProperty> propertyOverrides, FlatBufferSerializerOptions options) { string inputBufferFieldDef = "private readonly TInputBuffer buffer;"; string offsetFieldDef = "private readonly int offset;"; string ctorBody = $@" this.buffer = buffer; this.offset = offset; "; if (options.GreedyDeserialize) { inputBufferFieldDef = string.Empty; offsetFieldDef = string.Empty; ctorBody = string.Join("\r\n", propertyOverrides.Select(x => $"this.{x.BackingFieldName} = {x.ReadValueMethodName}(buffer, offset);")); } return ($@" private sealed class {className}<TInputBuffer> : {CSharpHelpers.GetCompilableTypeName(baseType)} where TInputBuffer : IInputBuffer {{ {inputBufferFieldDef} {offsetFieldDef} public {className}(TInputBuffer buffer, int offset) {{ {ctorBody} }} {string.Join("\r\n", propertyOverrides)} }} "); }
public ParserCodeGenerator(FlatBufferSerializerOptions options, IReadOnlyDictionary <Type, string> methodNames) { this.options = options; this.MethodNames = methodNames; }
public GetMaxSizeCodeGenContext(string valueVariableName, IReadOnlyDictionary <Type, string> methodNameMap, FlatBufferSerializerOptions options) { this.ValueVariableName = valueVariableName; this.MethodNameMap = methodNameMap; this.Options = options; }
/// <summary> /// Creates a new FlatBufferSerializer using the given options and type model provider. /// </summary> public FlatBufferSerializer(FlatBufferSerializerOptions options, TypeModelContainer typeModelContainer) { this.container = typeModelContainer ?? throw new ArgumentNullException(nameof(typeModelContainer)); this.Options = options ?? throw new ArgumentNullException(nameof(options)); }
/// <summary> /// Creates a new FlatBufferSerializer using the given options. /// </summary> public FlatBufferSerializer(FlatBufferSerializerOptions options) : this(options, TypeModelContainer.CreateDefault()) { }