private Expression GetClassContextExpression(ClassContext classContext)
        {
            var classContextCodeGenerator = new CodeGenerationClassContextSerializer();

            classContext.Serialize(classContextCodeGenerator);

            return(classContextCodeGenerator.GetConstructorInvocationExpression());
        }
コード例 #2
0
        /// <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));
        }
コード例 #3
0
        public Expression CreateNewClassContext(ClassContext classContext)
        {
            ArgumentUtility.CheckNotNull("classContext", classContext);

            var serializer = new ExpressionClassContextSerializer();

            classContext.Serialize(serializer);

            return(serializer.CreateNewExpression());
        }
コード例 #4
0
        public static FlatClassContext Create(ClassContext classContext)
        {
            ArgumentUtility.CheckNotNull("classContext", classContext);

            var serializer = new FlatClassContextSerializer();

            classContext.Serialize(serializer);

            return(new FlatClassContext(serializer.Values));
        }
コード例 #5
0
        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));
        }