Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6013817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:36:13+00:00 2026-05-23T02:36:13+00:00

Still learning my ways around C# generics… is it possible to achieve this functionality?

  • 0

Still learning my ways around C# generics… is it possible to achieve this functionality?

public interface ISetting<T>
{
    void SetSettings(T obj);
    // myTypeHere GetSettings(T obj);
}

public class RadDockSetting : ISetting<CormantRadDock>
{
    public RadDockSetting()
    {
    }

    public RadDockSetting GetSettings(CormantRadDock dock)
    {
    }

    public void SetSettings(CormantRadDock dock)
    {
    }
 }

I realize this is a counter-intuitive way to be using a Getter — shouldn’t have to pass anything to it. What I’m doing is creating an object, RadDockSetting, that stores the relevant properties of the CormantRadDock — and then returns the ‘got’ settings.

GetSettings is currently a static method, but I realize this will need to be refactored in order to allow implementing a getter from the interface. Maybe once this occurs the ‘weirdness’ of the getter will fall away?

So, a little background on all of this:

I started with a class that had a lot of ‘copy/pasted’ functions. These functions were in charge of saving and removing controls from a manager. When I realized this I set out trying to make these functions more generic. I succeeded, with SO’s help, in making remove generic.

For reference, here is remove:

public static void Remove<T>(string controlID) where T: new()
{
    Logger.InfoFormat("Removing control {0}", controlID);
    T states = RadControlStates.GetStates<T>();
    (states as IDictionary).Remove(controlID);
    RadControlStates.SetStates<T>(states);
}

and it is called like so: RadControlSave.Remove<SerializableDictionary<string, RadPaneSetting>>(ID);

Now, I am trying to extend this genericness to the rest of the methods — the savers. Here’s how one of these methods looks currently:

public static void SavePane(CormantRadPane pane)
{
    Logger.InfoFormat("Saving pane {0}", pane.ID);
    RadPaneSetting paneSettings = RadPaneSetting.GetSettings(pane);
    SerializableDictionary<string, RadPaneSetting> paneStates = RadControlStates.GetStates<SerializableDictionary<string, RadPaneSetting>>();

    bool paneIsKnown = paneStates.ContainsKey(paneSettings.ID);

    if (paneIsKnown)
    {
        Logger.Debug("Pane is known. Overwriting data.");
        paneStates[paneSettings.ID] = paneSettings;
    }
    else
    {
        Logger.Debug("Pane is unknown. Saving data.");
        paneStates.Add(paneSettings.ID, paneSettings);
    }

    RadControlStates.SetStates<SerializableDictionary<string, RadPaneSetting>>(paneStates);
}

At the start of this code block there is a call to “RadPaneSetting.GetSettings(pane)”.

RadPaneSettings implements the ISettings interface. Here is ISetting’s setter being used.

/// <summary>
/// Recreates a dashboard control based off of its settings.
/// </summary>
/// <typeparam name="T"> The type of control to be recreated. </typeparam>
/// <param name="settings"> The known settings needed to recreate the control.</param>
/// <returns> The recreated control. </returns>
public static T Recreate<T>(ISetting<T> settings) where T : new()
{
    T _control = new T();
    settings.SetSettings(_control);
    Logger.DebugFormat("Recreated control {0}", (_control as Control).ID);
    return _control;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:36:14+00:00Added an answer on May 23, 2026 at 2:36 am

    It looks like you just need to add another generic parameter here

    public interface ISetting<T1, T2>
    {
        void SetSettings(T1 obj);
        T2 GetSettings(T1 obj);
    }
    
    public class RadDockSettings : ISetting<CormantRadDock, RadDockSetting>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm still learning ASP.NET and I often see code like this throughout parts of
I'm still learning about REST and, in my test, came up with this scenario
This is going to sound like a silly question, but I'm still learning C,
edit: Ok, to put this in a question, I'm asking for possible ways I
Okay I'm still learning the ropes with the Entity Framework and I came across
Forgive my ignorance - still learning here. I am using Eclipse Ganymede (Java 1.5)
I'm still learning Grails and seem to have hit a stumbling block. Here are
I'm still learning the dark arts of TDD and recently I've been trying to
I am a C# developer. Still learning. I had not learn all the features
My company has recently started using Scrum; we've done 2 sprints. We're still learning,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.