Skip to content

Commit

Permalink
IProvider: minor incompatible changes funcName() -> procName()
Browse files Browse the repository at this point in the history
* `string funcName(string name);` has been renamed to `string procName(string name);` - as a common method for getting full lpProcName with main prefix etc.

The new name is more suitable for unified work with exported functions and for new support of variables, etc.
  • Loading branch information
3F committed Dec 24, 2016
1 parent 4d7d834 commit 21603c1
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 29 deletions.
16 changes: 9 additions & 7 deletions Conari/Core/IBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace net.r_eg.Conari.Core
public interface IBinder
{
/// <summary>
/// Binds the exported function.
/// Binds the exported Function. Full name is required.
/// </summary>
/// <typeparam name="T">Type of delegate.</typeparam>
/// <param name="lpProcName">The full name of exported function.</param>
Expand All @@ -43,25 +43,27 @@ public interface IBinder

/// <summary>
/// Alias `bindFunc&lt;Action&gt;(string lpProcName)`
/// Binds the exported function.
/// Binds the exported Function. Full name is required.
/// </summary>
/// <param name="lpProcName">The full name of exported function.</param>
/// <returns>Delegate of exported function.</returns>
Action bindFunc(string lpProcName);

/// <summary>
/// Binds the exported C API Function.
/// Binds the exported Function.
/// The main prefix will affects on this result.
/// </summary>
/// <typeparam name="T">Type of delegate.</typeparam>
/// <param name="func">The name of exported C API function.</param>
/// <param name="func">The name of exported function.</param>
/// <returns>Delegate of exported function.</returns>
T bind<T>(string func) where T : class;

/// <summary>
/// Alias `bind&lt;Action&gt;(string func)`
/// Binds the exported C API Function.
/// Binds the exported Function.
/// The main prefix will affects on this result.
/// </summary>
/// <param name="func">The name of exported C API function.</param>
/// <param name="func">The name of exported function.</param>
/// <returns>Delegate of exported function.</returns>
Action bind(string func);

Expand All @@ -83,7 +85,7 @@ public interface IBinder
/// It's recommended as a more efficient,
/// because it allows caching of all MethodInfo for the same signatures but different function names.
///
/// Use IProvider.funcName() to same control of IProvider.Prefix if needed.
/// Use IProvider.procName() to same control of IProvider.Prefix if needed.
/// </summary>
/// <param name="mi">Prepared signature.</param>
/// <param name="name">Valid function name.</param>
Expand Down
6 changes: 3 additions & 3 deletions Conari/Core/IProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public interface IProvider: IBinder, IMem
bool Mangling { get; set; }

/// <summary>
/// Returns full name of exported function.
/// Returns full lpProcName with main prefix etc.
/// </summary>
/// <param name="name">short function name.</param>
string funcName(string name);
/// <param name="name">Exported function or variable name.</param>
string procName(string name);
}
}
26 changes: 14 additions & 12 deletions Conari/Core/Provider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public bool Mangling
}

/// <summary>
/// Binds the exported function.
/// Binds the exported Function. Full name is required.
/// </summary>
/// <typeparam name="T">Type of delegate.</typeparam>
/// <param name="lpProcName">The full name of exported function.</param>
Expand All @@ -108,7 +108,7 @@ public T bindFunc<T>(string lpProcName) where T : class

/// <summary>
/// Alias `bindFunc&lt;Action&gt;(string lpProcName)`
/// Binds the exported function.
/// Binds the exported Function. Full name is required.
/// </summary>
/// <param name="lpProcName">The full name of exported function.</param>
/// <returns>Delegate of exported function.</returns>
Expand All @@ -118,21 +118,23 @@ public Action bindFunc(string lpProcName)
}

/// <summary>
/// Binds the exported C API Function.
/// Binds the exported Function.
/// The main prefix will affects on this result.
/// </summary>
/// <typeparam name="T">Type of delegate.</typeparam>
/// <param name="func">The name of exported C API function.</param>
/// <param name="func">The name of exported function.</param>
/// <returns>Delegate of exported function.</returns>
public T bind<T>(string func) where T : class
{
return bindFunc<T>(funcName(func));
return bindFunc<T>(procName(func));
}

/// <summary>
/// Alias `bind&lt;Action&gt;(string func)`
/// Binds the exported C API Function.
/// Binds the exported Function.
/// The main prefix will affects on this result.
/// </summary>
/// <param name="func">The name of exported C API function.</param>
/// <param name="func">The name of exported function.</param>
/// <returns>Delegate of exported function.</returns>
public Action bind(string func)
{
Expand All @@ -147,7 +149,7 @@ public Action bind(string func)
///// <returns>Complete information to create delegates or to invoke methods.</returns>
//public TDyn bind(MethodInfo mi, bool prefix = false)
//{
// string func = prefix ? funcName(mi.Name) : mi.Name;
// string func = prefix ? procName(mi.Name) : mi.Name;
// return wire(mi, func);
//}

Expand Down Expand Up @@ -228,14 +230,14 @@ public Method bind(string func, Type ret, params Type[] args)
/// <returns>Delegate of exported function.</returns>
public Method<T, object> bind<T>(string func, Type ret, params Type[] args)
{
return bindFunc<T>(funcName(func), ret, args);
return bindFunc<T>(procName(func), ret, args);
}

/// <summary>
/// Returns full name of exported function.
/// Returns full lpProcName with main prefix etc.
/// </summary>
/// <param name="name">short function name.</param>
public virtual string funcName(string name)
/// <param name="name">Exported function or variable name.</param>
public virtual string procName(string name)
{
if(String.IsNullOrWhiteSpace(name)) {
throw new ArgumentException("The function name cannot be empty or null.");
Expand Down
2 changes: 1 addition & 1 deletion Conari/Core/ProviderDLR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, o

Type[] tGeneric = getGenericArgTypes(binder).ToArray();
MethodInfo mi = getmi(binder.Name, tGeneric, tArgs);
TDyn dyn = provider.bind(mi, provider.funcName(binder.Name), Convention);
TDyn dyn = provider.bind(mi, provider.procName(binder.Name), Convention);

// Boxing types, for example: NullType -> null -> NullType

Expand Down
12 changes: 6 additions & 6 deletions ConariTest/ConariLTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ public void funcNameTest1()
var l = new ConariL(new Config("") { LazyLoading = true });

try {
l.funcName("");
l.procName("");
Assert.Fail("1");
}
catch(Exception ex) { Assert.IsTrue(ex.GetType() == typeof(ArgumentException), ex.GetType().ToString()); }

try {
l.funcName(null);
l.procName(null);
Assert.Fail("2");
}
catch(Exception ex) { Assert.IsTrue(ex.GetType() == typeof(ArgumentException), ex.GetType().ToString()); }
Expand All @@ -77,10 +77,10 @@ public void funcNameTest2()
string func = "name1";

l.Prefix = "test_";
Assert.AreEqual($"test_{func}", l.funcName(func));
Assert.AreEqual($"test_{func}", l.procName(func));

l.Prefix = "new_";
Assert.AreEqual($"new_{func}", l.funcName(func));
Assert.AreEqual($"new_{func}", l.procName(func));
}
}

Expand All @@ -93,10 +93,10 @@ public void funcNameTest3()
}, "test3_"))
{
string func = "name2";
Assert.AreEqual($"test3_{func}", l.funcName(func));
Assert.AreEqual($"test3_{func}", l.procName(func));

l.Prefix = null;
Assert.AreEqual(func, l.funcName(func));
Assert.AreEqual(func, l.procName(func));
}
}

Expand Down

0 comments on commit 21603c1

Please sign in to comment.