© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
9 replies
SWEETPONY

✅ Is it possible to refactor this methods and create only one?

I have following methods:
static private HashSet<string> GetSubjectsAddresses(                                       
    string channelName,
    IEnumerable<SubjectDto> subjects,
    IReadOnlyDictionary<string, ChannelSettingsDto> channelSettings)                      
{
    var subjectTypeSettings = channelSettings[channelName].SubjectTypeSettings;
    
    var addresses = new HashSet<string>();
   
    foreach (var subject in subjects)                                                    
    {
        if (!subjectTypeSettings.TryGetValue(subject.Type.Id, out var value)) continue;
                                                                                           
        if (subject.CustomFields.FieldValues.TryGetValue(value, out var to))           
        {                                                                                  
            var address = to.ToString();                                                   
                                                                                           
            if (address.IsNotNullOrEmpty())                                              
                addresses.Add(address);                                                  
        }                                                                                  
    }                                                                                      
                                                                                           
    return addresses;                                                                      
} 
static private HashSet<string> GetSubjectsAddresses(                                       
    string channelName,
    IEnumerable<SubjectDto> subjects,
    IReadOnlyDictionary<string, ChannelSettingsDto> channelSettings)                      
{
    var subjectTypeSettings = channelSettings[channelName].SubjectTypeSettings;
    
    var addresses = new HashSet<string>();
   
    foreach (var subject in subjects)                                                    
    {
        if (!subjectTypeSettings.TryGetValue(subject.Type.Id, out var value)) continue;
                                                                                           
        if (subject.CustomFields.FieldValues.TryGetValue(value, out var to))           
        {                                                                                  
            var address = to.ToString();                                                   
                                                                                           
            if (address.IsNotNullOrEmpty())                                              
                addresses.Add(address);                                                  
        }                                                                                  
    }                                                                                      
                                                                                           
    return addresses;                                                                      
} 
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Is it possible to remove those methods ?
C#CC# / help
2y ago
❔ Is it possible to serialize this struct?
C#CC# / help
3y ago
How to refactor and unit test this method.
C#CC# / help
4y ago
How to refactor lots of overloaded methods more smartly?
C#CC# / help
2y ago