Changeset 6025


Ignore:
Timestamp:
04/19/11 10:05:54 (8 years ago)
Author:
mkommend
Message:

#1049: Added a check for abstract types in ValueParameter.CreateDefaultValue.

File:
1 edited

Legend:

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

    r5843 r6025  
    5454    public ValueParameter(string name, string description, T value) : base(name, description, value) { }
    5555    public ValueParameter(string name, string description, T value, bool getsCollected) : base(name, description, value, getsCollected) { }
     56                                                                                 
     57    protected T CreateDefaultValue() {
     58      Type type = typeof(T);
     59      if (type.IsAbstract) return null;
     60      ConstructorInfo defaultConstructor = type.GetConstructor(Type.EmptyTypes);
     61      if (defaultConstructor == null) return null;
    5662
    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;
     63      return (T)defaultConstructor.Invoke(new object[0]);
    6264    }
    6365
Note: See TracChangeset for help on using the changeset viewer.