/// <summary> /// Resolve object from context. /// </summary> /// <param name="context"></param> /// <returns></returns> public object Resolve(IBuilderContext context) { object value; StepSynchronizationManager.GetContext().GetStepExecutionContext().TryGetValue(_propertyName, out value); if (value == null) { throw new InvalidOperationException(string.Format("Failed to get property {0} in step context.", _propertyName)); } return(value is T ? (T)value : StringConverter.Convert <T>(value.ToString())); }
private static void RegisterDestructionCallback(Tuple <Type, string> key, object instance) { var disposable = instance as IDisposable; if (disposable != null) { var name = key.Item1.FullName + ':' + key.Item2; StepSynchronizationManager.GetContext().RegisterDestructionCallback(name, new Task(() => { disposable.Dispose(); })); } }
/// <summary> /// Stores an object for the current step. /// </summary> /// <param name="newValue">the object to store</param> public override void SetValue(object newValue) { if (!(newValue is IProxyObject)) { Context.SetAttribute(_name, newValue); var disposable = newValue as IDisposable; if (disposable != null) { StepSynchronizationManager.GetContext().RegisterDestructionCallback(_name, new Task(() => { disposable.Dispose(); })); } } }