Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor DesignerHost to replace ArrayList with List<T> #8672

Merged
merged 2 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ internal sealed class DesignerHost : Container, IDesignerLoaderHost2, IDesignerH
private readonly Dictionary<IComponent, IDesigner> _designers; // designer -> component mapping
private readonly EventHandlerList _events; // event list
private DesignerLoader _loader; // the loader that loads our designers
private ICollection _savedSelection; // set of selected components saved across reloads
private List<string> _savedSelection; // set of selected components names saved across reloads
private HostDesigntimeLicenseContext _licenseCtx;
private IDesignerEventService _designerEventService;
private static readonly object s_selfLock = new object();
Expand Down Expand Up @@ -1162,7 +1162,10 @@ Type IDesignerHost.GetType(string typeName)
}

/// <summary>
/// This is called by the designer loader to indicate that the load has terminated. If there were errors, they should be passed in the errorCollection as a collection of exceptions (if they are not exceptions the designer loader host may just call ToString on them). If the load was successful then errorCollection should either be null or contain an empty collection.
/// This is called by the designer loader to indicate that the load has terminated.
/// If there were errors, they should be passed in the errorCollection as a collection of exceptions
/// (if they are not exceptions the designer loader host may just call ToString on them).
/// If the load was successful then errorCollection should either be null or contain an empty collection.
/// </summary>
void IDesignerLoaderHost.EndLoad(string rootClassName, bool successful, ICollection errorCollection)
{
Expand All @@ -1181,13 +1184,13 @@ void IDesignerLoaderHost.EndLoad(string rootClassName, bool successful, ICollect
// If the loader indicated success, but it never created a component, that is an error.
if (successful && _rootComponent is null)
{
ArrayList errorList = new ArrayList();
InvalidOperationException ex = new InvalidOperationException(SR.DesignerHostNoBaseClass)
errorCollection = new List<object>()
{
HelpLink = SR.DesignerHostNoBaseClass
new InvalidOperationException(SR.DesignerHostNoBaseClass)
{
HelpLink = SR.DesignerHostNoBaseClass
}
};
errorList.Add(ex);
errorCollection = errorList;
successful = false;
}

Expand Down Expand Up @@ -1226,16 +1229,12 @@ void IDesignerLoaderHost.EndLoad(string rootClassName, bool successful, ICollect
_state[s_stateLoading] = true;
Unload();

ArrayList errorList = new ArrayList
{
ex
};
if (errorCollection is not null)
errorCollection = errorCollection is null ? new List<object>() : errorCollection.Cast<object>().ToList();
if (errorCollection is List<object> errorList)
{
errorList.AddRange(errorCollection);
errorList.Insert(0, ex);
}

errorCollection = errorList;
successful = false;

_surface?.OnLoaded(successful, errorCollection);
Expand All @@ -1249,7 +1248,7 @@ void IDesignerLoaderHost.EndLoad(string rootClassName, bool successful, ICollect
{
if (GetService(typeof(ISelectionService)) is ISelectionService ss)
{
ArrayList selectedComponents = new ArrayList(_savedSelection.Count);
List<IComponent> selectedComponents = new(_savedSelection.Count);
foreach (string name in _savedSelection)
{
IComponent comp = Components[name];
Expand All @@ -1268,7 +1267,9 @@ void IDesignerLoaderHost.EndLoad(string rootClassName, bool successful, ICollect
}

/// <summary>
/// This is called by the designer loader when it wishes to reload the design document. The reload will happen immediately so the caller should ensure that it is in a state where BeginLoad may be called again.
/// This is called by the designer loader when it wishes to reload the design document.
/// The reload will happen immediately so the caller should ensure that it is in a state
/// where BeginLoad may be called again.
/// </summary>
void IDesignerLoaderHost.Reload()
{
Expand All @@ -1279,12 +1280,12 @@ void IDesignerLoaderHost.Reload()
// Next, stash off the set of selected objects by name. After the reload we will attempt to re-select them.
if (GetService(typeof(ISelectionService)) is ISelectionService ss)
{
ArrayList list = new ArrayList(ss.SelectionCount);
foreach (object o in ss.GetSelectedComponents())
List<string> list = new(ss.SelectionCount);
foreach (object item in ss.GetSelectedComponents())
{
if (o is IComponent comp && comp.Site is not null && comp.Site.Name is not null)
if (item is IComponent component && component.Site is not null && component.Site.Name is not null)
{
list.Add(comp.Site.Name);
list.Add(component.Site.Name);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public override void BeginLoad(IDesignerLoaderHost host)
//
// StartTimingMark();
bool successful = true;
ArrayList localErrorList = null;
List<object> localErrorList = null;
IDesignerLoaderService ls = GetService(typeof(IDesignerLoaderService)) as IDesignerLoaderService;

try
Expand All @@ -224,8 +224,7 @@ public override void BeginLoad(IDesignerLoaderHost host)
e = e.InnerException;
}

localErrorList = new ArrayList();
localErrorList.Add(e);
localErrorList = new() { e };
successful = false;
}

Expand Down