Skip to content

Instantly share code, notes, and snippets.

@ivandrofly
Created March 18, 2017 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivandrofly/e24f401bbe85b25b83fdfc6140ae043d to your computer and use it in GitHub Desktop.
Save ivandrofly/e24f401bbe85b25b83fdfc6140ae043d to your computer and use it in GitHub Desktop.
this method is written to fix Subtitle Edit's GetRegExContextMenu(Combobox/TextBox) nightmare
// this method is written to fix Subtitle Edit's GetRegExContextMenu(Combobox/TextBox) nightmare
// make more sense as an extension method.
public static Action<TControl, string> BuildContextMenuRegex<TControl>()
{
var setMethod = typeof(TControl).GetProperty("SelectedText").GetSetMethod();
var instanceParam = Expression.Parameter(typeof(TControl), "instance");
var regexTokenParam = Expression.Parameter(typeof(string), "regexToken");
var lambaExp = Expression.Lambda<Action<TControl, string>>(Expression.Call(instanceParam, setMethod, regexTokenParam), instanceParam, regexTokenParam);
return lambaExp.Compile();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment