Created
March 18, 2017 16:41
-
-
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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