Tweaking Reflector output
-
Hi, This isn't really a programming question (at least I don't think it is). It's a question about Reflector. I have a windows forms application that uses a listview. I have some code that gets a list of the checked items in the listview and does some stuff.
private void button1_Click(object sender, EventArgs e)
{
string names = "";
for (int i = 0; i < listView1.CheckedItems.Count; i++)
{
names += "\n" + listView1.Items[i].Text;
}
MessageBox.Show("Selected Names = " + names);
}When I look at the compiled executable in Reflector this code is disassembled as
private void button1_Click(object sender, EventArgs e)
{
string str = "";
for (int i = 0; i < this.listView1.get_CheckedItems().get_Count(); i++)
{
str = str + "\n" + this.listView1.Items[i].Text;
}
MessageBox.Show("Selected Names = " + str);
}I'm using the File Generator plugin to recreate the Visual Studio project. The generated project cannot be compiled. Compilation fails with the following error
"'System.Windows.Forms.ListView.CheckedItems.get': cannot explicitly call operator or accessor"
. Fair enough. Now to the question: Is there anyway to have Reflector disassemble the application so that I don't get these compiler errors? I've tried settings various options but I can't get it to work. The reason I need this is that a customer has reported a bug in a really old version of our application. We don't have a copy of the source code for this application so I'm using Reflector to generate the files. The generated project fails to compile with the error mentioned above. I know that I can manually tweak the generated files but there are about 8000 lines that I would need to change. If there is no way to change how Reflector outputs the code, can anyone recommend how to work around this problem? Thanks, dlarkin77 -
Hi, This isn't really a programming question (at least I don't think it is). It's a question about Reflector. I have a windows forms application that uses a listview. I have some code that gets a list of the checked items in the listview and does some stuff.
private void button1_Click(object sender, EventArgs e)
{
string names = "";
for (int i = 0; i < listView1.CheckedItems.Count; i++)
{
names += "\n" + listView1.Items[i].Text;
}
MessageBox.Show("Selected Names = " + names);
}When I look at the compiled executable in Reflector this code is disassembled as
private void button1_Click(object sender, EventArgs e)
{
string str = "";
for (int i = 0; i < this.listView1.get_CheckedItems().get_Count(); i++)
{
str = str + "\n" + this.listView1.Items[i].Text;
}
MessageBox.Show("Selected Names = " + str);
}I'm using the File Generator plugin to recreate the Visual Studio project. The generated project cannot be compiled. Compilation fails with the following error
"'System.Windows.Forms.ListView.CheckedItems.get': cannot explicitly call operator or accessor"
. Fair enough. Now to the question: Is there anyway to have Reflector disassemble the application so that I don't get these compiler errors? I've tried settings various options but I can't get it to work. The reason I need this is that a customer has reported a bug in a really old version of our application. We don't have a copy of the source code for this application so I'm using Reflector to generate the files. The generated project fails to compile with the error mentioned above. I know that I can manually tweak the generated files but there are about 8000 lines that I would need to change. If there is no way to change how Reflector outputs the code, can anyone recommend how to work around this problem? Thanks, dlarkin77Sounds like a candidate for a good global find/replace with a regular expression or two and some manual editting. 8,000 lines really isn't that big, if you only need to do it once.
Software Zen:
delete this;
-
Sounds like a candidate for a good global find/replace with a regular expression or two and some manual editting. 8,000 lines really isn't that big, if you only need to do it once.
Software Zen:
delete this;
Yeah I figured I'd probably have to take this route. I'm a bit confused as to how to actually replace text using a regular expression. Finding the text I need to replace should be pretty straight forward - I could search for
get_*()
This would find two matches:get_CheckedItems()
andget_Count()
But how can I use a regular expression to replace theget_
and the()
for each match? Thanks. -
Yeah I figured I'd probably have to take this route. I'm a bit confused as to how to actually replace text using a regular expression. Finding the text I need to replace should be pretty straight forward - I could search for
get_*()
This would find two matches:get_CheckedItems()
andget_Count()
But how can I use a regular expression to replace theget_
and the()
for each match? Thanks.Using Visual Studio, set your find string to:
\.get_{:i}\(\)
and your replace string to:
.\1
and make sure that 'regular expressions' is selected in the find options. The find string is translated as "find a literal period, followed by 'get_', followed by an identifier (which is tagged), followed by a literal left parenthesis, followed by a literal right parenthesis". The replace string is translated as "a literal period, followed by the identifier tagged in the find expression". I strongly recommend against using "Replace all" with this. I would do these one at a time, so you can confirm the changes.
Software Zen:
delete this;
-
Using Visual Studio, set your find string to:
\.get_{:i}\(\)
and your replace string to:
.\1
and make sure that 'regular expressions' is selected in the find options. The find string is translated as "find a literal period, followed by 'get_', followed by an identifier (which is tagged), followed by a literal left parenthesis, followed by a literal right parenthesis". The replace string is translated as "a literal period, followed by the identifier tagged in the find expression". I strongly recommend against using "Replace all" with this. I would do these one at a time, so you can confirm the changes.
Software Zen:
delete this;
-
Excellent. That seems to be working just fine - (I really do need to get a handle on the whole regular expressions thing, I seriously doubt I would have been to figure this out on my own). Thanks very much, dlarkin77
You're very welcome; glad I could help. Regular expressions are handy for this sort of thing, but they do have one hazard: you can end up spending more time debugging your regular expression than you would have just doing dumb old-fashioned editting.
Software Zen:
delete this;