|
I don't think it's possible. My advice:
1 - break up big methods into smalle ones
2 - build logging in to your app, so you can add logging code for methods that crash on a client machine, and can just turn on logging in your config
3 - always log exceptions so you can track down errors.
4 - If you see more than one object that could be null, add checks for them all, they will all bite you at some point.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thanks Christian, all good advice.
#1: Hmmm, I tend to keep my method size down to no more than a page already, but a method may involve many objects.
#2,#3: I'm already doing. I've got exceptions with centralized reporting bracketing most of my methods.
#4: Yeah, I may need to do this with specific assertion tests to go with the bracketing exception handler (which can't pinpoint the problem object). I've been layering my parameter validation, but apparently that's not sufficient.
It's disappointing that the CLR can't leverage the metadata at it's disposal to answer this silly, but crucial question.
|
|
|
|
|
Hi!
With debug builds you can at least get the line number and source file name where the exception occurrs, but you don't always have a name for the "thing" that evaluates to null.
For example, what should this "null object name" return in this case:
MyClass mc = new MyClass();
return (mc as AnotherClass).ToString();
A very simple and constructed case, but I think you can easily see that as soon as you combine two or more operations without assigning the result to a new variable every time, the runtime doesn't have a chance to give a name for the null object because it is not named explicitely.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Dear friends,
Please help me with the following:
In a C# program, how can I reuse a method that takes classes (or list of classes, List<classname> ) as arguments? The method is defined inside a class.
Presently, the method in my program works only if "the object of the function call" and "the object defined in the parameter list of the function" are the same. Thus practically I have to repeat the method code as many times as the function is called, each with a different class as argument.
The following shows the gravity of my situation: Supposing there are 10 such methods in my c# program and each method (which by itself is quite long and detailed) has to be performed on 10 different classes as arguments.
What I want is, the method (written as a single copy, meaning, if-else option is ruled out) should accept any suitable class passed to it, any number of times, and produce the result. I am looking for a suitable way, using for example, inheritance. Use of gettype to resolve the classname doesnot work as it produces complie errors.
Suppose if the method takes Int or Double argument types, this problem does not arise; thus, is this a fundamental problem in OOP languages? Is there a classical method (I mean, not workaround) to overcome this problem?
Anyway I would be happy to learn an efficient workaround too!
Thanks for ur replies in advance!
Greetings,
Karthik
|
|
|
|
|
karthikde1980 wrote: (which by itself is quite long and detailed)
Then it should probably be refactored. I aim for methods to never be > 30 lines if I can help it.
karthikde1980 wrote: thus, is this a fundamental problem in OOP languages?
No, oop has nothing to do with it, except that oop is the solution. You can either write a generic method ( which is not OOP, but lets you use any class you like ), or you can define a base class for all the classes you want to pass, and just write one method that passes that.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Indeed, one simple base class which the others are derived from. Now thats a feature i couldn't do without.
But remember, you can cast a derived class as its base class. But you cannot cast the base class, as one of its dervied classes.
My current favourite word is: Bauble!
-SK Genius
|
|
|
|
|
Well, you can only cast it if it was an instance of the derived class to start with. That stands to reason.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi,
how can I get size of a structure? There is sizeof too, but it doesn't work.
Thanks.
|
|
|
|
|
How is sizeof not working?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
daavena wrote: but it doesn't work.
That is vague. You have to tell us in what respect does it not work. Does it cause a compiler error? Does it cause an exception? Do you disagree with the result? What?
|
|
|
|
|
Hello All,
If I add certain Shapes (e.g. Polylines) to a WPF Grid (placed inside a WPF window), would they be rendered with hardware acceleration?
|
|
|
|
|
I know that you can actually write code that tells you if hardware acceleration is being used. I believe the answer is 'yes, if you have a good enough graphics card'
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
You can use the "rendering tier" to get a feeling for the caps of the videocard:
<br />
int tier = (System.Media.Rendercapability.Tier >> 16);<br />
0 is bad - only software emulation
1 is ok - the card supports partial accel (DirectX 7 - DirectX 8)
2 is state of the art with full accel
|
|
|
|
|
Bartosz Bien wrote: would they be rendered with hardware acceleration?
I think they should. Not 100% certain though.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hi everyone.
Does anyone know if it is possible to include the .net core assemblies, say in a cd for our program to use theme and solve the problem of detecting the installed .net version and installing the required version?!
It's a real problem for me that create multimedia cds using C#!
Sojaner!
|
|
|
|
|
I think there are .NET obfuscators that cram all the dependencies into one assembly and optionally compile it into a native executable.
ROFLOLMFAO
|
|
|
|
|
I could not find any free full functional one can you suggest me one please?!
Sojaner!
|
|
|
|
|
There are no "free full functional" ones.
The one or two products that promise to include all the required parts into your program are quite expensive from what I've heard.
But obviously, if one main requirement for your application is that no installation is required, then choosing .NET was a mistake in the first place.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
mav.northwind wrote: if one main requirement for your application is that no installation is required, then choosing .NET was a mistake in the first place.
Actually, it's not a mistake. If the OS comes with the required framework, no installation is required and a simple copy and paste is all that is needed. (e.g.: I can compile and send the resulting assembly over to my friend's computer for execution without him having to install anything.)
ROFLOLMFAO
|
|
|
|
|
Ri Qen-Sin wrote: If the OS comes with the required framework
I think that's exactly the problem he's facing.
Windows Server 2003 comes with .NET 2.0 pre-installed, Vista comes with .NET 3.0 pre-installed.
For all other OS's there is no .NET installed out-of-the-box, and without installing .NET the application doesn't work.
Installing .NET can be automated, but even then it takes a while.
Once the target system does have .NET, of course you can simply use XCOPY deployment for .NET applications, but without the framework you're grounded.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
|
I build a C++ app that launches the .NET install from CD if needed, then installs my app. It works well for me.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi,
I want in a textbox that is for date when user is entering date, automatically the text in it appears as --/--/--
i.e user only enters 6 digits(2 for day ,2 for month, 2 for year)
Best wishes
|
|
|
|
|
|
He might not be using .NET 2.0. I think one of out fellow Code Project members wrote one by extending a regular textbox and intercepting keys. I can't be sure.
ROFLOLMFAO
|
|
|
|