Building classes based on user input












0















I am creating a way to build automation which will allow users to enter commands via free-form textboxes with auto-complete, sort-of a pseudo-IDE functionality similar to intellisense. To start, I am defining what amounts to a list of string which act as definition templates that will be used to collect parameters from the users of my application. For example, the sample template looks like:



var scriptTemplate = "show message '{v_Message}' and close after {v_AutoClose} seconds"


So above is the defined pattern that my application is expecting to find. I anticipate looping over textbox data (happy path) that looks like:



"show message 'hello world!' //textbox1.Text


or



"show message 'hello world' and close after 4 seconds" //textbox1.Text


So, now I am building a method to take the user's input, compare it against the known templates, select a template and then extract the parameters (in this case v_Message and potentially v_AutoClose) and instantiate a class which will contain some logic to execute the command:



var newClassInstance = new CustomMessage();
newClassInstance.v_Message = "hello world";
//newClass.v_AutoClose = 4;
newClassInstance.Execute();


I am stuck on the part where I need to pull out the known parameters and apply them to the class as I am not sure the best way to go about this. I was able to make the first 2 words 'reserved' keywords to select the correct template, but what is the best way to extract the parameters and apply them back to the class? I am trying to do this generically for 100 different potential templates.










share|improve this question



























    0















    I am creating a way to build automation which will allow users to enter commands via free-form textboxes with auto-complete, sort-of a pseudo-IDE functionality similar to intellisense. To start, I am defining what amounts to a list of string which act as definition templates that will be used to collect parameters from the users of my application. For example, the sample template looks like:



    var scriptTemplate = "show message '{v_Message}' and close after {v_AutoClose} seconds"


    So above is the defined pattern that my application is expecting to find. I anticipate looping over textbox data (happy path) that looks like:



    "show message 'hello world!' //textbox1.Text


    or



    "show message 'hello world' and close after 4 seconds" //textbox1.Text


    So, now I am building a method to take the user's input, compare it against the known templates, select a template and then extract the parameters (in this case v_Message and potentially v_AutoClose) and instantiate a class which will contain some logic to execute the command:



    var newClassInstance = new CustomMessage();
    newClassInstance.v_Message = "hello world";
    //newClass.v_AutoClose = 4;
    newClassInstance.Execute();


    I am stuck on the part where I need to pull out the known parameters and apply them to the class as I am not sure the best way to go about this. I was able to make the first 2 words 'reserved' keywords to select the correct template, but what is the best way to extract the parameters and apply them back to the class? I am trying to do this generically for 100 different potential templates.










    share|improve this question

























      0












      0








      0








      I am creating a way to build automation which will allow users to enter commands via free-form textboxes with auto-complete, sort-of a pseudo-IDE functionality similar to intellisense. To start, I am defining what amounts to a list of string which act as definition templates that will be used to collect parameters from the users of my application. For example, the sample template looks like:



      var scriptTemplate = "show message '{v_Message}' and close after {v_AutoClose} seconds"


      So above is the defined pattern that my application is expecting to find. I anticipate looping over textbox data (happy path) that looks like:



      "show message 'hello world!' //textbox1.Text


      or



      "show message 'hello world' and close after 4 seconds" //textbox1.Text


      So, now I am building a method to take the user's input, compare it against the known templates, select a template and then extract the parameters (in this case v_Message and potentially v_AutoClose) and instantiate a class which will contain some logic to execute the command:



      var newClassInstance = new CustomMessage();
      newClassInstance.v_Message = "hello world";
      //newClass.v_AutoClose = 4;
      newClassInstance.Execute();


      I am stuck on the part where I need to pull out the known parameters and apply them to the class as I am not sure the best way to go about this. I was able to make the first 2 words 'reserved' keywords to select the correct template, but what is the best way to extract the parameters and apply them back to the class? I am trying to do this generically for 100 different potential templates.










      share|improve this question














      I am creating a way to build automation which will allow users to enter commands via free-form textboxes with auto-complete, sort-of a pseudo-IDE functionality similar to intellisense. To start, I am defining what amounts to a list of string which act as definition templates that will be used to collect parameters from the users of my application. For example, the sample template looks like:



      var scriptTemplate = "show message '{v_Message}' and close after {v_AutoClose} seconds"


      So above is the defined pattern that my application is expecting to find. I anticipate looping over textbox data (happy path) that looks like:



      "show message 'hello world!' //textbox1.Text


      or



      "show message 'hello world' and close after 4 seconds" //textbox1.Text


      So, now I am building a method to take the user's input, compare it against the known templates, select a template and then extract the parameters (in this case v_Message and potentially v_AutoClose) and instantiate a class which will contain some logic to execute the command:



      var newClassInstance = new CustomMessage();
      newClassInstance.v_Message = "hello world";
      //newClass.v_AutoClose = 4;
      newClassInstance.Execute();


      I am stuck on the part where I need to pull out the known parameters and apply them to the class as I am not sure the best way to go about this. I was able to make the first 2 words 'reserved' keywords to select the correct template, but what is the best way to extract the parameters and apply them back to the class? I am trying to do this generically for 100 different potential templates.







      c# winforms






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 '18 at 5:53









      Jason BayldonJason Bayldon

      78931935




      78931935
























          1 Answer
          1






          active

          oldest

          votes


















          0














          I have come across the similar type of requirement, where I have two tables with a column describing "TitleOfCampus", One of the tables is master and second one fresh data (your form data).
          All I need to do is, map-it the fresh data to the matching data in master table (Your template table).



          I took each entry from fresh data(TitleOfCampus), filtered the master table by breaking the string value in TitleOfCampus as follows,




          1. Actual full string based filter,

          2. String.Split(" ") array keywords based filter


          From the obtained results, then finally sort the matching master table info based on first letter of filter value TitleOfCampus, so the topmost data is the most matching info ready for mapping. Sample Code as follows



          List<MyTemplate> templateDetails = new List<MyTemplate>
          //Your filter code
          templateDetails.AddRange(actualFullStringMatchResults);
          foreach(var item in searchKeyword.ToString().Split(" "))
          {
          //Your filter code
          templateDetails.AddRange(eachKeyWordMatchResults);
          }
          //Remove duplicate
          templateDetails= templateDetails.DistinctBy(x => x.TempalteID).ToList();
          //Set topmost value as most releavant one
          templateDetails.OrderByDescending(i => i.TitleOfCampus[0] == fullStringFilter[0]).ToList();


          I hope this concept will sort out your requirement. auto close template in stipulated time is not an important point here but showing the right template is important.






          share|improve this answer
























          • Splitting by string is not ideal because the parameters can contain strings which will make it not 1:1. For example show message 'hello world' would not translate well to show message '{v_message}'

            – Jason Bayldon
            Nov 28 '18 at 17:44













          • @JasonBayldon, Am I clear with your problem, "User types some words, you need to use those words as a parameter to search and fetch from the 100 potential templates with most relevant one as suggestion added with auto close template suggested in few seconds. "

            – Pranesh Janarthanan
            Nov 30 '18 at 6:57











          • @JasonBayldon why do you want to translate back to show message '{v_message}'. It is not necessary bcoz it is actually showing the matching template not the keywords typed by the user.

            – Pranesh Janarthanan
            Nov 30 '18 at 6:58











          • The problem is I am trying to extract parameters from the text that the user supplied and instantiate a class. Splitting by space would work but only if I can escape single quotes from being split as well as I cant guarantee that the user is not going to input spaces. I need to pull out the parameters from a string based on the source pattern.

            – Jason Bayldon
            Nov 30 '18 at 13:28













          • @JasonBayldon Keyword with or without (space, " ' ") is not a big deal. where does this single quote comes from? Can u give me a clear example with sample inputs by editing your question. These inputs shall be what you think as difficult to solve. I could sort your problem easily.

            – Pranesh Janarthanan
            Dec 1 '18 at 9:47












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424654%2fbuilding-classes-based-on-user-input%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          I have come across the similar type of requirement, where I have two tables with a column describing "TitleOfCampus", One of the tables is master and second one fresh data (your form data).
          All I need to do is, map-it the fresh data to the matching data in master table (Your template table).



          I took each entry from fresh data(TitleOfCampus), filtered the master table by breaking the string value in TitleOfCampus as follows,




          1. Actual full string based filter,

          2. String.Split(" ") array keywords based filter


          From the obtained results, then finally sort the matching master table info based on first letter of filter value TitleOfCampus, so the topmost data is the most matching info ready for mapping. Sample Code as follows



          List<MyTemplate> templateDetails = new List<MyTemplate>
          //Your filter code
          templateDetails.AddRange(actualFullStringMatchResults);
          foreach(var item in searchKeyword.ToString().Split(" "))
          {
          //Your filter code
          templateDetails.AddRange(eachKeyWordMatchResults);
          }
          //Remove duplicate
          templateDetails= templateDetails.DistinctBy(x => x.TempalteID).ToList();
          //Set topmost value as most releavant one
          templateDetails.OrderByDescending(i => i.TitleOfCampus[0] == fullStringFilter[0]).ToList();


          I hope this concept will sort out your requirement. auto close template in stipulated time is not an important point here but showing the right template is important.






          share|improve this answer
























          • Splitting by string is not ideal because the parameters can contain strings which will make it not 1:1. For example show message 'hello world' would not translate well to show message '{v_message}'

            – Jason Bayldon
            Nov 28 '18 at 17:44













          • @JasonBayldon, Am I clear with your problem, "User types some words, you need to use those words as a parameter to search and fetch from the 100 potential templates with most relevant one as suggestion added with auto close template suggested in few seconds. "

            – Pranesh Janarthanan
            Nov 30 '18 at 6:57











          • @JasonBayldon why do you want to translate back to show message '{v_message}'. It is not necessary bcoz it is actually showing the matching template not the keywords typed by the user.

            – Pranesh Janarthanan
            Nov 30 '18 at 6:58











          • The problem is I am trying to extract parameters from the text that the user supplied and instantiate a class. Splitting by space would work but only if I can escape single quotes from being split as well as I cant guarantee that the user is not going to input spaces. I need to pull out the parameters from a string based on the source pattern.

            – Jason Bayldon
            Nov 30 '18 at 13:28













          • @JasonBayldon Keyword with or without (space, " ' ") is not a big deal. where does this single quote comes from? Can u give me a clear example with sample inputs by editing your question. These inputs shall be what you think as difficult to solve. I could sort your problem easily.

            – Pranesh Janarthanan
            Dec 1 '18 at 9:47
















          0














          I have come across the similar type of requirement, where I have two tables with a column describing "TitleOfCampus", One of the tables is master and second one fresh data (your form data).
          All I need to do is, map-it the fresh data to the matching data in master table (Your template table).



          I took each entry from fresh data(TitleOfCampus), filtered the master table by breaking the string value in TitleOfCampus as follows,




          1. Actual full string based filter,

          2. String.Split(" ") array keywords based filter


          From the obtained results, then finally sort the matching master table info based on first letter of filter value TitleOfCampus, so the topmost data is the most matching info ready for mapping. Sample Code as follows



          List<MyTemplate> templateDetails = new List<MyTemplate>
          //Your filter code
          templateDetails.AddRange(actualFullStringMatchResults);
          foreach(var item in searchKeyword.ToString().Split(" "))
          {
          //Your filter code
          templateDetails.AddRange(eachKeyWordMatchResults);
          }
          //Remove duplicate
          templateDetails= templateDetails.DistinctBy(x => x.TempalteID).ToList();
          //Set topmost value as most releavant one
          templateDetails.OrderByDescending(i => i.TitleOfCampus[0] == fullStringFilter[0]).ToList();


          I hope this concept will sort out your requirement. auto close template in stipulated time is not an important point here but showing the right template is important.






          share|improve this answer
























          • Splitting by string is not ideal because the parameters can contain strings which will make it not 1:1. For example show message 'hello world' would not translate well to show message '{v_message}'

            – Jason Bayldon
            Nov 28 '18 at 17:44













          • @JasonBayldon, Am I clear with your problem, "User types some words, you need to use those words as a parameter to search and fetch from the 100 potential templates with most relevant one as suggestion added with auto close template suggested in few seconds. "

            – Pranesh Janarthanan
            Nov 30 '18 at 6:57











          • @JasonBayldon why do you want to translate back to show message '{v_message}'. It is not necessary bcoz it is actually showing the matching template not the keywords typed by the user.

            – Pranesh Janarthanan
            Nov 30 '18 at 6:58











          • The problem is I am trying to extract parameters from the text that the user supplied and instantiate a class. Splitting by space would work but only if I can escape single quotes from being split as well as I cant guarantee that the user is not going to input spaces. I need to pull out the parameters from a string based on the source pattern.

            – Jason Bayldon
            Nov 30 '18 at 13:28













          • @JasonBayldon Keyword with or without (space, " ' ") is not a big deal. where does this single quote comes from? Can u give me a clear example with sample inputs by editing your question. These inputs shall be what you think as difficult to solve. I could sort your problem easily.

            – Pranesh Janarthanan
            Dec 1 '18 at 9:47














          0












          0








          0







          I have come across the similar type of requirement, where I have two tables with a column describing "TitleOfCampus", One of the tables is master and second one fresh data (your form data).
          All I need to do is, map-it the fresh data to the matching data in master table (Your template table).



          I took each entry from fresh data(TitleOfCampus), filtered the master table by breaking the string value in TitleOfCampus as follows,




          1. Actual full string based filter,

          2. String.Split(" ") array keywords based filter


          From the obtained results, then finally sort the matching master table info based on first letter of filter value TitleOfCampus, so the topmost data is the most matching info ready for mapping. Sample Code as follows



          List<MyTemplate> templateDetails = new List<MyTemplate>
          //Your filter code
          templateDetails.AddRange(actualFullStringMatchResults);
          foreach(var item in searchKeyword.ToString().Split(" "))
          {
          //Your filter code
          templateDetails.AddRange(eachKeyWordMatchResults);
          }
          //Remove duplicate
          templateDetails= templateDetails.DistinctBy(x => x.TempalteID).ToList();
          //Set topmost value as most releavant one
          templateDetails.OrderByDescending(i => i.TitleOfCampus[0] == fullStringFilter[0]).ToList();


          I hope this concept will sort out your requirement. auto close template in stipulated time is not an important point here but showing the right template is important.






          share|improve this answer













          I have come across the similar type of requirement, where I have two tables with a column describing "TitleOfCampus", One of the tables is master and second one fresh data (your form data).
          All I need to do is, map-it the fresh data to the matching data in master table (Your template table).



          I took each entry from fresh data(TitleOfCampus), filtered the master table by breaking the string value in TitleOfCampus as follows,




          1. Actual full string based filter,

          2. String.Split(" ") array keywords based filter


          From the obtained results, then finally sort the matching master table info based on first letter of filter value TitleOfCampus, so the topmost data is the most matching info ready for mapping. Sample Code as follows



          List<MyTemplate> templateDetails = new List<MyTemplate>
          //Your filter code
          templateDetails.AddRange(actualFullStringMatchResults);
          foreach(var item in searchKeyword.ToString().Split(" "))
          {
          //Your filter code
          templateDetails.AddRange(eachKeyWordMatchResults);
          }
          //Remove duplicate
          templateDetails= templateDetails.DistinctBy(x => x.TempalteID).ToList();
          //Set topmost value as most releavant one
          templateDetails.OrderByDescending(i => i.TitleOfCampus[0] == fullStringFilter[0]).ToList();


          I hope this concept will sort out your requirement. auto close template in stipulated time is not an important point here but showing the right template is important.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 '18 at 6:25









          Pranesh JanarthananPranesh Janarthanan

          609817




          609817













          • Splitting by string is not ideal because the parameters can contain strings which will make it not 1:1. For example show message 'hello world' would not translate well to show message '{v_message}'

            – Jason Bayldon
            Nov 28 '18 at 17:44













          • @JasonBayldon, Am I clear with your problem, "User types some words, you need to use those words as a parameter to search and fetch from the 100 potential templates with most relevant one as suggestion added with auto close template suggested in few seconds. "

            – Pranesh Janarthanan
            Nov 30 '18 at 6:57











          • @JasonBayldon why do you want to translate back to show message '{v_message}'. It is not necessary bcoz it is actually showing the matching template not the keywords typed by the user.

            – Pranesh Janarthanan
            Nov 30 '18 at 6:58











          • The problem is I am trying to extract parameters from the text that the user supplied and instantiate a class. Splitting by space would work but only if I can escape single quotes from being split as well as I cant guarantee that the user is not going to input spaces. I need to pull out the parameters from a string based on the source pattern.

            – Jason Bayldon
            Nov 30 '18 at 13:28













          • @JasonBayldon Keyword with or without (space, " ' ") is not a big deal. where does this single quote comes from? Can u give me a clear example with sample inputs by editing your question. These inputs shall be what you think as difficult to solve. I could sort your problem easily.

            – Pranesh Janarthanan
            Dec 1 '18 at 9:47



















          • Splitting by string is not ideal because the parameters can contain strings which will make it not 1:1. For example show message 'hello world' would not translate well to show message '{v_message}'

            – Jason Bayldon
            Nov 28 '18 at 17:44













          • @JasonBayldon, Am I clear with your problem, "User types some words, you need to use those words as a parameter to search and fetch from the 100 potential templates with most relevant one as suggestion added with auto close template suggested in few seconds. "

            – Pranesh Janarthanan
            Nov 30 '18 at 6:57











          • @JasonBayldon why do you want to translate back to show message '{v_message}'. It is not necessary bcoz it is actually showing the matching template not the keywords typed by the user.

            – Pranesh Janarthanan
            Nov 30 '18 at 6:58











          • The problem is I am trying to extract parameters from the text that the user supplied and instantiate a class. Splitting by space would work but only if I can escape single quotes from being split as well as I cant guarantee that the user is not going to input spaces. I need to pull out the parameters from a string based on the source pattern.

            – Jason Bayldon
            Nov 30 '18 at 13:28













          • @JasonBayldon Keyword with or without (space, " ' ") is not a big deal. where does this single quote comes from? Can u give me a clear example with sample inputs by editing your question. These inputs shall be what you think as difficult to solve. I could sort your problem easily.

            – Pranesh Janarthanan
            Dec 1 '18 at 9:47

















          Splitting by string is not ideal because the parameters can contain strings which will make it not 1:1. For example show message 'hello world' would not translate well to show message '{v_message}'

          – Jason Bayldon
          Nov 28 '18 at 17:44







          Splitting by string is not ideal because the parameters can contain strings which will make it not 1:1. For example show message 'hello world' would not translate well to show message '{v_message}'

          – Jason Bayldon
          Nov 28 '18 at 17:44















          @JasonBayldon, Am I clear with your problem, "User types some words, you need to use those words as a parameter to search and fetch from the 100 potential templates with most relevant one as suggestion added with auto close template suggested in few seconds. "

          – Pranesh Janarthanan
          Nov 30 '18 at 6:57





          @JasonBayldon, Am I clear with your problem, "User types some words, you need to use those words as a parameter to search and fetch from the 100 potential templates with most relevant one as suggestion added with auto close template suggested in few seconds. "

          – Pranesh Janarthanan
          Nov 30 '18 at 6:57













          @JasonBayldon why do you want to translate back to show message '{v_message}'. It is not necessary bcoz it is actually showing the matching template not the keywords typed by the user.

          – Pranesh Janarthanan
          Nov 30 '18 at 6:58





          @JasonBayldon why do you want to translate back to show message '{v_message}'. It is not necessary bcoz it is actually showing the matching template not the keywords typed by the user.

          – Pranesh Janarthanan
          Nov 30 '18 at 6:58













          The problem is I am trying to extract parameters from the text that the user supplied and instantiate a class. Splitting by space would work but only if I can escape single quotes from being split as well as I cant guarantee that the user is not going to input spaces. I need to pull out the parameters from a string based on the source pattern.

          – Jason Bayldon
          Nov 30 '18 at 13:28







          The problem is I am trying to extract parameters from the text that the user supplied and instantiate a class. Splitting by space would work but only if I can escape single quotes from being split as well as I cant guarantee that the user is not going to input spaces. I need to pull out the parameters from a string based on the source pattern.

          – Jason Bayldon
          Nov 30 '18 at 13:28















          @JasonBayldon Keyword with or without (space, " ' ") is not a big deal. where does this single quote comes from? Can u give me a clear example with sample inputs by editing your question. These inputs shall be what you think as difficult to solve. I could sort your problem easily.

          – Pranesh Janarthanan
          Dec 1 '18 at 9:47





          @JasonBayldon Keyword with or without (space, " ' ") is not a big deal. where does this single quote comes from? Can u give me a clear example with sample inputs by editing your question. These inputs shall be what you think as difficult to solve. I could sort your problem easily.

          – Pranesh Janarthanan
          Dec 1 '18 at 9:47




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424654%2fbuilding-classes-based-on-user-input%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to change which sound is reproduced for terminal bell?

          Can I use Tabulator js library in my java Spring + Thymeleaf project?

          Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents