Skip to content

Commit

Permalink
Minor optimization for dynamic type creation in .NET PageFactory
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jimevans committed Mar 27, 2015
1 parent 689276b commit 59d3940
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace OpenQA.Selenium.Support.PageObjects
public class DefaultPageObjectMemberDecorator : IPageObjectMemberDecorator
{
private static List<Type> interfacesToBeProxied;
private static Type interfaceProxyType;

private static List<Type> InterfacesToBeProxied
{
Expand All @@ -49,6 +50,19 @@ private static List<Type> InterfacesToBeProxied
}
}

private static Type InterfaceProxyType
{
get
{
if (interfaceProxyType == null)
{
interfaceProxyType = CreateTypeForASingleElement();
}

return interfaceProxyType;
}
}

/// <summary>
/// Locates an element or list of elements for a Page Object member, and returns a
/// proxy object for the element or list of elements.
Expand Down Expand Up @@ -184,7 +198,7 @@ private static object CreateProxyObject(Type memberType, IElementLocator locator
}
else if (memberType == typeof(IWebElement))
{
proxyObject = WebElementProxy.CreateProxy(CreateTypeForASingleElement(), locator, bys, cache);
proxyObject = WebElementProxy.CreateProxy(InterfaceProxyType, locator, bys, cache);
}
else
{
Expand Down

0 comments on commit 59d3940

Please sign in to comment.