Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/31/17 16:15:08 (7 years ago)
Author:
bburlacu
Message:

#2723: Found a different solution to this issue, by using IList<T> as the return type for the GetValues<T> method.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Dataset.cs

    r14864 r15013  
    7474        throw new ArgumentException(message);
    7575      }
    76       DatasetUtil.ValidateInputData(variableValues); // the validation call checks if every values IList is actually a list of the supported type
    7776      rows = variableValues.First().Count;
    7877      this.variableNames = new List<string>(variableNames);
     
    175174    }
    176175    public IEnumerable<string> DoubleVariables {
    177       get { return variableValues.Where(p => p.Value is List<double>).Select(p => p.Key); }
     176      get { return variableValues.Where(p => p.Value is IList<double>).Select(p => p.Key); }
    178177    }
    179178
    180179    public IEnumerable<string> StringVariables {
    181       get { return variableValues.Where(p => p.Value is List<string>).Select(p => p.Key); }
     180      get { return variableValues.Where(p => p.Value is IList<string>).Select(p => p.Key); }
    182181    }
    183182
     
    194193    public ReadOnlyCollection<double> GetReadOnlyDoubleValues(string variableName) {
    195194      var values = GetValues<double>(variableName);
    196       return values.AsReadOnly();
     195      return new ReadOnlyCollection<double>(values);
    197196    }
    198197    public double GetDoubleValue(string variableName, int row) {
     
    214213    public ReadOnlyCollection<string> GetReadOnlyStringValues(string variableName) {
    215214      var values = GetValues<string>(variableName);
    216       return values.AsReadOnly();
     215      return new ReadOnlyCollection<string>(values);
    217216    }
    218217
     
    221220      return rows.Select(x => values[x]);
    222221    }
    223     private List<T> GetValues<T>(string variableName) {
     222    private IList<T> GetValues<T>(string variableName) {
    224223      IList list;
    225224      if (!variableValues.TryGetValue(variableName, out list))
    226225        throw new ArgumentException("The variable " + variableName + " does not exist in the dataset.");
    227       List<T> values = list as List<T>;
     226      IList<T> values = list as IList<T>;
    228227      if (values == null) throw new ArgumentException("The variable " + variableName + " is not a " + typeof(T) + " variable.");
    229228      return values;
Note: See TracChangeset for help on using the changeset viewer.