开发者

Need to Copy a Method To File.txt

开发者 https://www.devze.com 2023-04-11 01:20 出处:网络
public int UpdateTable() { string SpName=\"UPDATE_TABLE_S1\"; . . .//statement 30 return recordsaffected = 1;
public int UpdateTable()
{

string SpName="UPDATE_TABLE_S1";
.
.
.//statement 30

return recordsaffected = 1;
}

public int InsertTable()
{

string SpName="Insert_TABLE_S1";
.
.
.
return recordsaffected = 1;
}

public int DeleteTable()
{

string SpName="DELETE_TABLE_S1";
.
.
return recordsaffected = 1;
}

There is class which has around 20 methods and i need to copy a method by Searching a SpName = 'INSERT_TABLE_S1' To Text Fi开发者_开发知识库le.

i used stream reader to search the sp name. but copying the whole method is where i am struck. Is there any in built method to copy the whole method.

i tried by writing to file when public keyword starts and till the return comes.. but this doesn't seem correct...


I'd be inclined to start storing methods in a string builder one line at a time until either the method ends or the string you are looking for is found. If it is found finish reading the method and write to your external file. Maybe even store all the methods in a list of string builders so I could search through them all at the end.

I'd probably extract an interface which I would use to give me a list of all the method signatures which I could use to start reading in each method.


You can split based on public keyword and then search for the method name:

        string spName = "DELETE_TABLE_S1";
        string methodText = "";
        string[] methods = theCompleteStringWithAllMethods.Split(new string[] { "public"     }, StringSplitOptions.None);
        for (int ii = 0; ii < methods.Length; ii++)
        {
            if (methods[ii].Contains("SpName=" + spName))
            {
                methodText = "public " + methods[ii];
                break;
            }
        }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号