Skip to content

Commit 27c822e

Browse files
committed
Stop using Encoding when we already have a string
Everything that has an unnecessary Encoding is now marked Obsolete. Fixes #33
1 parent a08b6ae commit 27c822e

File tree

6 files changed

+35
-27
lines changed

6 files changed

+35
-27
lines changed

ProjNet.Tests/CoordinateSystemServicesTest.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Diagnostics;
44
using System.IO;
55
using System.Linq;
6-
using System.Text;
76
using System.Threading;
87
using System.Xml.Linq;
98
using NUnit.Framework;
@@ -17,7 +16,7 @@ public class CoordinateSystemServicesTest
1716
[Test]
1817
public void TestConstructor()
1918
{
20-
var css = new CoordinateSystemServices(new CoordinateSystemFactory(Encoding.UTF8),
19+
var css = new CoordinateSystemServices(new CoordinateSystemFactory(),
2120
new CoordinateTransformationFactory());
2221

2322
Assert.IsNotNull(css.GetCoordinateSystem(4326));
@@ -30,7 +29,7 @@ public void TestConstructorLoadXml(string xmlPath)
3029
if (!File.Exists(xmlPath))
3130
throw new IgnoreException("Specified file not found");
3231

33-
var css = new CoordinateSystemServices(new CoordinateSystemFactory(Encoding.UTF8),
32+
var css = new CoordinateSystemServices(new CoordinateSystemFactory(),
3433
new CoordinateTransformationFactory(), LoadXml(xmlPath));
3534

3635
Assert.IsNotNull(css.GetCoordinateSystem(4326));
@@ -46,7 +45,7 @@ public void TestConstructorLoadCsv(string csvPath)
4645
if (!File.Exists(csvPath))
4746
throw new IgnoreException("Specified file not found");
4847

49-
var css = new CoordinateSystemServices(new CoordinateSystemFactory(Encoding.UTF8),
48+
var css = new CoordinateSystemServices(new CoordinateSystemFactory(),
5049
new CoordinateTransformationFactory(), LoadCsv(csvPath));
5150

5251
Assert.IsNotNull(css.GetCoordinateSystem(4326));

ProjNet.Tests/CoordinateTransformTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -861,8 +861,8 @@ public void Test_EPSG_21780_PrimeMeredianTransformation()
861861
double[] sourceCoord = new double[] { 160443.329034, 23582.55586 };
862862
double[] expectedTargetCoord = new double[] { 9.5553588867188, 47.145080566406 };
863863

864-
ICoordinateSystem cs1 = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(wkt21780, System.Text.Encoding.Default) as ICoordinateSystem;
865-
ICoordinateSystem cs2 = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(wkt4326, System.Text.Encoding.Default) as ICoordinateSystem;
864+
ICoordinateSystem cs1 = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(wkt21780) as ICoordinateSystem;
865+
ICoordinateSystem cs2 = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(wkt4326) as ICoordinateSystem;
866866
CoordinateTransformationFactory ctf = new CoordinateTransformationFactory();
867867
var ict = ctf.CreateFromCoordinateSystems(cs1, cs2);
868868

ProjNet.Tests/WKT/WKTMathTransformParserTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void ParseAffineTransformWkt ()
3434
try
3535
{
3636
//TODO replace with MathTransformFactory implementation
37-
mt = MathTransformWktReader.Parse (wkt, System.Text.Encoding.Unicode);
37+
mt = MathTransformWktReader.Parse (wkt);
3838
}
3939
catch (Exception ex)
4040
{
@@ -69,7 +69,7 @@ public void TestMathTransformWktReaderExponencialNumberParsingIssue(string wkt)
6969
try
7070
{
7171
//TODO replace with MathTransformFactory implementation
72-
mt = MathTransformWktReader.Parse (wkt, System.Text.Encoding.Unicode);
72+
mt = MathTransformWktReader.Parse (wkt);
7373
}
7474
catch (ArgumentException ex)
7575
{

ProjNet/CoordinateSystems/CoordinateSystemFactory.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,14 @@ namespace ProjNet.CoordinateSystems
4040
/// </remarks>
4141
public class CoordinateSystemFactory : ICoordinateSystemFactory
4242
{
43+
[Obsolete("The encoding is no longer used and will be removed in a future release.")]
4344
public Encoding Encoding { get; private set; }
4445

45-
public CoordinateSystemFactory() : this(Encoding.UTF8) { }
46+
public CoordinateSystemFactory() { }
4647

48+
[Obsolete("The encoding is no longer used and will be removed in a future release.")]
4749
public CoordinateSystemFactory(Encoding encoding)
4850
{
49-
if (encoding == null)
50-
throw new ArgumentNullException("encoding");
51-
5251
Encoding = encoding;
5352
}
5453

@@ -71,7 +70,7 @@ public ICoordinateSystem CreateFromXml(string xml)
7170
/// <returns>The resulting spatial reference object</returns>
7271
public ICoordinateSystem CreateFromWkt(string WKT)
7372
{
74-
IInfo info = CoordinateSystemWktReader.Parse(WKT, Encoding);
73+
IInfo info = CoordinateSystemWktReader.Parse(WKT);
7574
return info as ICoordinateSystem;
7675
}
7776

ProjNet/IO/CoordinateSystems/CoordinateSystemWktReader.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,24 @@ public static class CoordinateSystemWktReader
5454
/// Reads and parses a WKT-formatted projection string.
5555
/// </summary>
5656
/// <param name="wkt">String containing WKT.</param>
57-
/// <param name="encoding">The encoding to use.</param>
57+
/// <param name="encoding">The parameter is not used.</param>
5858
/// <returns>Object representation of the WKT.</returns>
5959
/// <exception cref="System.ArgumentException">If a token is not recognised.</exception>
60-
public static IInfo Parse(string wkt, Encoding encoding)
60+
[Obsolete("The encoding is no longer used and will be removed in a future release.")]
61+
public static IInfo Parse(string wkt, Encoding encoding) => Parse(wkt);
62+
63+
/// <summary>
64+
/// Reads and parses a WKT-formatted projection string.
65+
/// </summary>
66+
/// <param name="wkt">String containing WKT.</param>
67+
/// <returns>Object representation of the WKT.</returns>
68+
/// <exception cref="System.ArgumentException">If a token is not recognised.</exception>
69+
public static IInfo Parse(string wkt)
6170
{
6271
if (String.IsNullOrEmpty(wkt))
6372
throw new ArgumentNullException("wkt");
64-
if (encoding == null)
65-
throw new ArgumentNullException("encoding");
6673

67-
byte[] arr = encoding.GetBytes(wkt);
68-
using (Stream stream = new MemoryStream(arr))
69-
using (TextReader reader = new StreamReader(stream, encoding))
74+
using (TextReader reader = new StringReader(wkt))
7075
{
7176
WktStreamTokenizer tokenizer = new WktStreamTokenizer(reader);
7277
tokenizer.NextToken();

ProjNet/IO/CoordinateSystems/MathTransformWktReader.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,24 @@ public static class MathTransformWktReader
5555
/// Reads and parses a WKT-formatted projection string.
5656
/// </summary>
5757
/// <param name="wkt">String containing WKT.</param>
58-
/// <param name="encoding">The encoding to use.</param>
58+
/// <param name="encoding">The parameter is not used.</param>
5959
/// <returns>Object representation of the WKT.</returns>
6060
/// <exception cref="System.ArgumentException">If a token is not recognised.</exception>
61-
public static IMathTransform Parse (string wkt, Encoding encoding)
61+
[Obsolete("The encoding is no longer used and will be removed in a future release.")]
62+
public static IMathTransform Parse (string wkt, Encoding encoding) => Parse(wkt);
63+
64+
/// <summary>
65+
/// Reads and parses a WKT-formatted projection string.
66+
/// </summary>
67+
/// <param name="wkt">String containing WKT.</param>
68+
/// <returns>Object representation of the WKT.</returns>
69+
/// <exception cref="System.ArgumentException">If a token is not recognised.</exception>
70+
public static IMathTransform Parse (string wkt)
6271
{
6372
if (String.IsNullOrEmpty (wkt))
6473
throw new ArgumentNullException ("wkt");
65-
if (encoding == null)
66-
throw new ArgumentNullException ("encoding");
6774

68-
byte[] arr = encoding.GetBytes (wkt);
69-
using (Stream stream = new MemoryStream (arr))
70-
using (TextReader reader = new StreamReader (stream, encoding))
75+
using (TextReader reader = new StringReader (wkt))
7176
{
7277
WktStreamTokenizer tokenizer = new WktStreamTokenizer (reader);
7378
tokenizer.NextToken ();

0 commit comments

Comments
 (0)