Home

1 complement, 1 question and 1 idea

Hi, my name is Bryan. I have been using LinqPad since the invention of the hammer. This application is paramount in my daily life. Not only do I use is professionally, I also use it personally and I have recommended this application countless times and lead to several purchases, a few enterprise level at different companies I've worked for.

This application is amazing and the quality grade A.

I've seen some questions on the forum and the internet in general about user input. Generally I've seen people use VB references and the Interaction.InputBox method. Is there any other methods for user input? If not are there any plans for user input?

I have created queries that start small and over time become pretty complex and in some cases have a decision tree that needs input from the user. A simple example would be a combo box list of several choices. I'd like to prompt the user (typically always me) for the option and have the query adjust based on that choice.

If needed I can elaborate and give a real world example.

Which leads me to an idea or suggestion that might be something for a future build. First, is it possible to create plugin's for LinPad? Or better yet, does LinPad support MEF or any other type of dependency injection and if so could some of it's core functionality be modified? I understand there could be some security concerns around the world creating plug-ins that might touch or transmit data. Maybe some type of "Verified Plug-In" where the code has been reviewed by a community. Anyway, that's a side tangent.

My suggestion/request - as I stated before some of my queries become very complex - practically mini-applications. THAT said, it would be nice if there is a way to "promote" this query into an application. Press a button and it extract program.cs with a data context and table classes, config file with the connection string, etc-
"This thing has outgrown LinqPad, I need to promote!"
  • click promote button
  • file save location prompt
  • exports all the files needed, in the format selected (C#,VB)
  • opens windows explorer to the location with all the files
  • bonus bad-ass points awarded if it creates a VS project file (or an option for users who don't use VS)
I would appreciate some feedback from the developer and other community members.

Anyway, thanks for your time.
~Bryan

Comments

  • Regarding user input, have you looked at the

    Util.ReadLine()

    method?
  • kingkeith, yes - I have. It works, but it is a little clunky. I'd like a popup combo box type deal.
  • edited August 2016
    Look at the examples here: http://www.linqpad.net/customvisualizers.aspx
    var title = "WPF Control Gallery";
    var margin = new Thickness(10);
    var webClient = new WebClient { Headers = { "User-agent: LINQPad" } };
    
    var timeSources = new Dictionary<string, string> {
      { "ISO 8601", "http://www.timeapi.org/utc/now" },
      { "json", "http://www.timeapi.org/utc/now.json"}
    };
    var comboBox = new ComboBox { ItemsSource = timeSources, DisplayMemberPath = "Key", SelectedValuePath = "Value", SelectedIndex = 0, Margin = margin };
    var button = new Button { Content = "Get time", Margin = margin };
    var label = new Label { Content = "Result", Margin = margin };
    
    button.Click +=
      async (o, e) =>
      {
        var uri = new Uri((string)comboBox.SelectedValue);
        label.Content = await webClient.DownloadStringTaskAsync(uri);
      };
    
    Array.ForEach(
      new UIElement[] { comboBox, new TextBlock { Margin = margin }, button, label },
      x => PanelManager.StackWpfElement(x, title)
    );
    image

    Or if you really want a dialog:
    var panel = new StackPanel();
    var window = new Window { Title = "My Dialog", Content = panel };
    var margin = new Thickness(10);
    
    var timeSources = new Dictionary<string, string> {
      { "ISO 8601", "http://www.timeapi.org/utc/now" },
      { "json", "http://www.timeapi.org/utc/now.json"}
    };
    
    var comboBox = new ComboBox { ItemsSource = timeSources, DisplayMemberPath = "Key", SelectedValuePath = "Value", SelectedIndex = 0, Margin = margin };
    var button = new Button { Content = "OK", Margin = margin };
    
    button.Click += (o, e) => window.Close();
    
    panel.Children.Add(comboBox);
    panel.Children.Add(button);
    
    window.ShowDialog();
    
    comboBox.SelectedItem.Dump("Time source");
    
    using (var webClient = new WebClient { Headers = { "User-agent: LINQPad" } })
    {
      var uri = new Uri((string)comboBox.SelectedValue);
      webClient.DownloadStringTaskAsync(uri).Dump("Time");
    }
    image

    image

    You could create your own method to mark up and display a combobox and save it in MyExtensions:
    void Main()
    {
      // Write code to test your extensions here. Press F5 to compile and run.
    
      var timeSources = new Dictionary<string, string> {
        { "ISO 8601", "http://www.timeapi.org/utc/now" },
        { "json", "http://www.timeapi.org/utc/now.json"}
      };
    
      MyExtensions.ShowDialog(timeSources, "Select a time source").Dump();
    }
    
    public static class MyExtensions
    {
      // Write custom extension methods here. They will be available to all queries.
    
      public static T ShowDialog<T>(Dictionary<string, T> values, string title)
      {
        var panel = new StackPanel();
        var window = new Window { Title = title, Content = panel };
        var margin = new Thickness(10);
    
        var comboBox = new ComboBox { ItemsSource = values, DisplayMemberPath = "Key", SelectedValuePath = "Value", SelectedIndex = 0, Margin = margin };
        var button = new Button { Content = "OK", Margin = margin };
    
        button.Click += (o, e) => window.Close();
    
        panel.Children.Add(comboBox);
        panel.Children.Add(button);
    
        window.ShowDialog();
    
        return (T)comboBox.SelectedValue;
      }
    
    }
    
    // You can also define non-static classes, enums, etc.
  • @nescafe considering there isn't a built in method, I really like your suggestion. Good job!
  • Thanks for your support and suggestions!

    Regarding extensibility points, these are hard to design (and easy to screw up) without a reasonable set of use-cases.

    You're right about Util.ReadLine being clunky. When you provide it with suggestions, it feeds the autocompletion list, but it doesn't give a combobox dropdown, so there's no way to get a list of all options. I'll fix this for the next build.
  • The new beta build with a ComboBox in Util.ReadLine is now out.
  • Nice! Thanks @JoeAlbahari, I'll give it a download!
Sign In or Register to comment.