Add IJavascriptObjectRepository.UnRegister

Allows for an object to be removed from the repository, doesn't unbind the object from javascript though
This commit is contained in:
amaitland
2018-07-12 20:31:31 +10:00
parent 383734efdf
commit 37a364c0ad
2 changed files with 22 additions and 0 deletions
+7
View File
@@ -35,6 +35,13 @@ namespace CefSharp
/// and other advanced options though this class.</param>
void Register(string name, object objectToBind, bool isAsync = false, BindingOptions options = null);
/// <summary>
/// UnRegister a bound object from the repository. If you unregister an object that is currently
/// bound in JavaScript then the method/property calls will fail.
/// </summary>
/// <param name="name">object name</param>
/// <returns>returns true if the object was successfully unbound otherwise false.</returns>
bool UnRegister(string name);
/// <summary>
/// Has bound objects
/// </summary>
bool HasBoundObjects { get; }
@@ -160,6 +160,21 @@ namespace CefSharp.Internals
AnalyseObjectForBinding(jsObject, analyseMethods: true, analyseProperties: !isAsync, readPropertyValue: false, camelCaseJavascriptNames: camelCaseJavascriptNames);
}
public bool UnRegister(string name)
{
foreach (var kvp in objects)
{
if(string.Equals(kvp.Value.Name, name, StringComparison.OrdinalIgnoreCase))
{
objects.Remove(kvp.Key);
return true;
}
}
return false;
}
internal bool TryCallMethod(long objectId, string name, object[] parameters, out object result, out string exception)
{
exception = "";