private Expression GetClassContextExpression(ClassContext classContext) { var classContextCodeGenerator = new CodeGenerationClassContextSerializer(); classContext.Serialize(classContextCodeGenerator); return(classContextCodeGenerator.GetConstructorInvocationExpression()); }
/// <summary> /// Creates a <see cref="ConcreteMixedTypeAttribute"/> from a given <see cref="ClassContext"/>. /// </summary> /// <param name="context">The class context describing the concrete mixed type.</param> /// <param name="orderedMixinTypes">The types of the mixins applied to the target class of this attribute in the same order that was used for the /// code generation. The mixin types directly match the mixin types defined by <see cref="TargetClassDefinition.Mixins"/>.</param> /// <returns>A new <see cref="ConcreteMixedTypeAttribute"/> with the <see cref="ClassContextData"/> property holding a serialized version of /// <paramre name="context"/>.</returns> public static ConcreteMixedTypeAttribute FromClassContext(ClassContext context, Type[] orderedMixinTypes) { ArgumentUtility.CheckNotNull("context", context); var serializer = new AttributeClassContextSerializer(); context.Serialize(serializer); return(new ConcreteMixedTypeAttribute(serializer.Values, orderedMixinTypes)); }
public Expression CreateNewClassContext(ClassContext classContext) { ArgumentUtility.CheckNotNull("classContext", classContext); var serializer = new ExpressionClassContextSerializer(); classContext.Serialize(serializer); return(serializer.CreateNewExpression()); }
public static FlatClassContext Create(ClassContext classContext) { ArgumentUtility.CheckNotNull("classContext", classContext); var serializer = new FlatClassContextSerializer(); classContext.Serialize(serializer); return(new FlatClassContext(serializer.Values)); }
public void Serialize() { var serializer = MockRepository.GenerateMock <IClassContextSerializer> (); var context = new ClassContext(typeof(BaseType1), new[] { CreateBT1Mixin1Context() }, new[] { typeof(int), typeof(string) }); context.Serialize(serializer); serializer.AssertWasCalled(mock => mock.AddClassType(context.Type)); serializer.AssertWasCalled(mock => mock.AddMixins(context.Mixins)); serializer.AssertWasCalled(mock => mock.AddComposedInterfaces(context.ComposedInterfaces)); }
public void IntegrationTest() { var referenceMixinContext1 = MixinContextObjectMother.Create(mixinType: typeof(BT1Mixin1)); var referenceMixinContext2 = MixinContextObjectMother.Create(mixinType: typeof(BT1Mixin2)); var referenceClassContext = new ClassContext(typeof(BaseType1), new[] { referenceMixinContext1, referenceMixinContext2 }, new[] { typeof(DateTime) }); var serializer = new CodeGenerationClassContextSerializer(); referenceClassContext.Serialize(serializer); var expression = serializer.GetConstructorInvocationExpression(); var compiledExpression = Expression.Lambda <Func <ClassContext> > (expression).Compile(); var result = compiledExpression(); Assert.That(result, Is.EqualTo(referenceClassContext)); }