예제 #1
0
 public MethodInfo GetMethod(RepItem key, bool forceRebuild)
 {
     if (forceRebuild || !_objs.TryGetValue(key, out MethodInfo mi))
     {
         mi         = CsBuilder.GetMethod(key);
         _objs[key] = mi;
     }
     return(mi);
 }
예제 #2
0
        private void cfgTree_AfterSelect(object sender, TreeViewEventArgs e)
        {
            _isSetting = true;
            RepItem repItem = e.Node.Tag as RepItem;

            splitContainer1.Panel2.Enabled = (repItem != null);
            if (repItem != null)
            {
                tbPattern.Text      = repItem.Pattern;
                tbReplace.Text      = repItem.RepalceToRN();
                chkCase.Checked     = repItem.IgnoreCase;
                chkGlobal.Checked   = repItem.Global;
                chkRegB.Checked     = repItem.Boundary;
                chkDisabled.Checked = repItem.Disabled;
                rdNormal.Checked    = (repItem.RepType == RepType.Direct);
                rdCSharp.Checked    = (repItem.RepType == RepType.CS_Code);
            }
            _isSetting = false;
        }
예제 #3
0
        public static MethodInfo GetMethod(RepItem item)
        {
            string text  = "_Rep" + item.GetHashCode().ToString().Replace("-", "_");
            string value = @"
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using System.IO;
using System.Data;
using System.Reflection;
namespace hz {
   public class " + text + @"
   {
        " + item.RepalceToRN() + @"
   }   
}";
            CodeSnippetCompileUnit codeSnippetCompileUnit = new CodeSnippetCompileUnit(value);
            CompilerParameters     compilerParameters     = new CompilerParameters();

            compilerParameters.ReferencedAssemblies.Add("System.dll");
            compilerParameters.ReferencedAssemblies.Add("System.Data.dll");
            compilerParameters.ReferencedAssemblies.Add("System.Xml.dll");
            compilerParameters.GenerateInMemory   = true;
            compilerParameters.GenerateExecutable = false;
            CompilerResults compilerResults = new CSharpCodeProvider().CompileAssemblyFromDom(compilerParameters, codeSnippetCompileUnit);

            if (compilerResults.Errors.HasErrors)
            {
                throw new Exception(compilerResults.Errors[0].Line + "," + compilerResults.Errors[0].Column + ":" + compilerResults.Errors[0].ErrorText);
            }
            Assembly compiledAssembly = compilerResults.CompiledAssembly;
            Type     type             = compiledAssembly.GetType("hz." + text);

            return(type.GetMethod("ReplaceEach", BindingFlags.Static | BindingFlags.Public));
        }
예제 #4
0
        private void toolNewRepItem_Click(object sender, EventArgs e)
        {
            TreeNode treeNode = cfgTree.SelectedNode;

            if (treeNode != null)
            {
                if (treeNode.Parent != null)
                {
                    treeNode = treeNode.Parent;
                }
                RepItem repItem = new RepItem();
                repItem.Title      = "描述";
                repItem.Pattern    = "查找内容";
                repItem.RepalceTo  = "替换为";
                repItem.IgnoreCase = false;
                repItem.Global     = true;
                repItem.Boundary   = false;
                TreeNode treeNode2 = new TreeNode(repItem.Title, 2, 2);
                treeNode2.Tag = repItem;
                treeNode.Nodes.Add(treeNode2);
                (treeNode.Tag as RepBatch).Items.Add(repItem);
                treeNode2.BeginEdit();
            }
        }