Skip to content

Commit 454fdb8

Browse files
committed
Add IJavascriptObjectRepository.UnRegister
Allows for an object to be removed from the repository, doesn't unbind the object from javascript though
1 parent 0e9d980 commit 454fdb8

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

CefSharp/IJavascriptObjectRepository.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ public interface IJavascriptObjectRepository : IDisposable
3535
/// and other advanced options though this class.</param>
3636
void Register(string name, object objectToBind, bool isAsync = false, BindingOptions options = null);
3737
/// <summary>
38+
/// UnRegister a bound object from the repository. If you unregister an object that is currently
39+
/// bound in JavaScript then the method/property calls will fail.
40+
/// </summary>
41+
/// <param name="name">object name</param>
42+
/// <returns>returns true if the object was successfully unbound otherwise false.</returns>
43+
bool UnRegister(string name);
44+
/// <summary>
3845
/// Has bound objects
3946
/// </summary>
4047
bool HasBoundObjects { get; }

CefSharp/Internals/JavascriptObjectRepository.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,21 @@ public void Register(string name, object value, bool isAsync, BindingOptions opt
160160
AnalyseObjectForBinding(jsObject, analyseMethods: true, analyseProperties: !isAsync, readPropertyValue: false, camelCaseJavascriptNames: camelCaseJavascriptNames);
161161
}
162162

163+
public bool UnRegister(string name)
164+
{
165+
foreach (var kvp in objects)
166+
{
167+
if(string.Equals(kvp.Value.Name, name, StringComparison.OrdinalIgnoreCase))
168+
{
169+
objects.Remove(kvp.Key);
170+
171+
return true;
172+
}
173+
}
174+
175+
return false;
176+
}
177+
163178
internal bool TryCallMethod(long objectId, string name, object[] parameters, out object result, out string exception)
164179
{
165180
exception = "";

0 commit comments

Comments
 (0)