public CodeExpression TryGenerate(ICodeDomContext context, Type behaviorType) { if (behaviorType != typeof(ReprocessBehavior)) { return(null); } ReprocessAttribute attribute = context.HandlerType.GetCustomAttribute <ReprocessAttribute>(); if (attribute == null) { return(null); } double delay = attribute.DelayBeforeReprocess.TotalMilliseconds; if (delay > 0) { return(new CodeObjectCreateExpression( new CodeTypeReference(typeof(ReprocessBehavior)), new CodePrimitiveExpression(attribute.Count), new CodeMethodInvokeExpression( new CodeTypeReferenceExpression(typeof(TimeSpan)), "FromMilliseconds", new CodePrimitiveExpression(delay) ) )); } return(new CodeObjectCreateExpression( new CodeTypeReference(typeof(ReprocessBehavior)), new CodePrimitiveExpression(attribute.Count) )); }
public object TryCreate(IReflectionBehaviorFactoryContext context, Type behaviorType) { if (behaviorType != typeof(ReprocessBehavior)) { return(null); } ReprocessAttribute attribute = context.HandlerType.GetCustomAttribute <ReprocessAttribute>(); if (attribute == null) { return(null); } TimeSpan delay = attribute.DelayBeforeReprocess; if (delay != TimeSpan.Zero) { return(new ReprocessBehavior(attribute.Count, delay)); } return(new ReprocessBehavior(attribute.Count)); }