Skip to content

Commit e777ba5

Browse files
committed
Keep original field name
1 parent 64278c9 commit e777ba5

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/NetTopologySuite.IO.Esri.Shapefile/Dbf/DbfStreamExtensions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ public static Encoding ReadDbfEncoding(this Stream stream)
8484
public static void WriteDbaseFieldDescriptor(this Stream stream, DbfField field, Encoding encoding)
8585
{
8686
encoding = encoding ?? Dbf.DefaultEncoding;
87-
var name = field.Name.PadRight(Dbf.MaxFieldNameLength, char.MinValue); // Field name must have empty space zero-filled
88-
87+
var name = field.OriginalName.PadRight(Dbf.MaxFieldNameLength, char.MinValue); // Field name must have empty space zero-filled
8988

9089
stream.WriteString(name, Dbf.MaxFieldNameLength, encoding);
9190
stream.WriteNullBytes(1);

src/NetTopologySuite.IO.Esri.Shapefile/Dbf/Fields/DbfField.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ namespace NetTopologySuite.IO.Esri.Dbf.Fields
1414
public abstract class DbfField
1515
{
1616
// TODO: Spit DbfField into DbfFieldDefinition (Without Value property) and DbfFieldValue
17-
private readonly string _name;
17+
18+
/// <summary>
19+
/// Original field name
20+
/// </summary>
21+
internal string OriginalName { get; }
22+
1823
/// <summary>
1924
/// Field Name.
2025
/// </summary>
@@ -23,7 +28,7 @@ public string Name
2328
get
2429
{
2530
string suffix = DuplicateCount > 0 ? $"_{DuplicateCount}" : string.Empty;
26-
return $"{_name}{suffix}";
31+
return $"{OriginalName}{suffix}";
2732
}
2833
}
2934

@@ -82,17 +87,12 @@ internal DbfField(string name, DbfType type, int length, int precision)
8287
throw new ArgumentException($"Ivalid dBASE field precision: {precision}.", nameof(precision));
8388
}
8489

85-
_name = name;
90+
OriginalName = name;
8691
FieldType = type;
8792
Length = length;
8893
NumericScale = precision;
8994
}
9095

91-
private bool IsValidFieldNameChar(char c)
92-
{
93-
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || (c >= '0' && c <= '9');
94-
}
95-
9696
/// <inheritdoc/>
9797
public override string ToString()
9898
{

0 commit comments

Comments
 (0)