C
C#17mo ago
stigzler

❔ Neat Overloads?

Is there a neater way to do the overloading below?
public void CacheImage(Image image, string path, string filename, Size? resizeTo = null)
{
// Stuff
}
public void CacheImage(string image, string path, string filename, Size? resizeTo = null)
{
if (ImageOperation.IsValidimage(image))
{
CacheImage(Image.FromFile(image), path, filename, resizeTo);
}
}
public void CacheImage(Image image, string path, string filename, Size? resizeTo = null)
{
// Stuff
}
public void CacheImage(string image, string path, string filename, Size? resizeTo = null)
{
if (ImageOperation.IsValidimage(image))
{
CacheImage(Image.FromFile(image), path, filename, resizeTo);
}
}
5 Replies
ero
ero17mo ago
That seems like a perfect use of it to me I would potentially even throw an exception if the image wasn't valid
stigzler
stigzlerOP17mo ago
I just wondered if there was any alternative/shorter syntax for the second method rather than list out the same last 3 parameters in full but guess the full range of parameters may be needed by the interpreter
Sossenbinder
Sossenbinder17mo ago
I guess you could wrap the parameters in a simple class or record so you only have to pass forward a single parameter, just in case the amount of parameter is annoying
stigzler
stigzlerOP17mo ago
yeah - not possible in this use case, but see the reasoning Thanks both
Accord
Accord17mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server