Advertisement
ivandrofly

[Expression-Tree] - Get regex context menu

Mar 18th, 2017
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.69 KB | None | 0 0
  1.         // this method is written to fix Subtitle Edit's GetRegExContextMenu(Combobox/TextBox)
  2.  
  3.         // make more sense as an extension method.
  4.         public static Action<TControl, string> BuildContextMenuRegex<TControl>()
  5.         {
  6.             var setMethod = typeof(TControl).GetProperty("SelectedText").GetSetMethod();
  7.             var instanceParam = Expression.Parameter(typeof(TControl), "instance");
  8.             var regexTokenParam = Expression.Parameter(typeof(string), "regexToken");
  9.             var lambaExp = Expression.Lambda<Action<TControl, string>>(Expression.Call(instanceParam, setMethod, regexTokenParam), instanceParam, regexTokenParam);
  10.             return lambaExp.Compile();
  11.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement