I have the following interface:
public interface ISearchProperties {
string CurrentUserLocation { get; set; }
string SearchUsername { get; set; }
}
With the following implementations:
public class BroadcastPreviewDto : ISearchProperties {
// other properties
}
public class ProfileSearchDto : ISearchProperties {
// other properties
}
I have the following functions:
public void PrepSearchProperties(ref ProfileSearchDto query) {
// do a bunch of stuff to query here (only on ISearchProperties properties)
}
public void PrepSearchProperties(ref BroadCastPreviewDto query) {
// do a bunch of same stuff to query here (only on ISearchProperties properties)
}
The problem is that this isn't very DRY - the function bodies are exactly the same thing. I tried doing this:
public void PrepSearchProperties(ref ISearchProperties query) {
// do a bunch of stuff to query here
}
But this doesn't quite work unless I declare the original query as ISearchProperties, which strips the implementing class properties.
What pattern can I follow to DRY my code up?
Aucun commentaire:
Enregistrer un commentaire