Ejemplo n.º 1
0
 public Type CompileBaseDefinition()
 {
     if (State == Metadata.State.NotDefined)
     {
         VerificationBaseDefinition(true);
         typeBuilder = moduleBuilder.DefineType(Name, TypeAttributes);
         if (Parent != null)
         {
             typeBuilder.SetParent(Parent);
         }
         foreach (Metadata.Metadata @interface in interfaces)
         {
             typeBuilder.AddInterfaceImplementation(@interface);
         }
         if (genericParameters.Count > 0)
         {
             foreach (GenericTypeParameterBuilder genericBuilder in typeBuilder.DefineGenericParameters(genericParameters.Select(g => g.Name).ToArray()))
             {
                 GenericParameterCreator generericParameterCreator = genericParameters.Single(g => g.Name == genericBuilder.Name);
                 generericParameterCreator.CompileBaseDefinition(genericBuilder);
             }
         }
         foreach (CustomAttributeBuilder customAttribute in customAttributes)
         {
             typeBuilder.SetCustomAttribute(customAttribute);
         }
         State = Metadata.State.BaseDefinition;
         type  = typeBuilder;
         return(type);
     }
     else
     {
         throw new Exception("You already start or finish compilation");
     }
 }
Ejemplo n.º 2
0
        internal void CompileBaseDefinitionDefinition(TypeBuilder typeBuilder)
        {
            VerificationBaseDefinition(true);
            MethodBuilder methodBuilder = typeBuilder.DefineMethod(Name, methodAttributes, callingConventions);

            if (genericParameters.Count > 0)
            {
                foreach (GenericTypeParameterBuilder genericBuilder in methodBuilder.DefineGenericParameters(genericParameters.Select(g => g.Name).ToArray()))
                {
                    GenericParameterCreator genericParameterCreator = genericParameters.Single(g => g.Name == genericBuilder.Name);
                    genericParameterCreator.CompileBaseDefinition(genericBuilder);
                }
            }
            methodBuilder.SetReturnType(returnType);
            if (parameters.Count > 0)
            {
                methodBuilder.SetParameters((from t in parameters select(Type) t).ToArray());
                foreach (ParameterCreator parameter in configurationParameter)
                {
                    parameter.Compile(methodBuilder);
                }
            }
            foreach (ParameterCreator parameter in configurationParameter)
            {
                parameter.Compile(methodBuilder);
            }
            foreach (CustomAttributeBuilder customAttribute in customAttributes)
            {
                methodBuilder.SetCustomAttribute(customAttribute);
            }
            State = Metadata.State.BaseDefinition;
            this.methodBuilder = methodBuilder;
            methodInfo         = methodBuilder;
        }