Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,
I have class placed on the data layer, and it is initially instantiated with basic information.
It exposes a sub object called ExternalSourceData (or a method called Enrich), that calls an external source (consumes time) and instantiates some more data members inside the same object.

Clarification: I haven't used inheritance since this object is exposed to an external project, that uses it as an external assembly. Moreover, I want to clearly differ between the "regular" data members and the "external data source" members.

Thus, that's what I came up with:
List list = new List();
ExposedClass a = new ExposedClass(list); // a has members such as size, date
int size = a.size;
string name = a.name;
.
.

if (LoadFromExternal)
   a.ExternalSourcedData = new ExternalSourceData(externalSourceSessionParms)


and the usage will be:
C#
if (a.ExternalSourcedData != null){
   Guid id = a.ExternalSourcedData.ID;
   .
   .
   .
 }



I want the ExternalSourcedData ctor to use the list passed to a (it also passes over the elements of the list). unfortunately, from what i gather, there's no way to do it on c# (on c++ it would be called "Friend" and in java it could have been solved by using an inner class).

Is anyone familiar with a solution to that problem ? Maybe a design pattern that would make it more acceptable as i don't want to pass the list again to the ExternalSourceData ctor?

Thanks allot.
Posted
Updated 2-Mar-11 22:44pm
v8

1 solution

MSIL
You just need to add a public method for invoking the event. Microsoft already does this for some events such as PerformClick for controls that expose a Click event.

public class CustomGUIElement
{
    public void PerformClick()
    {
        OnClick(EventArgs.Empty);
    }

    protected virtual void OnClick(EventArgs e)
    {
        if (Click != null)
            Click(this, e);
    }
}
You would then do the following inside your example event handler...

public void CustomForm_Click(object sender, MouseEventArgs e)
{
    _elements[0].PerformClick();
}
 
Share this answer
 
Comments
OrenSchwartz 3-Mar-11 5:05am    
Hi thanks !

how would registering to an event help ?
if the assembly user registers to the event, all he'll know is when the enrichment occurred. he would still have to pass the "inner class" the list that i already passed the father.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900