From d860446727b046e6f561a45f2fdf8123b20799b0 Mon Sep 17 00:00:00 2001 From: James Courtney Date: Sun, 15 Oct 2023 23:23:17 -0700 Subject: [PATCH] Add global namespace test --- .../CloneMethodsGenerator.cs | 2 +- .../SchemaModel/TableSchemaModel.cs | 4 ++-- .../GlobalNamespaceBlocker.cs | 21 +++++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 src/Tests/FlatSharpEndToEndTests/GlobalNamespaceBlocker.cs diff --git a/src/FlatSharp.Compiler/CloneMethodsGenerator.cs b/src/FlatSharp.Compiler/CloneMethodsGenerator.cs index 782a0dd8..56293579 100644 --- a/src/FlatSharp.Compiler/CloneMethodsGenerator.cs +++ b/src/FlatSharp.Compiler/CloneMethodsGenerator.cs @@ -34,7 +34,7 @@ public static string GenerateCloneMethodsForAssembly( string className = $"CloneHelpers_{Guid.NewGuid():n}"; string methodName = "Clone"; - string fullyQualifiedMethodName = $"{@namespace}.{className}.{methodName}"; + string fullyQualifiedMethodName = $"global::{@namespace}.{className}.{methodName}"; HashSet seenTypes = new HashSet(); foreach (var type in assembly.GetTypes()) diff --git a/src/FlatSharp.Compiler/SchemaModel/TableSchemaModel.cs b/src/FlatSharp.Compiler/SchemaModel/TableSchemaModel.cs index 2a5f452a..c25a3a4a 100644 --- a/src/FlatSharp.Compiler/SchemaModel/TableSchemaModel.cs +++ b/src/FlatSharp.Compiler/SchemaModel/TableSchemaModel.cs @@ -64,7 +64,7 @@ protected override void EmitExtraData(CodeWriter writer, CompileContext context) string optionTypeName = typeof(FlatBufferDeserializationOption).GetGlobalCompilableTypeName(); - writer.AppendLine($"public static ISerializer<{this.FullName}> Serializer {{ get; }} = new {ns}.{name}().AsISerializer({optionTypeName}.{this.Attributes.DeserializationOption.Value});"); + writer.AppendLine($"public static ISerializer<{this.FullName}> Serializer {{ get; }} = new global::{ns}.{name}().AsISerializer({optionTypeName}.{this.Attributes.DeserializationOption.Value});"); writer.AppendLine(); @@ -75,7 +75,7 @@ protected override void EmitExtraData(CodeWriter writer, CompileContext context) foreach (var option in new[] { FlatBufferDeserializationOption.Lazy, FlatBufferDeserializationOption.Greedy, FlatBufferDeserializationOption.GreedyMutable, FlatBufferDeserializationOption.Progressive }) { - string staticAbstractMethod = $"static ISerializer<{this.FullName}> {nameof(IFlatBufferSerializable)}<{this.FullName}>.{option}Serializer {{ get; }} = new {ns}.{name}().AsISerializer({optionTypeName}.{option});"; + string staticAbstractMethod = $"static ISerializer<{this.FullName}> {nameof(IFlatBufferSerializable)}<{this.FullName}>.{option}Serializer {{ get; }} = new global::{ns}.{name}().AsISerializer({optionTypeName}.{option});"; writer.BeginPreprocessorIf(CSharpHelpers.Net7PreprocessorVariable, staticAbstractMethod).Flush(); } } diff --git a/src/Tests/FlatSharpEndToEndTests/GlobalNamespaceBlocker.cs b/src/Tests/FlatSharpEndToEndTests/GlobalNamespaceBlocker.cs new file mode 100644 index 00000000..55c8a5ab --- /dev/null +++ b/src/Tests/FlatSharpEndToEndTests/GlobalNamespaceBlocker.cs @@ -0,0 +1,21 @@ +/* + * Copyright 2023 James Courtney + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace FlatSharpEndToEndTests.FlatSharp; + +public static class Fake +{ +} \ No newline at end of file