Beispiel #1
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;
        }
Beispiel #2
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));
        }