protected static ActivityVariable <T> GetVariable <T>(Dictionary <ObjectKey, IActivityVariable> collection, ActivityVariable <T> variableDefinition, GetVariablesDelegate getMethod, int id) { IActivityVariable variable; ActivityVariable <T> variableGeneric; if (collection.TryGetValue(variableDefinition.Key, out variable)) { variableGeneric = variable as ActivityVariable <T>; if (variableGeneric == null) //for some reason it has the wrong type, so lets fix it here { variableGeneric = variableDefinition.NewInstance <T>(variable.ValueObj); collection[variableDefinition.Key] = variableGeneric; } } else { variableGeneric = GetVariable(variableDefinition, getMethod, id); collection[variableDefinition.Key] = variableGeneric; } return(variableGeneric); }
protected static ActivityVariable <T> GetVariable <T>(ActivityVariable <T> variableDefinition, GetVariablesDelegate getMethod, int id) { object rawVariable = null; if (id != DummyId) { using (Transaction trans = DatabaseAccess.ForSystemDatabase.GetRequestTransaction()) { using (IDataReader reader = getMethod(trans, variableDefinition.Key, id)) { if (reader.Read()) { rawVariable = RuntimePlatformUtils.ConvertFromString((string)reader["Value"], (string)reader["Data_Type"]); } } } } return((rawVariable != null) ? variableDefinition.NewInstance <T>(rawVariable) : variableDefinition.NewInstance <T>()); }