Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 277001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T01:00:21+00:00 2026-05-12T01:00:21+00:00

I have a control and it provides a selection mechanism. However, the items that

  • 0

I have a control and it provides a selection mechanism. However, the items that it selects are not appropriate for general consumption and instead, must be projected into a different type parameterised by date.

In addition to this, there are some controls that want to encapsulate the same information and, more importantly, want to retain a particular selection even if the original control’s selection has changed. Therefore, just chaining methods doesn’t work because the original control’s method will always return the projection of its current selection.

To work around this, I created a property that returns a closure, which performs the projection based on a specific selection. This way, I can encapsulate the projection and protect the real type being projected, but also encapsulate a specific collection. Here is a simplified version of what I have.

public class MySelectionControl
{
  public Func<DateTime, IEnumerable<MyProjectedType>> CreateSelectionForDate
  {
    get
    {
       // Take a copy of the selection before creating the lambda so
       // that the source items won't change if the selection does.
       IEnumerable<MyRealType> copyOfSelection = this.realSelection.ToList();
       return weekEnding =>
          copyOfSelection.Select(x => new MyProjectedType(x, weekEnding));
    }
  }
}

This can then be called like a method as in:

MySelectionControl control = new MySelectionControl();

// Gives the current selection for a given date.
control.CreateSelectionForDate(DateTime.Today);

// Takes a copy of the selection for later use, regardless of
// whether the original selection changes.
var selectedItemsProjection = control.CreateSelectionForDate;

So, is this terrible design or clever use of delegates?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T01:00:22+00:00Added an answer on May 12, 2026 at 1:00 am

    Since the purpose of this arrangement is to provide a context and a method to run from within that context, it would seem better to use it more like this:

    Closure closure = selectionControl.GetClosure(DateTime.Today);
    closure.DateSelection ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First, I'll start off by saying that I do not have control over the
Some code that I don't have control over is overriding the global JSON object
I want to read UTF-8 strings from a server that I have control of,
I have listview control.There is an option to remove selected items.After the user removes
I have a control that look something like this: <asp:DetailsView ID=dvUsers runat=server DataSourceID=odsData DataKeyNames=Id>
I have been playing around with the WPF GridView control (DesktopUI not Silverlight) and
I love the ease that the ASP.NET Ajax control Toolkit provides to ASP.NET developers.
I have a legacy VB6 ActiveX control used in IE to provide control of
I have control, subclassed from CDialogBar, it has some buttons(like on toolbar). When I
In WinForms, you have Control.BeginInvoke() , which means you can marshall a call from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.