/// <summary> /// Transforms the input argument into an output using the provided transformation /// </summary> /// <typeparam name="TOut">The desired output type</typeparam> /// <param name="input">The input parameter</param> /// <param name="startRule">The rule that should be started with. If this is null, an applicable rule is found.</param> /// <param name="context">The context that should be used (must not be null).</param> /// <returns>The output from the transformation</returns> public static TOut Transform <TOut>(object[] input, ITransformationEngineContext context, GeneralTransformationRule startRule) where TOut : class { if (context == null) { throw new ArgumentNullException("context"); } if (input == null) { throw new ArgumentNullException("input"); } var transformation = context.Transformation; if (!transformation.IsInitialized) { transformation.Initialize(); } if (startRule == null) { startRule = context.Transformation.GetRuleForTypeSignature(input.GetTypes(), typeof(TOut)); } else { if (startRule.Transformation != context.Transformation) { ThrowRuleNotPartOfTransformation(); } CheckTransformationRule <TOut>(input, startRule); } return(TransformationRunner.Transform(input, null, startRule, context).Output as TOut); }
public static TOut Transform <TIn, TOut>(TIn input, ITransformationEngineContext context, TransformationRuleBase <TIn, TOut> startRule) where TIn : class where TOut : class { if (context == null) { throw new ArgumentNullException("context"); } var transformation = context.Transformation; if (!transformation.IsInitialized) { transformation.Initialize(); } if (startRule == null) { startRule = context.Transformation.GetRuleForTypeSignature(new Type[] { typeof(TIn) }, typeof(TOut)) as TransformationRuleBase <TIn, TOut>; } else { if (startRule.Transformation != context.Transformation) { ThrowRuleNotPartOfTransformation(); } } return(TransformationRunner.Transform(new object[] { input }, null, startRule, context).Output as TOut); }
public static void Process <TIn>(TIn input, ITransformationEngineContext context, GeneralTransformationRule <TIn> startRule) where TIn : class { if (context == null) { throw new ArgumentNullException("context"); } var transformation = context.Transformation; if (!transformation.IsInitialized) { transformation.Initialize(); } if (startRule == null) { startRule = context.Transformation.GetRulesForInputTypes(new Type[] { typeof(TIn) }).FirstOrDefault() as GeneralTransformationRule <TIn>; } else { if (startRule.Transformation != context.Transformation) { ThrowRuleNotPartOfTransformation(); } } TransformationRunner.Transform(new object[] { input }, null, startRule, context); }
public ISynchronizationContext Synchronize <TLeft, TRight>(SynchronizationRule <TLeft, TRight> startRule, ref TLeft left, ref TRight right, SynchronizationDirection direction, ChangePropagationMode changePropagation) where TLeft : class where TRight : class { if (startRule == null) { throw new ArgumentNullException("startRule"); } Initialize(); var context = new SynchronizationContext(this, direction, changePropagation); switch (direction) { case SynchronizationDirection.LeftToRight: case SynchronizationDirection.LeftToRightForced: case SynchronizationDirection.LeftWins: var c1 = TransformationRunner.Transform(new object[] { left }, right != null ? new Axiom(right) : null, startRule.LeftToRight, context); right = c1.Output as TRight; break; case SynchronizationDirection.RightToLeft: case SynchronizationDirection.RightToLeftForced: case SynchronizationDirection.RightWins: var c2 = TransformationRunner.Transform(new object[] { right }, left != null ? new Axiom(left) : null, startRule.RightToLeft, context); left = c2.Output as TLeft; break; default: throw new ArgumentOutOfRangeException("direction"); } return(context); }