Skip to content

Commit f92ee3d

Browse files
committed
Fix Merge Conflicts
2 parents abf2da8 + e58f5d6 commit f92ee3d

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

Json-Rpc/Attributes.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,27 @@ public string JsonMethodName
2424
get { return jsonMethodName; }
2525
}
2626
}
27+
28+
/// <summary>
29+
/// Used to assign JsonRpc parameter name to method argument.
30+
/// </summary>
31+
[AttributeUsage(AttributeTargets.Parameter, Inherited = false, AllowMultiple = false)]
32+
public sealed class JsonRpcParamAttribute : Attribute
33+
{
34+
readonly string jsonParamName;
35+
36+
/// <summary>
37+
/// Used to assign JsonRpc parameter name to method argument.
38+
/// </summary>
39+
/// <param name="jsonParamName">Lets you specify the parameter name as it will be referred to by JsonRpc.</param>
40+
public JsonRpcParamAttribute(string jsonParamName = "")
41+
{
42+
this.jsonParamName = jsonParamName;
43+
}
44+
45+
public string JsonParamName
46+
{
47+
get { return jsonParamName; }
48+
}
49+
}
2750
}

Json-Rpc/ServiceBinder.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,26 @@ public static void bindService<T>(string sessionID, Func<T> serviceFactory)
2424
List<Type> parameterTypeArray = new List<Type>();
2525
for (int i = 0; i < paramzs.Length; i++)
2626
{
27+
string paramName;
28+
var paramAttrs = paramzs[i].GetCustomAttributes(typeof(JsonRpcParamAttribute), false);
29+
if (paramAttrs.Length > 0)
30+
{
31+
paramName = ((JsonRpcParamAttribute)paramAttrs[0]).JsonParamName;
32+
if (string.IsNullOrEmpty(paramName))
33+
{
34+
paramName = paramzs[i].Name;
35+
}
36+
}
37+
else
38+
{
39+
paramName = paramzs[i].Name;
40+
}
2741
// reflection attribute information for optional parameters
2842
//http://stackoverflow.com/questions/2421994/invoking-methods-with-optional-parameters-through-reflection
29-
paras.Add(paramzs[i].Name, paramzs[i].ParameterType);
43+
paras.Add(paramName, paramzs[i].ParameterType);
3044

3145
if (paramzs[i].IsOptional) // if the parameter is an optional, add the default value to our default values dictionary.
32-
defaultValues.Add(paramzs[i].Name, paramzs[i].DefaultValue);
46+
defaultValues.Add(paramName, paramzs[i].DefaultValue);
3347
}
3448

3549
var resType = meth.ReturnType;
@@ -44,6 +58,7 @@ public static void bindService<T>(string sessionID, Func<T> serviceFactory)
4458
handlerSession.MetaData.AddService(methodName, paras, defaultValues, newDel);
4559
}
4660
}
61+
4762
}
4863
public static void bindService<T>(string sessionID) where T : new()
4964
{

0 commit comments

Comments
 (0)