Click here to Skip to main content
15,901,505 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: do you use extension methods intensively in your projects? Pin
  Forogar  16-Oct-16 3:26
professional  Forogar  16-Oct-16 3:26 
GeneralRe: do you use extension methods intensively in your projects? Pin
Chris Maunder16-Oct-16 13:37
cofounderChris Maunder16-Oct-16 13:37 
GeneralRe: do you use extension methods intensively in your projects? Pin
Fabio Franco17-Oct-16 0:21
professionalFabio Franco17-Oct-16 0:21 
GeneralRe: do you use extension methods intensively in your projects? Pin
Chris Maunder17-Oct-16 4:41
cofounderChris Maunder17-Oct-16 4:41 
GeneralRe: do you use extension methods intensively in your projects? Pin
Fabio Franco17-Oct-16 0:19
professionalFabio Franco17-Oct-16 0:19 
GeneralRe: do you use extension methods intensively in your projects? Pin
PSU Steve17-Oct-16 2:49
professionalPSU Steve17-Oct-16 2:49 
GeneralRe: do you use extension methods intensively in your projects? Pin
Harley L. Pebley17-Oct-16 5:11
Harley L. Pebley17-Oct-16 5:11 
GeneralRe: do you use extension methods intensively in your projects? Pin
Matthew Dennis17-Oct-16 5:42
sysadminMatthew Dennis17-Oct-16 5:42 
I have a .NET Core based Redis Client that I've been working on for a while that heavily uses extension methods. The 'client' just knows how to send a command and receive a response.

All the Redis commands are implemented as extension methods on the 'client'. So as static class for the Key Commands, another for the Hash Commands, ...

in Redis Client
C#
/// <summary>
/// Sends a command and returns the response string.
/// </summary>
/// <param name="command">The Command.</param>
/// <param name="parameters">The parameters.</param>
/// <returns>The response.</returns>
public Task SendAsync(string command, params object[] parameters)
{
    return SendAsync(command, (IEnumerable<object>)parameters);
}

/// <summary>
/// Sends a command and returns the response string.
/// </summary>
/// <param name="command">The Command.</param>
/// <param name="parameters">The parameters.</param>
/// <returns>The awaitable Task.</returns>
public async Task SendAsync(string command, IEnumerable<object> parameters = null)
{
    await EnsureConnected().ConfigureAwait(false);
    await _commandWriter.WriteRedisCommandAsync(command, parameters).ConfigureAwait(false);
}


in HashCommands
C#
public static Task SendHGetAsync(this RedisClient client, string key, string field)
{
    if (string.IsNullOrWhiteSpace(key))
        throw new ArgumentNullException(nameof(key));

    if (string.IsNullOrWhiteSpace(field))
        throw new ArgumentNullException(nameof(field));

    return client.SendAsync("HGet", key, field);
}



Each commands are small and trivial. The core client has no tricky dependencies on the commands. Classic Open for Extension but Closed for Modification.

What has been delaying me is the number of tests to test all the commands, plus an update to the latest .NET Core bits.

Another great thing about Extension Methods is the ability to extend 3rd party libraries.
"Time flies like an arrow. Fruit flies like a banana."

GeneralRe: do you use extension methods intensively in your projects? Pin
Jim Balter17-Oct-16 6:49
Jim Balter17-Oct-16 6:49 
GeneralRe: do you use extension methods intensively in your projects? Pin
Robert g Blair17-Oct-16 14:30
Robert g Blair17-Oct-16 14:30 
GeneralRe: do you use extension methods intensively in your projects? Pin
mbb0119-Oct-16 23:14
mbb0119-Oct-16 23:14 
GeneralIt's not even Halloween yet... Pin
R. Giskard Reventlov14-Oct-16 12:54
R. Giskard Reventlov14-Oct-16 12:54 
GeneralRe: It's not even Halloween yet... Pin
Marc Clifton15-Oct-16 3:16
mvaMarc Clifton15-Oct-16 3:16 
GeneralRe: It's not even Halloween yet... Pin
Kschuler17-Oct-16 3:38
Kschuler17-Oct-16 3:38 
General*IGMO Pin
GenJerDan14-Oct-16 6:06
GenJerDan14-Oct-16 6:06 
GeneralRe: *IGMO Pin
devenv.exe14-Oct-16 6:35
professionaldevenv.exe14-Oct-16 6:35 
GeneralRe: *IGMO Pin
GenJerDan14-Oct-16 6:39
GenJerDan14-Oct-16 6:39 
GeneralRe: *IGMO Pin
Ravi Bhavnani14-Oct-16 8:23
professionalRavi Bhavnani14-Oct-16 8:23 
GeneralRe: *IGMO Pin
CDP180214-Oct-16 6:57
CDP180214-Oct-16 6:57 
GeneralRe: *IGMO Pin
kmoorevs14-Oct-16 8:01
kmoorevs14-Oct-16 8:01 
GeneralRe: *IGMO Pin
GenJerDan14-Oct-16 8:15
GenJerDan14-Oct-16 8:15 
GeneralRe: *IGMO Pin
kmoorevs14-Oct-16 8:51
kmoorevs14-Oct-16 8:51 
GeneralRe: *IGMO Pin
GenJerDan14-Oct-16 8:56
GenJerDan14-Oct-16 8:56 
GeneralRe: *IGMO Pin
Eddy Vluggen14-Oct-16 10:22
professionalEddy Vluggen14-Oct-16 10:22 
GeneralThought of the day PinPopular
OriginalGriff14-Oct-16 5:04
mveOriginalGriff14-Oct-16 5:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.