public ElementInstance(ILinkElement instance) { this.instance = instance; invoker = CreateInvoker(instance); // You would do it smarter IsBefore = instance.GetType().BaseType.Name.StartsWith("Before"); IsAfter = instance.GetType().BaseType.Name.StartsWith("After"); if (IsAfter || IsBefore) return; IsSurround = true; }
static IStepInvoker CreateInvoker(ILinkElement step) { var behaviorInterface = step.GetType().GetInterfaces().First(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(ILinkElement <,>)); var invokerType = typeof(StepInvoker <,>).MakeGenericType(behaviorInterface.GetGenericArguments()); return((IStepInvoker)Activator.CreateInstance(invokerType)); }
public ElementInstance(ILinkElement instance) { this.instance = instance; invoker = CreateInvoker(instance); // You would do it smarter IsBefore = instance.GetType().BaseType.Name.StartsWith("Before"); IsAfter = instance.GetType().BaseType.Name.StartsWith("After"); if (IsAfter || IsBefore) { return; } IsSurround = true; }
static IElementInvoker CreateInvoker(ILinkElement step) { var behaviorInterface = step.GetType().GetInterfaces().First(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(ILinkElement<,>)); var invokerType = typeof(ElementInvoker<,>).MakeGenericType(behaviorInterface.GetGenericArguments()); return (IElementInvoker)Activator.CreateInstance(invokerType); }