示例#1
0
 private void SetMethodsToInitialValues(Block generator)
 {
     foreach (Method method in methods)
     {
         generator.LoadArg(0);
         generator.Load(method);
         generator.StoreField(typeBuilder.GetField(method.Name));
     }
 }
示例#2
0
        private void DefineParserConstructor()
        {
            OrderedSet <string> fields = pattern.Fields;

            Type[] parameterTypes = new Type[1 + fields.Count];

            parameterTypes[0] = typeof(Source);

            for (int n = 1; n < parameterTypes.Length; n++)
            {
                parameterTypes[n] = typeof(object);
            }

            ConstructorBuilder builder = typeBuilder.DefineConstructor(
                MethodAttributes.Public,
                CallingConventions.Standard,
                parameterTypes);

            Block generator = new Block();

            // Call the base constructor

            ConstructorInfo baseConstructor
                = typeBuilder.BaseType.GetConstructor(new Type[] { typeof(Source) });

            if (baseConstructor == null)
            {
                throw new Exception();
            }

            generator.LoadArg(0);
            generator.LoadArg(1);
            generator.Call(baseConstructor);

            SetMethodsToInitialValues(generator);

            // Save the fields

            for (int n = 0; n < fields.Count; n++)
            {
                generator.LoadArg(0);
                generator.LoadArg(n + 2);
                generator.StoreField(typeBuilder.GetField(fields[n]));
            }

            generator.Return();

            generator.Build(new ConstructorBuilderProxy(builder));
        }
示例#3
0
        private void DefineParserConstructor()
        {
            OrderedSet<string> fields = pattern.Fields;
            
            Type[] parameterTypes = new Type[1 + fields.Count];
            
            parameterTypes[0] = typeof(Source);
            
            for (int n = 1; n < parameterTypes.Length; n++)
                parameterTypes[n] = typeof(object);

            ConstructorBuilder builder = typeBuilder.DefineConstructor(
                MethodAttributes.Public,
                CallingConventions.Standard,
                parameterTypes);
            
            Block generator = new Block();
            
            // Call the base constructor
            
            ConstructorInfo baseConstructor
                = typeBuilder.BaseType.GetConstructor(new Type[]{typeof(Source)});
            
            if (baseConstructor == null)
                throw new Exception();
            
            generator.LoadArg(0);
            generator.LoadArg(1);
            generator.Call(baseConstructor);
            
            SetMethodsToInitialValues(generator);
            
            // Save the fields
            
            for (int n = 0; n < fields.Count; n++)
            {
                generator.LoadArg(0);
                generator.LoadArg(n + 2);
                generator.StoreField(typeBuilder.GetField(fields[n]));
            }
            
            generator.Return();
            
            generator.Build(new ConstructorBuilderProxy(builder));
        }
示例#4
0
 private void SetMethodsToInitialValues(Block generator)
 {
     foreach (Method method in methods)
     {
         generator.LoadArg(0);
         generator.Load(method);
         generator.StoreField(typeBuilder.GetField(method.Name));
     }
 }