Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.