Skip to content

Commit

Permalink
Add ProjectionsRegistry.RegisterAlias method (#72)
Browse files Browse the repository at this point in the history
* Add ProjectionsRegistry.RegisterAlias method
* Use existing proj name -> key format in existing proj lookup

closes #71
  • Loading branch information
jarobbins authored Oct 27, 2020
1 parent 34628b2 commit f6dac8c
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/ProjNet/CoordinateSystems/Projections/ProjectionsRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static void Register(string name, Type type)
if (ci == null)
throw new ArgumentException("The provided type is lacking a suitable constructor", nameof(type));

string key = name.ToLowerInvariant().Replace(' ', '_');
string key = ProjectionNameToRegistryKey(name);
lock (RegistryLock)
{
if (TypeRegistry.ContainsKey(key))
Expand All @@ -86,6 +86,29 @@ public static void Register(string name, Type type)
}
}

private static string ProjectionNameToRegistryKey(string name)
{
return name.ToLowerInvariant().Replace(' ', '_');
}

/// <summary>
/// Register an alias for an existing Map.
/// </summary>
/// <param name="aliasName"></param>
/// <param name="existingName"></param>
public static void RegisterAlias(string aliasName, string existingName)
{
lock (RegistryLock)
{
if (!TypeRegistry.TryGetValue(ProjectionNameToRegistryKey(existingName), out var existingProjectionType))
{
throw new ArgumentException($"{existingName} is not a registered projection type");
}

Register(aliasName, existingProjectionType);
}
}

private static Type CheckConstructor(Type type)
{
// find a constructor that accepts exactly one parameter that's an
Expand All @@ -106,7 +129,7 @@ private static Type CheckConstructor(Type type)

internal static MathTransform CreateProjection(string className, IEnumerable<ProjectionParameter> parameters)
{
string key = className.ToLowerInvariant().Replace(' ', '_');
string key = ProjectionNameToRegistryKey(className);

Type projectionType;
Type ci;
Expand Down

0 comments on commit f6dac8c

Please sign in to comment.