samedi 14 mai 2016

How to architect an arg on a method to do data retrieval and manipulation on retrieved data returning a final string

I have many methods each with many args. I need each arg to be told here's the data parts I need you to fetch and here's how I need you to manipulate all data parts into a final output string. Manipulation could be doing string search/replace on one or more data parts, inserting one data part at a specific index of another data part, etc. I'd like to focus on these two operations for now and leave room for future expansion.

Initial thoughts are to have the args for these methods accept either a struct or a class with bools that each say whether to fetch the data part. eg GetDataPartA = false, GetDataPartB = true. GetDataPartB could tell a property getter if string DataPartB == null go pull that data. And to finally have that struct or class representing the arg have a member that specifies the editing instructions for the data parts.

I'm struggling with how to cleanly do the final editing instructions part, and how to reference the property values that were filled based on the bool that told it to get it's fetched data.

Here's a more thorough use case:

  • Call into method A having args B.
  • Tell arg B to fetch DataPartA and DataPartB.
  • Tell arg B to substitute all strings "123" with "456" in DataPartB
  • Tell arg B to insert DataPartB after the "head" tag in DataPartA
  • Method A should now have a final string for arg B produced and ready for use

Aucun commentaire:

Enregistrer un commentaire