/// <param name="requestingType">Type of the class for which to create the field</param> /// <param name="fieldType">FieldType of the field to construct</param> /// <param name="preferredDefaultValue"></param> /// <returns>a new Field of the given fieldType, with the scope of it's value being restricted to the Type scope</returns> public IField CreateField(Type requestingType, IFieldType fieldType, object preferredDefaultValue) { string requestingTypeName = requestingType.Name; string requestedField = requestingTypeName + "." + fieldType.Name; object fieldValue = preferredDefaultValue; // Check if the configuration exists if (LastUsedFieldValues == null) { LastUsedFieldValues = new Dictionary <string, object>(); } // Check if settings for the requesting type exist, if not create! if (LastUsedFieldValues.ContainsKey(requestedField)) { // Check if a value is set (not null)! if (LastUsedFieldValues[requestedField] != null) { fieldValue = LastUsedFieldValues[requestedField]; } else { // Overwrite null value LastUsedFieldValues[requestedField] = fieldValue; } } else { LastUsedFieldValues.Add(requestedField, fieldValue); } return(new Field(fieldType, requestingType) { Value = fieldValue }); }
/// <summary> /// Create a value for the scoped fieldtype, with a preferred default /// </summary> /// <param name="scope">Scope (usually the name of the type) for which to create the field</param> /// <param name="fieldType">FieldType of the field to construct</param> /// <param name="preferredDefaultValue">preferred default</param> /// <returns>a new or cached value for the given fieldType, with the scope of it's value being restricted to the Type scope</returns> public object CreateCachedValue(string scope, FieldTypes fieldType, object preferredDefaultValue) { if (fieldType == FieldTypes.FLAGS) { return(preferredDefaultValue); } string requestedField = scope + "." + fieldType.ToString(); object fieldValue = preferredDefaultValue; // Check if the configuration exists if (LastUsedFieldValues == null) { LastUsedFieldValues = new Dictionary <string, object>(); } // Check if settings for the requesting type exist, if not create! if (LastUsedFieldValues.ContainsKey(requestedField)) { // Check if a value is set (not null)! if (LastUsedFieldValues[requestedField] != null) { fieldValue = LastUsedFieldValues[requestedField]; } else { // Overwrite null value LastUsedFieldValues[requestedField] = fieldValue; } } else { LastUsedFieldValues.Add(requestedField, fieldValue); } return(fieldValue); }
public void UpdateLastFieldValue(IField field) { string requestedField = field.Scope + "." + field.FieldType.Name; // Check if the configuration exists if (LastUsedFieldValues == null) { LastUsedFieldValues = new Dictionary <string, object>(); } // check if settings for the requesting type exist, if not create! if (LastUsedFieldValues.ContainsKey(requestedField)) { LastUsedFieldValues[requestedField] = field.Value; } else { LastUsedFieldValues.Add(requestedField, field.Value); } }
/// <summary> /// Update the cached value for a certain fieldtype /// </summary> /// <param name="scope"></param> /// <param name="fieldType"></param> /// <param name="newValue"></param> public void UpdateCachedValue(string scope, FieldTypes fieldType, object newValue) { if (fieldType == FieldTypes.FLAGS) { return; } string requestedField = scope + "." + fieldType.ToString(); // Check if the configuration exists if (LastUsedFieldValues == null) { LastUsedFieldValues = new Dictionary <string, object>(); } // check if settings for the requesting type exist, if not create! if (LastUsedFieldValues.ContainsKey(requestedField)) { LastUsedFieldValues[requestedField] = newValue; } else { LastUsedFieldValues.Add(requestedField, newValue); } }