예제 #1
0
        /// <summary>
        /// 制作程序集
        /// </summary>
        /// <param name="inputRequest"></param>
        /// <returns></returns>
        public AssemblyRespondBean CreatOneAssembly(AssemblyMakeRequest inputRequest)
        {
            //列表保护
            if (null == inputRequest.LstUseTypeMakeRequest)
            {
                inputRequest.LstUseTypeMakeRequest = new List <TypeMakeRequest>();
            }

            AssemblyRespondBean respond = new AssemblyRespondBean();
            var tempAssemblyBuilder     = GetAssemblyBuilder(inputRequest.AssemblyName, inputRequest.AssemblyDir);

            var tempModuleBuilder = GetModuleBuilder(tempAssemblyBuilder, inputRequest.AssemblyName);

            //数据回写
            respond.UseAssembuilder  = tempAssemblyBuilder;
            respond.UseModuleBuilder = tempModuleBuilder;
            respond.LstClassBean     = new List <ClassBuilderBean>();

            foreach (var oneTypeRequest in inputRequest.LstUseTypeMakeRequest)
            {
                ClassBuilderBean typeRespond = new ClassBuilderBean();
                //添加到返回值列表
                respond.LstClassBean.Add(typeRespond);
                typeRespond.UseLstKVPMethodBuilder = new List <KeyValuePair <MethodRequest, MethodBuilder> >();

                //创造类型
                var tempTypeBuilder = CreatType(tempModuleBuilder, oneTypeRequest.TypeName,
                                                oneTypeRequest.ParentType, oneTypeRequest.LstInterfaceType, oneTypeRequest.LstAttribute);
                typeRespond.UseTypeBuilder = tempTypeBuilder;

                Dictionary <FieldBuilder, FiledMakeRequest> fieldDic;
                //创造字段
                AppendFileds(tempTypeBuilder, oneTypeRequest.LstFiled, out fieldDic);

                //字段回写
                typeRespond.UseFiledDic = fieldDic.ToDictionary(k => k.Value.FiledName, k => k.Key);

                //制作方法
                if (null == oneTypeRequest.LstMethodRequest)
                {
                    continue;
                }

                foreach (var oneMethodRequest in oneTypeRequest.LstMethodRequest)
                {
                    MakeMethod(typeRespond, oneMethodRequest);
                }
            }


            return(respond);
        }
예제 #2
0
        /// <summary>
        /// 制作方法
        /// </summary>
        /// <param name="inputClassBuilderBean"></param>
        /// <param name="inputRequest"></param>
        private void MakeMethod(ClassBuilderBean inputClassBuilderBean, MethodRequest inputRequest)
        {
            var tempUseTypeBuilder = inputClassBuilderBean.UseTypeBuilder;

            var tempMethodBuilder = tempUseTypeBuilder.DefineMethod(inputRequest.Name, MethodAttributes.Public | MethodAttributes.Virtual,
                                                                    inputRequest.ReturnType, inputRequest.ParameterTypes);

            inputRequest.UseMethodDel(tempMethodBuilder, inputClassBuilderBean);

            if (null != inputRequest.UseBaseMethod)
            {
                tempUseTypeBuilder.DefineMethodOverride(tempMethodBuilder, inputRequest.UseBaseMethod);
            }

            //生成数据回写
            inputClassBuilderBean.UseLstKVPMethodBuilder.Add
                (new KeyValuePair <MethodRequest, MethodBuilder>(inputRequest, tempMethodBuilder));
        }