Question

I've got a lot of entity classes, and now in all properties of the entity classes need to add new functionality (call some method) in the getters and setters. What i want to say looks like this:

public class PersistentClass : BaseClass {
private string attr1;
[Persistent]
public string Attr1 
{
    get
    {
        //need to call here base class method
        //refreshContents();
        return attr1;
    }
    set
    {
        //need to call here base class method
        //refreshContents();
        attr1 = value;
    }
}

private SomeObject attr2;
[Persistent]
public SomeObject Attr2
{
    get
    {
        //need to call here base class method
        //refreshContents();
        return attr2;
    }
    set
    {
        //need to call here base class method
        //refreshContents();
        attr2 = value;
    }
}

private List<SomeOtherObhect> details;
[Persistent]
pubic List<SomeOtherObject> Details
{
    get
    {
        //need to call here base class method
        //refreshContents("details");
        return details;
    }
    set 
    {
        //need to call here base class method
        //refreshContents("details");
        details = value;
    }
}

}

For different types of fields i need to call different methods e.g. refreshContents() and refreshContetns("fieldName"). I'm looking to solve problem with IoC and Dependency Injection. Could you help me please?

Was it helpful?

Solution

This seems like a use case for Aspect Oriented Programming (AOP).

Here are some links to start with:

OTHER TIPS

What will IoC or DI do in your case?

i think you just want a generic method in base class and call thios method from getters or setters

If you want to keep your refresh logic at one place, and call it differently from your properties, consider implementing INotifyPropertyChanged and handling the PropertyChanged event in your entity class itself and implement the refresh logic there.

However, More important question is why do you want to refresh the contents when a property is set or get? It might help to understand if you provide some real property names.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top