예제 #1
0
        /// <summary>
        /// Generates one public constructor receiving
        /// the <see cref="IInterceptor"/> instance and instantiating a hashtable
        /// </summary>
        protected virtual EasyConstructor GenerateConstructor(ConstructorInfo baseConstructor)
        {
            ArrayList arguments = new ArrayList();

            ArgumentReference arg1 = new ArgumentReference(Context.Interceptor);
            ArgumentReference arg2 = new ArgumentReference(typeof(object[]));

            arguments.Add(arg1);

            ParameterInfo[] parameters = baseConstructor.GetParameters();

            if (Context.HasMixins)
            {
                arguments.Add(arg2);
            }

            ArgumentReference[] originalArguments =
                ArgumentsUtil.ConvertToArgumentReference(parameters);

            arguments.AddRange(originalArguments);

            EasyConstructor constructor = MainTypeBuilder.CreateConstructor(
                (ArgumentReference[])arguments.ToArray(typeof(ArgumentReference)));

            GenerateConstructorCode(constructor.CodeBuilder, arg1, SelfReference.Self, arg2);

            constructor.CodeBuilder.InvokeBaseConstructor(baseConstructor, originalArguments);

            constructor.CodeBuilder.AddStatement(new ReturnStatement());

            return(constructor);
        }
예제 #2
0
        /// <summary>
        /// Generates one public constructor receiving
        /// the <see cref="IInterceptor"/> instance and instantiating a HybridCollection
        /// </summary>
        protected override EasyConstructor GenerateConstructor()
        {
            ArgumentReference arg1 = new ArgumentReference(Context.Interceptor);
            ArgumentReference arg2 = new ArgumentReference(typeof(object));
            ArgumentReference arg3 = new ArgumentReference(typeof(object[]));

            EasyConstructor constructor;

            if (Context.HasMixins)
            {
                constructor = MainTypeBuilder.CreateConstructor(arg1, arg2, arg3);
            }
            else
            {
                constructor = MainTypeBuilder.CreateConstructor(arg1, arg2);
            }

            GenerateConstructorCode(constructor.CodeBuilder, arg1, SelfReference.Self, arg3);

            constructor.CodeBuilder.InvokeBaseConstructor();

            constructor.CodeBuilder.AddStatement(new AssignStatement(
                                                     _targetField, arg2.ToExpression()));

            constructor.CodeBuilder.AddStatement(new ReturnStatement());

            return(constructor);
        }
예제 #3
0
        protected void GenerateSerializationConstructor()
        {
            ArgumentReference arg1 = new ArgumentReference(typeof(SerializationInfo));
            ArgumentReference arg2 = new ArgumentReference(typeof(StreamingContext));

            EasyConstructor constr = MainTypeBuilder.CreateConstructor(arg1, arg2);

            constr.CodeBuilder.AddStatement(new ExpressionStatement(
                                                new ConstructorInvocationExpression(_serializationConstructor,
                                                                                    arg1.ToExpression(), arg2.ToExpression())));

            Type[]     object_arg     = new Type[] { typeof(String), typeof(Type) };
            MethodInfo getValueMethod = typeof(SerializationInfo).GetMethod("GetValue", object_arg);

            VirtualMethodInvocationExpression getInterceptorInvocation =
                new VirtualMethodInvocationExpression(arg1, getValueMethod,
                                                      new FixedReference("__interceptor").ToExpression(),
                                                      new TypeTokenExpression(Context.Interceptor));

            VirtualMethodInvocationExpression getMixinsInvocation =
                new VirtualMethodInvocationExpression(arg1, getValueMethod,
                                                      new FixedReference("__mixins").ToExpression(),
                                                      new TypeTokenExpression(typeof(object[])));

            constr.CodeBuilder.AddStatement(new AssignStatement(
                                                InterceptorField, getInterceptorInvocation));

            constr.CodeBuilder.AddStatement(new AssignStatement(
                                                CacheField, new NewInstanceExpression(
                                                    typeof(HybridDictionary).GetConstructor(new Type[0]))));

            constr.CodeBuilder.AddStatement(new AssignStatement(
                                                MixinField,
                                                getMixinsInvocation));

            // Initialize the delegate fields
            foreach (CallableField field in _cachedFields)
            {
                field.WriteInitialization(constr.CodeBuilder, SelfReference.Self, MixinField);
            }

            constr.CodeBuilder.AddStatement(new ReturnStatement());
        }