|
Hi,
I've just had to expose a load of private members as public properties, and thought that regex should be able to do the trick. It did. Use the following:
search for
{.*}private {:c+} m_{:a+};
replace with
\1public \2 \3\n\1\{\n\1\tget \{ return m_\3; \}\n\1\tset \{ m_\3 = value; \}\n\1\}\n
Remember to enable regex.
Or save the following macro:
Sub PrivatesToProperties()<br />
DTE.ExecuteCommand("Edit.Replace")<br />
DTE.Find.ReplaceWith = "\1public \2 \3\n\1\{\n\1\tget \{ return m_\3; \}\n\1\tset \{ m_\3 = value; \}\n\1\}\n"<br />
DTE.Find.FindWhat = "{.*}private {:c+} m_{:a+};"<br />
DTE.Find.ReplaceWith = "\1public \2 \3\n\1\{\n\1\tget \{ return m_\3; \}\n\1\tset \{ m_\3 = value; \}\n\1\}\n"<br />
DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocumentSelection<br />
DTE.Find.MatchCase = False<br />
DTE.Find.MatchWholeWord = False<br />
DTE.Find.MatchInHiddenText = True<br />
DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxRegExpr<br />
DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResultsNone<br />
DTE.Find.Action = vsFindAction.vsFindActionReplaceAll<br />
DTE.Find.Execute()<br />
DTE.Windows.Item(Constants.vsWindowKindFindReplace).Close()<br />
End Sub
It will convert this:
private int m_blabla;
private string m_moreBla;
to this:
public int blabla
{
get { return m_blabla; }
set { m_blabla = value; }
}
public string moreBla
{
get { return m_moreBla; }
set { m_moreBla = value; }
}
but requires that you start with privates that are prefixed with "m_". And it doesn't uppercase the properties (blabla should be Blabla) - but the world isn't perfect
Just a tip - many of you probably already know it, but I didn't find it on CP so here it is.
/Jan
Do you know why it's important to make fast decisions? Because you give yourself more time to correct your mistakes, when you find out that you made the wrong one. Chris Meech on deciding whether to go to his daughters graduation or a Neil Young concert
|
|
|
|
|
Hi folks,
I recently reviewed some code from a collegue and I found he was using exceptions a great deal -- my gut feeling was that he was using them too much (his dictionary implementations throw exceptions if you pass a key for a non-existent entry, that sort of thing).
I set the IDE to break whenever an exception is thrown and I got bored after the 20th exception before the UI even displayed.
So my question is: What is the performance hit of exceptions, as opposed to returning a null or empty value?
Any pointers to articles would be especially useful as I will probably need hard data to win the argument.
Thanks
Herbie
Dr Herbie
Remember, half the people out there have below average IQs.
|
|
|
|
|
Dr Herbie wrote:
What is the performance hit of exceptions, as opposed to returning a null or empty value?
Exceptions are VERY expensive, especially the FIRST one (from what I have seen around 600ms). Exceptions are what they are, exceptional conditions (normally from external usage), not some internal bad coding habits. It all depends how your public object/interface will be used.
xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots
|
|
|
|
|
It's recommended that you use as few exceptions as possbile. An exception should never occur in the normal execution of an application.
To use exceptions for the program flow is a lazy way of programming. It's slow, and there is a big risk that you accidentally catch any real errors that might occur, and ignore them.
---
b { font-weight: normal; }
|
|
|
|
|
Another way to look at this is to think in terms of contracts. With the data it's given can a routine fufil its contract, i.e., can it do what it says it can do? If it can then you shouldn't throw an exception. If it can't then it should fail, which means throwing an exception or signalling some other type of failure. Not being able to fulfil its contract is either due to a programmer error, or an environment error such as out of memeory. Either way it will be a rare occurrence.
I think in the situation you describe, your gut feeling is probably right.
Kevin
|
|
|
|
|
To add to what has already been said, it is my experience that any method that may throw an exception should have a way of determining whether that exception will be thrown.
To use your dictionary as an example... if the index accessor throws an exception when the key doesnt exist then that is fine.. so long as the Contains method always returns false for that key.
|
|
|
|
|
Here's a chapter from a design book on the subject Exceptions[^]. Also, Effective Java and More Effective C++ have good material. I have't seen Effective C#, but I suspect it has a similar take on them and they will all support your argument.
I'm not sure the performance angle is the best one to pursue though. I think it is better to point out that it is simply misuse of the feature. The purpose of exceptions is to deal with exceptional conditions.
Matt Gerrans
|
|
|
|
|
I am developing a plug-in to word that uses a webservice to take out information and insert it into bookmarks. For example I'm sending the bookmarkname "ProjectName" and the webservice retrieves the name of a particular project.
But I need to do the same with excel, does it exist a way to bookmark cells? Preferably together. I could use search and replace, but as the templates are not only used for this I want them to be able to use them normally too and it feels very clumsy to search and replace something in each cell.
I'm hoping that there exist some easier way so it will be more similar to the method I'm using with Word.
|
|
|
|
|
Hi, I am developing a web application, which consist of three pages, WebForm1.aspx, WebForm2.aspx, WebForm3.aspx, now I want to display WebForm3.aspx at the start of application. Where as, when I start, it shows WebForm1.aspx.
Tried this code, but it is not working
<authentication mode="Forms">
<forms loginurl="WebForm3.aspx">
plz help me,tell me is it a right way to gain the above purpose?
|
|
|
|
|
In your designer ,set the webform3.aspx page tothe startup page.
|
|
|
|
|
I got a Access database, i have a table points where i store points coordinates, and the attributive information... I want to make a querry, to fetch some rows for example row 7, 39, 40, 578, 722 and so on...
Will it be the right way:
SELECT * FROM points where ID in(7,39,40,578,722)
|
|
|
|
|
Yes.
---
b { font-weight: normal; }
|
|
|
|
|
Hello,
I try to create myself a component control under compact framework .NET with Windows CE. But as I try to add reference to my software, the Visual Studio.NET refuse and tell me, that it is not a compatible .NET component.
I think it is is realy not easy, because the Windows CE is runing unter different machine with different asembly languages. But the library OpenNetCF is a good sample, wich is possible running under compact framework. I wonder, how does it work realy?
Thank you much in advance
Hung Le Quoc
email hung.lequoc@brabender.com
|
|
|
|
|
using (OleDbCommand cmd = new OleDbCommand ("UPDATE Table SET ID = '"+ID+"',[Progress] = '"+progress+"'" +
"WHERE (ID = '0') AND ([Progress] = '0')", con))
I need debugging help on this query which is bothering me for ages. Juz a query to update 2 columns but juz cant work...Any help? thanks...
|
|
|
|
|
Use a blank space before WHERE, it should run.
Sheo
|
|
|
|
|
its still not working.. i got this error..
Syntax error in UPDATE statement.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.OleDb.OleDbException: Syntax error in UPDATE statement.
Line 80: {
Line 81: // cmd.CommandType = CommandType.Text; Default is text, ut if you change to something else you should change this here.
Line 82: cmd.ExecuteNonQuery();
Line 83: //cmd1.ExecuteNonQuery();
Line 84:
|
|
|
|
|
what the right process of executing sql in my knowledge is like this.
This is compact
//To update/insert/delete records
stirng Sql = "Update or whatever sql statement"
OleDbCommand dCmd = new OleDbCommand(Sql,conn);
dCmd.ExecuteNonQuery();
dCmd = null;
// for Select statement
stirng Sql = "Update or whatever sql statement"
OleDbCommand dCmd = new OleDbCommand(Sql,conn);
OleDbDataReader dReader = dCmd.ExecuteReader();
DataGrid1.DataSource = dReader;
DataGrid1.DataBind();
dReader.Close();
dCmd = null;
In your case you are using the Sql into the Command object and again assiging the text property to command object to the same sql.
Please try this way, i hope this should work.
Sheo
|
|
|
|
|
Here's the situation:
I’m building an application that is going to be used buy a ton of different people in my organization. So security is becoming a big deal. Someone in this department can do this function X, but a different department can’t do that function X and so forth. This application is going to grow and evolve. I’m trying to figure out the best way to keep track of who can do what, and ensuring that people are only doing the things they are allowed to do.
Right now I’ve got something like this CurrentUser.IsMemberOf(“Administration”) The IsMemberOf method checks to see if the user is in the supplied group. Only problem is that if Administration ever gets renamed or a developer misspells it, then the compiler won’t ever catch it and the application will have a runtime error.
I was thinking that if I created enums for all of the various functions like
CreateUser
EditUser
EditGroup
EditDocument
ChangeDocumentState
Etc, etc.
Then I could ensure that everything was correct at compile time, and as my application grows I can just add in additional values for the enum.
Then I would do something like
bool result = CurrentUser.CanPreformFunction(Functions.EditUser) ;
Is this a good way to design application functional security? Or is there a better more elegant way?
I don’t think Method Security will work in my case either, because I need to modify the UI depending on the user’s rights, not what they can call, etc.
Let me know!
Thanks!
Ryan
|
|
|
|
|
If you change the enum you will have to recompile all code that uses it. If that is not a problem, it is a good way to go.
---
b { font-weight: normal; }
|
|
|
|
|
Hello all.
My .Net solution uses a C# dll, as well as a managed C++ dll that is attempting to call a MS Embedded Visual C++ 4.0 dll.
The C# and managed C++ dlls are part of the .Net solution as 'projects'. When I build and run this project in the emulator, I also wish to load the win32 (non .Net) dll into the emulator so that the managed C++ can use the win32 dll.
Is this possible? Any help would be great!
|
|
|
|
|
Um...
P/Invoke from C#? If you can do native code does LoadLibrary work?
Alex Korchemniy
|
|
|
|
|
I am using P/Invoke from the C# to interface to LoadLibrary and GetProcaddress. However I need to make the function call within a managed C++ module because C# does not handle function pointers (needed to call the function in the win32 dll).
The issue is loading the win32 dll that is not part of the .Net environment into the emulator so that my C# dll can call it....
Do you know how to do this?
|
|
|
|
|
Hello list,
I've found myself in a bit of a pickle in trying to do something that is intuitively simple. I'm relatively new to coding, esp. in C#, so I hope you don't mind a novice-level question.
Here's what I need to do:
1. I have a text file with some data, and each line in the text file is a number of type "double".
2. I would like the user to be able to click a button on the application's form, navigate to this text file and be able to read ALL available lines (numbers) into an array of doubles.
I've figured out how to put the button on the form and the use of the OpenFileDialog. I just don't seem to be doing the reading of data into the array correctly.
Your help would be greatly appreciated! Thank you.
|
|
|
|
|
You might want to check out the StreamReader class. It has a ReadLine method which should be able to help you. The Convert class would be able to help you do the conversion from string to double.
<font=arial>Weiye Chen
Life is hard, yet we are made of flesh...
|
|
|
|
|
Check out http://www.codeproject.com/cs/database/CsvReader.asp
|
|
|
|