Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static Action<object, string> TokenProvider;
- private static Action<object, string> BuildTokenProvider(object control)
- {
- if (TokenProvider != null)
- {
- // NOTE: once this is contructed, if you try to invoke it using other type of control it will throw exception
- return TokenProvider;
- }
- Type ctrlType = control.GetType();
- var objParam = Expression.Parameter(typeof(object), "control");
- var objValueParam = Expression.Parameter(typeof(string), "value");
- // convert the given object to control type to allow accesing "SelectedText" property
- var convertExpr = Expression.Convert(objParam, ctrlType);
- var propExp = Expression.Property(convertExpr, "SelectedText");
- var binaryExp = Expression.Assign(propExp, objValueParam);
- TokenProvider = Expression.Lambda<Action<object, string>>(binaryExp, objParam, objValueParam).Compile();
- return TokenProvider;
- }
- public static ContextMenu GetRegExContextMenu(object control)
- {
- TokenProvider = TokenProvider ?? BuildTokenProvider(control);
- var cm = new ContextMenu();
- var l = Configuration.Settings.Language.RegularExpressionContextMenu;
- cm.MenuItems.Add(l.WordBoundary, delegate { TokenProvider(control, "\\b"); });
- cm.MenuItems.Add(l.NonWordBoundary, delegate { TokenProvider(control, "\\B"); });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement