Skip to content

Commit 59d3940

Browse files
committed
Minor optimization for dynamic type creation in .NET PageFactory
The PageFactory creates a dynamic type which implements the WebDriver interfaces as a means of having a concrete System.Type to proxy. This commit moves that dynamic type creation to a single act, so that additional, unnecssary dynamic types are not created, reducing bloat and memory footprint.
1 parent 689276b commit 59d3940

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

dotnet/src/support/PageObjects/DefaultPageObjectMemberDecorator.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ namespace OpenQA.Selenium.Support.PageObjects
3232
public class DefaultPageObjectMemberDecorator : IPageObjectMemberDecorator
3333
{
3434
private static List<Type> interfacesToBeProxied;
35+
private static Type interfaceProxyType;
3536

3637
private static List<Type> InterfacesToBeProxied
3738
{
@@ -49,6 +50,19 @@ private static List<Type> InterfacesToBeProxied
4950
}
5051
}
5152

53+
private static Type InterfaceProxyType
54+
{
55+
get
56+
{
57+
if (interfaceProxyType == null)
58+
{
59+
interfaceProxyType = CreateTypeForASingleElement();
60+
}
61+
62+
return interfaceProxyType;
63+
}
64+
}
65+
5266
/// <summary>
5367
/// Locates an element or list of elements for a Page Object member, and returns a
5468
/// proxy object for the element or list of elements.
@@ -184,7 +198,7 @@ private static object CreateProxyObject(Type memberType, IElementLocator locator
184198
}
185199
else if (memberType == typeof(IWebElement))
186200
{
187-
proxyObject = WebElementProxy.CreateProxy(CreateTypeForASingleElement(), locator, bys, cache);
201+
proxyObject = WebElementProxy.CreateProxy(InterfaceProxyType, locator, bys, cache);
188202
}
189203
else
190204
{

0 commit comments

Comments
 (0)