public void Execute() { try { var genericListInstance = _genericTypeCreator.CreateInstanceFor(typeof(List <>), _fieldInfo.FieldType.GenericTypeArguments); var command = new SetFieldCommand(_object, _collectionName, genericListInstance); command.Execute(); AddElementsTo(genericListInstance.GetType()); } catch (Exception ex) { throw new FluentBuilderException(string.Format("Failed setting collection \"{0}\" - Object \"{1}\"", _collectionName, _object.GetType()), ex); } }
private void InitializeField(FieldInfo fieldInfo) { try { var defaultValueGenerator = fieldInfo.FieldType.GetDefaultValueGenerator(); var defaultValue = defaultValueGenerator.GetDefaultValueFor(fieldInfo.FieldType); if (defaultValue == null) { return; } var command = new SetFieldCommand(_object, fieldInfo.Name, defaultValue); command.Execute(); } catch (Exception ex) { throw new FluentBuilderException(string.Format("Failed setting default value for field \"{0}\" - Object \"{1}\"", fieldInfo.Name, _object.GetType()), ex); } }