Skip to content

Commit f6dac8c

Browse files
authored
Add ProjectionsRegistry.RegisterAlias method (#72)
* Add ProjectionsRegistry.RegisterAlias method * Use existing proj name -> key format in existing proj lookup closes #71
1 parent 34628b2 commit f6dac8c

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/ProjNet/CoordinateSystems/Projections/ProjectionsRegistry.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public static void Register(string name, Type type)
7070
if (ci == null)
7171
throw new ArgumentException("The provided type is lacking a suitable constructor", nameof(type));
7272

73-
string key = name.ToLowerInvariant().Replace(' ', '_');
73+
string key = ProjectionNameToRegistryKey(name);
7474
lock (RegistryLock)
7575
{
7676
if (TypeRegistry.ContainsKey(key))
@@ -86,6 +86,29 @@ public static void Register(string name, Type type)
8686
}
8787
}
8888

89+
private static string ProjectionNameToRegistryKey(string name)
90+
{
91+
return name.ToLowerInvariant().Replace(' ', '_');
92+
}
93+
94+
/// <summary>
95+
/// Register an alias for an existing Map.
96+
/// </summary>
97+
/// <param name="aliasName"></param>
98+
/// <param name="existingName"></param>
99+
public static void RegisterAlias(string aliasName, string existingName)
100+
{
101+
lock (RegistryLock)
102+
{
103+
if (!TypeRegistry.TryGetValue(ProjectionNameToRegistryKey(existingName), out var existingProjectionType))
104+
{
105+
throw new ArgumentException($"{existingName} is not a registered projection type");
106+
}
107+
108+
Register(aliasName, existingProjectionType);
109+
}
110+
}
111+
89112
private static Type CheckConstructor(Type type)
90113
{
91114
// find a constructor that accepts exactly one parameter that's an
@@ -106,7 +129,7 @@ private static Type CheckConstructor(Type type)
106129

107130
internal static MathTransform CreateProjection(string className, IEnumerable<ProjectionParameter> parameters)
108131
{
109-
string key = className.ToLowerInvariant().Replace(' ', '_');
132+
string key = ProjectionNameToRegistryKey(className);
110133

111134
Type projectionType;
112135
Type ci;

0 commit comments

Comments
 (0)