Tuesday, April 24, 2007

Guidelines for using method permission requests in C#

  • Use SecurityAction.PermitOnly declarations to limit the permissions available to each method.
  • Use Security.Deny declarations to further refine the permissions available to each method.
  • Use CodeAccessPermissoin.Assert when you want to allow partially trusted code to call a method that requires permissions the caller might lack.
  • Use CodeAccessPermission.PermitOnly to imperatively reduce permissions when a section of a method requires fewer permissions than the rest of the method.
  • Use CodeAccessPermission.Demand only when your assembly implements customized functionality that does not rely on functionality built into the .Net Framework, such as calls to unmanaged code.

Wednesday, April 18, 2007

Some info about Windows Services in 2.0

This are some tips i've learned about windows services:
  • to debug a windows service, we need to start the service first and attach the debugger to the service's process.
  • you must always create installation components for windows services.
  • the Main method of the service application should always issue the Run command for the services.
  • error messages should be logged in the windows event logger.
  • run your service with the fewest privileges possible to minimize potential damage.

Monday, April 16, 2007

String VS StringBuilder

A few months ago i was wondering what is the purpose of the stringbuilder class in C#, if what it can do can also be done in a simple String/string variable type... and is done, imao, with more ease.

For example let's look at string concatenation:

//StringBuilder
StringBuilder sbExample = new StringBuilder();
sbExample.Append("Some ");
sbExample.Append("Text Here...");
return sbExample.ToString();


//String
String strExample = "Some ";
strExample = strExample + "Text Here...";
return strExample;


In this example, it is much easier to perform string concatenation with a plain simple string type than the stringbuilder, now what exactly is the difference between the two?

The answer: i've been reading the MS Book Application Foundation and here i've learned that a string memory address is immutable... if you concatenate or replace the string value, it does not overwrite its current memory location and instead allocates a new memory location for the new string value, meanwhile with the stringbuilder it always use the same memory it is allocated with whenever you try to modify it's value...

eureka! now i know, for better optimization, when dealing with strings use stringbuilder instead of the basic string value type, there might be an increase in the effort in coding, but what is a little sacrifice for a little more optimized performance.

small things can become big things too ;)

Friday, April 13, 2007

A year of OOP practice

Well it's been a year since i started OOP programming, i've earned quite a few certifications in Microsoft, but still I found myself lost in this 3 letter abbreviated concept...

i've downloaded dozens of OOP ebooks, but frankly, i've not gone through the first chapter... hmmm, why? lazy me, nope i've been spending time studying somewhat kinda new technologies to me (i was a c programmer before) C#, .Net, ASP.Net, SQL Server 2000/2005, HTML(yep even this one!) etc.. etc..

i remembered when i first started with OOP, i've been hooked up to procedural programming for so long as i can remember that my codes looked like procedural programming codes... thousands of lines, redundant functions or should i say methods, seldom code reuse... but as days, weeks, months have gone by i could say my codes began to trim down, and started to look cleaner (for my current colleagues, yep it trimmed down), what a great improvement... thank god i've discovered inheritance, interfaces, properties and other wonderful techniques of OOP.

and now i must continue my journey in discovering and learning this wonderful technique...

OOP technique rocks!