Skip to content

Instantly share code, notes, and snippets.

@Svetomech
Created November 9, 2016 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Svetomech/683b8b69e997edb414baa6abc1d8c703 to your computer and use it in GitHub Desktop.
Save Svetomech/683b8b69e997edb414baa6abc1d8c703 to your computer and use it in GitHub Desktop.
public static class Populate
{
public static Window[] FromHandles(string[] handles)
{
var windows = new Window[handles.Length];
for (int i = 0; i < windows.Length; ++i)
{
windows[i] = new Window(new IntPtr(Convert.ToInt32(handles[i])));
}
return windows;
}
public static Window[] FromHandles(IntPtr[] handles)
{
var windows = new Window[handles.Length];
for (int i = 0; i < windows.Length; ++i)
{
windows[i] = new Window(handles[i]);
}
return windows;
}
}
@AxelUser
Copy link

        public void Test()
        {
            string[] dataStr = new List<string>().ToArray();
            IntPtr[] data = new List<IntPtr>().ToArray();
            IEnumerable res1 = FromHandles((collection, i) => new Window(new IntPtr(Convert.ToInt32(collection.ElementAt(i)))), dataStr);
            IEnumerable res2 = FromHandles((collection, i) => new Window(collection.ElementAt(i)), data);
        }


        public static ICollection<Window> FromHandles<T>(Func<IEnumerable<T>, int, Window> windowCreator, IEnumerable<T> data)
        {
            var windows = new Window[data.Count()];
            for(int i = 0; i< data.Count(); ++i)
            {
                windows[i] = windowCreator(data, i);
            }
            return windows;
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment