Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/28/11 17:22:36 (13 years ago)
Author:
mkommend
Message:

#1049: Added code to create default values in ValueParameters if possible.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Parameters/3.3/ValueParameter.cs

    r5445 r5843  
    2121
    2222using System;
     23using System.Reflection;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
     
    4344    protected ValueParameter(bool deserializing) : base(deserializing) { }
    4445    protected ValueParameter(ValueParameter<T> original, Cloner cloner) : base(original, cloner) { }
     46
    4547    public ValueParameter() : base() { }
    46     public ValueParameter(string name) : base(name) { }
    47     public ValueParameter(string name, bool getsCollected) : base(name, getsCollected) { }
     48    public ValueParameter(string name) : base(name) { base.Value = CreateDefaultValue(); }
     49    public ValueParameter(string name, bool getsCollected) : base(name, getsCollected) { base.Value = CreateDefaultValue(); }
    4850    public ValueParameter(string name, T value) : base(name, value) { }
    4951    public ValueParameter(string name, T value, bool getsCollected) : base(name, value, getsCollected) { }
    50     public ValueParameter(string name, string description) : base(name, description) { }
    51     public ValueParameter(string name, string description, bool getsCollected) : base(name, description, getsCollected) { }
     52    public ValueParameter(string name, string description) : base(name, description) { base.Value = CreateDefaultValue(); }
     53    public ValueParameter(string name, string description, bool getsCollected) : base(name, description, getsCollected) { base.Value = CreateDefaultValue(); }
    5254    public ValueParameter(string name, string description, T value) : base(name, description, value) { }
    5355    public ValueParameter(string name, string description, T value, bool getsCollected) : base(name, description, value, getsCollected) { }
     56
     57    protected T CreateDefaultValue() {
     58      ConstructorInfo defaultConstructor = typeof(T).GetConstructor(Type.EmptyTypes);
     59      if (defaultConstructor != null)
     60        return (T)defaultConstructor.Invoke(new object[0]);
     61      return null;
     62    }
    5463
    5564    public override IDeepCloneable Clone(Cloner cloner) {
Note: See TracChangeset for help on using the changeset viewer.