Click here to Skip to main content
15,889,651 members
Home / Discussions / C#
   

C#

 
AnswerRe: What's The Best Way To Do This? Pin
Gerry Schmitz31-Oct-17 12:08
mveGerry Schmitz31-Oct-17 12:08 
GeneralRe: What's The Best Way To Do This? Pin
Rob Philpott1-Nov-17 3:04
Rob Philpott1-Nov-17 3:04 
GeneralRe: What's The Best Way To Do This? Pin
peterkmx2-Nov-17 3:49
professionalpeterkmx2-Nov-17 3:49 
GeneralRe: What's The Best Way To Do This? Pin
Gerry Schmitz2-Nov-17 5:31
mveGerry Schmitz2-Nov-17 5:31 
AnswerRe: What's The Best Way To Do This? Pin
Pete O'Hanlon31-Oct-17 21:45
mvePete O'Hanlon31-Oct-17 21:45 
GeneralRe: What's The Best Way To Do This? Pin
Kevin Marois1-Nov-17 5:43
professionalKevin Marois1-Nov-17 5:43 
GeneralRe: What's The Best Way To Do This? Pin
Pete O'Hanlon1-Nov-17 5:59
mvePete O'Hanlon1-Nov-17 5:59 
AnswerRe: What's The Best Way To Do This? Pin
Nathan Minier1-Nov-17 1:36
professionalNathan Minier1-Nov-17 1:36 
Ah, the reason I like coding against interfaces instead of abstracts!

I've used this for getters before, but not setters, so that bit is a little up to you. The setter implementation isn't exactly tested.
C#
public interface ISetting
{
   object SettingValue { get; set; }
   object MinValue { get; set; }
   object MaxValue { get; set; }
   string Key { get; set; }
   string Description { get; set; }
}

public class Setting<T> : ISetting
{
   public T SettingValue { get; set; }
   public T MinValue { get; set; }
   public T MaxValue { get; set; }
   public string Key { get; set; }
   public string Description { get; set; }

   object ISetting.SettingValue
   {
      get => SettingValue;
      set {
         var xlate = value as T;
         if(xlate != null)
         {
            SettingValue = t;
         }
         else
         {
            throw new Exception($"Invalid type assignment for Setting<{typeof(T)}>.SettingValue ");
         }
      }
   }

   object ISetting.MinValue 
   {
      get => MinValue;
      set {
         var xlate = value as T;
         if(xlate != null)
         {
            MinValue = t;
         }
         else
         {
            throw new Exception($"Invalid type assignment for Setting<{typeof(T)}>.MinValue");
         }
      }
   }

   object ISetting.MaxValue  
   {
      get => MaxValue;
      set {
         var xlate = value as T;
         if(xlate != null)
         {
            MaxValue= t;
         }
         else
         {
            throw new Exception($"Invalid type assignment for Setting<{typeof(T)}>.MaxValue");
         }
      }
   }
}

public List<ISetting> MySettings { get; set; }
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli

SuggestionRe: What's The Best Way To Do This? Pin
Sascha Lefèvre1-Nov-17 2:01
professionalSascha Lefèvre1-Nov-17 2:01 
GeneralRe: What's The Best Way To Do This? Pin
Nathan Minier1-Nov-17 2:34
professionalNathan Minier1-Nov-17 2:34 
QuestionRe: What's The Best Way To Do This? Pin
Eddy Vluggen1-Nov-17 10:19
professionalEddy Vluggen1-Nov-17 10:19 
AnswerRe: What's The Best Way To Do This? Pin
Wendelius1-Nov-17 10:51
mentorWendelius1-Nov-17 10:51 
QuestionNext generics Problem Pin
Kevin Marois31-Oct-17 6:03
professionalKevin Marois31-Oct-17 6:03 
AnswerRe: Next generics Problem Pin
harold aptroot31-Oct-17 6:11
harold aptroot31-Oct-17 6:11 
GeneralRe: Next generics Problem Pin
Kevin Marois31-Oct-17 6:25
professionalKevin Marois31-Oct-17 6:25 
QuestionHow To Make This Generic Pin
Kevin Marois31-Oct-17 5:02
professionalKevin Marois31-Oct-17 5:02 
AnswerRe: How To Make This Generic Pin
Sascha Lefèvre31-Oct-17 5:43
professionalSascha Lefèvre31-Oct-17 5:43 
GeneralRe: How To Make This Generic Pin
Kevin Marois31-Oct-17 5:55
professionalKevin Marois31-Oct-17 5:55 
QuestionWPF assembly in C# Pin
Benjamin Bruno30-Oct-17 19:36
Benjamin Bruno30-Oct-17 19:36 
AnswerRe: WPF assembly in C# Pin
Mycroft Holmes30-Oct-17 20:30
professionalMycroft Holmes30-Oct-17 20:30 
AnswerRe: WPF assembly in C# Pin
Pete O'Hanlon30-Oct-17 20:31
mvePete O'Hanlon30-Oct-17 20:31 
AnswerRe: WPF assembly in C# Pin
OriginalGriff30-Oct-17 20:37
mveOriginalGriff30-Oct-17 20:37 
AnswerRe: WPF assembly in C# Pin
Gerry Schmitz31-Oct-17 12:17
mveGerry Schmitz31-Oct-17 12:17 
GeneralRe: WPF assembly in C# Pin
peterkmx2-Nov-17 6:29
professionalpeterkmx2-Nov-17 6:29 
QuestionEnum of C# Data Types - byte[] and char[] Pin
Kevin Marois30-Oct-17 12:30
professionalKevin Marois30-Oct-17 12:30 

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.