Change new paramAray test methods in BindingTest.html to execute immediately (same as all the majority)

Revert changes to NuGet.config
Remove unused using statement from ScriptedMethodsBoundObject
Rename JavascriptMethod.Parameters to just JavascriptMethod.Parameters (it's in the context of the method so naming was redundant)
Pre compute HasParamArray for minor (very minor) performance improvement - relevant when executing method many times in a tight loop
This commit is contained in:
amaitland
2016-04-05 16:19:55 +10:00
parent 7cf5f17565
commit 669404f74c
6 changed files with 26 additions and 44 deletions
+3 -3
View File
@@ -279,15 +279,15 @@ namespace CefSharp.Example
/// <param name="args">Params Argument</param>
public string MethodWithParams(string name, params object[] args)
{
return String.Join(", ", args.ToArray());
return "Name:" + name + ";Args:" + string.Join(", ", args.ToArray());
}
public string MethodWithoutParams(string name, string arg2)
{
return String.Format("{0}, {1}", name, arg2);
return string.Format("{0}, {1}", name, arg2);
}
public string methodWithoutAnything()
public string MethodWithoutAnything()
{
return "Method without anything called and returned successfully.";
}
+5 -24
View File
@@ -240,31 +240,12 @@
<p>
Javascript function sending variable number of parameters to Bound Object. (ParamArray Test)
<script type="text/javascript">
function invokeParamArrayMethod(func) {
var result = func();
document.getElementById('paramArrayResults').innerHTML = result;
}
document.write(bound.methodWithParams('With 1 Params', 'hello-world') + "<br/>");
document.write(bound.methodWithParams('With 2 Params', 'hello-world', 'chris was here') + "<br/>");
document.write(bound.methodWithParams('With no Params') + "<br/>");
document.write(bound.methodWithoutParams('Normal Method', 'hello') + "<br/>");
document.write(bound.methodWithoutAnything() + "<br/>");
</script>
<ul>
<li style="list-style:none;display:inline-block;">
<button onclick="invokeParamArrayMethod(function(){return bound.methodWithParams('test', 'hello-world')})">With 1 Params</button>
</li>
<li style="list-style:none;display:inline-block;">
<button onclick="invokeParamArrayMethod(function(){return bound.methodWithParams('test', 'hello-world', 'chris was here')})">With 2 Params</button>
</li>
<li style="list-style:none;display:inline-block;">
<button onclick="invokeParamArrayMethod(function(){return bound.methodWithParams('test')})">With no Params</button>
</li>
<li style="list-style:none;display:inline-block;">
<button onclick="invokeParamArrayMethod(function(){return bound.methodWithoutParams('test', 'hello')})">Normal Method</button>
</li>
<li style="list-style:none;display:inline-block;">
<button onclick="invokeParamArrayMethod(function(){return bound.methodWithoutAnything()})">Normal Method No Params</button>
</li>
</ul>
<span>ParamArray Results</span>
<br />
<span id="paramArrayResults"></span>
</p>
</body>
</html>
@@ -2,7 +2,6 @@
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
using System;
using System.Linq;
namespace CefSharp.Example
{
+6 -1
View File
@@ -34,7 +34,12 @@ namespace CefSharp.Internals
[DataMember]
public string JavascriptName { get; set; }
public List<MethodParameter> MethodParameters { get; set; }
/// <summary>
/// Params this method expects
/// </summary>
public List<MethodParameter> Parameters { get; set; }
public bool HasParamArray { get;set; }
/// <summary>
/// Number of Params this function exepects
@@ -104,32 +104,32 @@ namespace CefSharp.Internals
try
{
//Added param array support. Current implementation support param Object only. 04/04/2016
//Added param array support #1644
var missingParams = method.ParameterCount - parameters.Length;
//CONDITION #1 : Check for parameter count missmatch between the parameters on the javascript function and the
// number of parameters on the bound object method.
// number of parameters on the bound object method. (This is relevant for methods that have default values)
//CONDITION #2 : Check if the bound object method contains a ParamArray as the last parameter on the method signature.
if (missingParams > 0 || method.MethodParameters.LastOrDefault(t => t.IsParamArray) != null)
if (missingParams > 0 || method.HasParamArray)
{
var paramList = new List<object>(method.MethodParameters.Count);
var paramList = new List<object>(method.Parameters.Count);
//Loop through all of the method parameters on the bound object.
for (var i = 0; i < method.MethodParameters.Count; i++)
for (var i = 0; i < method.Parameters.Count; i++)
{
//Attempt to get the javascript function param at the current bound object parameter index.
//If the javascript function param is missing IE: NULL, then add Type.Missing.
//This will allow for default bound object parameters. IE: (string someParameter = "someValue")
object jsParam = parameters.ElementAtOrDefault(i);
if (jsParam == null && !method.MethodParameters[i].IsParamArray)
var jsParam = parameters.ElementAtOrDefault(i);
if (jsParam == null && !method.Parameters[i].IsParamArray)
{
paramList.Add(Type.Missing);
}
//If the method parameter is a paramArray IE: (params Object[] someParameter)
//grab the parameters from the javascript function starting at the current bound object parameter index
//and add create an array that will be passed in as the last bound object method parameter.
else if (method.MethodParameters[i].IsParamArray)
else if (method.Parameters[i].IsParamArray)
{
List<object> convertedParams = new List<object>();
var convertedParams = new List<object>();
for (var s = i; s < parameters.Length; s++)
{
convertedParams.Add(parameters[s]);
@@ -314,12 +314,13 @@ namespace CefSharp.Internals
jsMethod.JavascriptName = GetJavascriptName(methodInfo.Name, camelCaseJavascriptNames);
jsMethod.Function = methodInfo.Invoke;
jsMethod.ParameterCount = methodInfo.GetParameters().Length;
jsMethod.MethodParameters = methodInfo.GetParameters()
jsMethod.Parameters = methodInfo.GetParameters()
.Select(t => new MethodParameter()
{
IsParamArray = t.GetCustomAttributes(typeof(ParamArrayAttribute), false).Length > 0
}).ToList();
//Pre compute HasParamArray for a very minor performance gain
jsMethod.HasParamArray = jsMethod.Parameters.LastOrDefault(t => t.IsParamArray) != null;
return jsMethod;
}
-4
View File
@@ -5,9 +5,5 @@
</activePackageSource>
<packageSources>
<add key="cefsharp-myget" value="https://www.myget.org/F/cefsharp/" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
<disabledPackageSources>
<add key="nuget.org" value="true" />
</disabledPackageSources>
</configuration>