From e777ba52839dd470c5ac75197605d0e32f613d5e Mon Sep 17 00:00:00 2001 From: FObermaier Date: Tue, 17 Sep 2024 10:09:51 +0200 Subject: [PATCH] Keep original field name --- .../Dbf/DbfStreamExtensions.cs | 3 +-- .../Dbf/Fields/DbfField.cs | 16 ++++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/NetTopologySuite.IO.Esri.Shapefile/Dbf/DbfStreamExtensions.cs b/src/NetTopologySuite.IO.Esri.Shapefile/Dbf/DbfStreamExtensions.cs index 2578e60..ea1aec2 100644 --- a/src/NetTopologySuite.IO.Esri.Shapefile/Dbf/DbfStreamExtensions.cs +++ b/src/NetTopologySuite.IO.Esri.Shapefile/Dbf/DbfStreamExtensions.cs @@ -84,8 +84,7 @@ public static Encoding ReadDbfEncoding(this Stream stream) public static void WriteDbaseFieldDescriptor(this Stream stream, DbfField field, Encoding encoding) { encoding = encoding ?? Dbf.DefaultEncoding; - var name = field.Name.PadRight(Dbf.MaxFieldNameLength, char.MinValue); // Field name must have empty space zero-filled - + var name = field.OriginalName.PadRight(Dbf.MaxFieldNameLength, char.MinValue); // Field name must have empty space zero-filled stream.WriteString(name, Dbf.MaxFieldNameLength, encoding); stream.WriteNullBytes(1); diff --git a/src/NetTopologySuite.IO.Esri.Shapefile/Dbf/Fields/DbfField.cs b/src/NetTopologySuite.IO.Esri.Shapefile/Dbf/Fields/DbfField.cs index 5d8a603..089612e 100644 --- a/src/NetTopologySuite.IO.Esri.Shapefile/Dbf/Fields/DbfField.cs +++ b/src/NetTopologySuite.IO.Esri.Shapefile/Dbf/Fields/DbfField.cs @@ -14,7 +14,12 @@ namespace NetTopologySuite.IO.Esri.Dbf.Fields public abstract class DbfField { // TODO: Spit DbfField into DbfFieldDefinition (Without Value property) and DbfFieldValue - private readonly string _name; + + /// + /// Original field name + /// + internal string OriginalName { get; } + /// /// Field Name. /// @@ -23,7 +28,7 @@ public string Name get { string suffix = DuplicateCount > 0 ? $"_{DuplicateCount}" : string.Empty; - return $"{_name}{suffix}"; + return $"{OriginalName}{suffix}"; } } @@ -82,17 +87,12 @@ internal DbfField(string name, DbfType type, int length, int precision) throw new ArgumentException($"Ivalid dBASE field precision: {precision}.", nameof(precision)); } - _name = name; + OriginalName = name; FieldType = type; Length = length; NumericScale = precision; } - private bool IsValidFieldNameChar(char c) - { - return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || (c >= '0' && c <= '9'); - } - /// public override string ToString() {