Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/13/16 10:38:42 (8 years ago)
Author:
abeham
Message:

#2281: moved type verification to member method

File:
1 edited

Legend:

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

    r14056 r14057  
    171171      string translatedName = Name;
    172172      var value = GetValue(ExecutionContext, ref translatedName);
     173      if (value != null && !(value is T))
     174        throw new InvalidOperationException(
     175          string.Format("Type mismatch. Variable \"{0}\" does not contain a \"{1}\".",
     176                        translatedName,
     177                        typeof(T).GetPrettyName())
     178        );
    173179      CachedActualValue = value;
    174180      return value;
    175181    }
    176182
    177     protected static IItem GetValue(IExecutionContext executionContext, ref string name, bool verifyType = true) {
     183    protected static IItem GetValue(IExecutionContext executionContext, ref string name) {
    178184      // try to get value from context stack
    179185      IValueParameter param = GetValueParameterAndTranslateName(executionContext, ref name);
     
    182188      // try to get variable from scope
    183189      IVariable var = LookupVariable(executionContext.Scope, name);
    184       if (var != null) {
    185         if (verifyType && !(var.Value is T))
    186           throw new InvalidOperationException(
    187             string.Format("Type mismatch. Variable \"{0}\" does not contain a \"{1}\".",
    188                           name,
    189                           typeof(T).GetPrettyName())
    190           );
    191         return var.Value;
    192       }
    193       return null;
     190      return var != null ? var.Value : null;
    194191    }
    195192
Note: See TracChangeset for help on using the changeset viewer.