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

  • Home
  • SEARCH
  • 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

I have control over the HttpServer but not over the ApplicationServer or the Java
Is there a way to Minimize an external application that I don't have control
I have a control that, upon postback, saves form results back to the database.
I have a control that is created like so: public partial class MYControl :
I have a WCF service hosted for internal clients - we have control of
I'm trying to skin HTML output which I don't have control over. One of
I have tree control object created using CTreeCtrl MFC class. The tree control needs
I have user control named DateTimeUC which has two textboxes on its markup: <asp:TextBox
I have a control where I have to check in which page I am,
I have a control application - using asp.net webservices. I have a timer which

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.