Tags: , , | Categories: Tip, Programlama, Genel Posted by okutbay on 26.02.2010 11:41 | Yorumlar (0)

You can always write comment to your codes. But comment itself can be outdated and misleads a developer. So writing self-documented codes must our first aim to make our code more maintainable.

In my opinion a big step to achieve self-documented code begins writing if clauses.

If a developer understands if clause, he/she understand purpose of the code block more easily.

But how can we write more readable if clause.

Very easy: Don't write logical comparisons into if clause.

    1 if ((preprocessedFailedEmails.Count > 0) || (failedEmails.Count > 0))

    2 {

    3     //some code

    4 }

Although this is a very simple if clause it's a bit hard to get what is happening there. Let's make it more readable.

    1 bool hasErrors = ((preprocessedFailedEmails.Count > 0) || (failedEmails.Count > 0));

    2 if (hasErrors)

    3 {

    4     //some code

    5 }

Happy coding...

Bu yazıyı ilk değerlendiren siz olun

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: | Categories: IDE, Genel, Tip Posted by okutbay on 25.02.2010 19:08 | Yorumlar (0)

If you're working with lot of projects, or you want to release your DLL to specific location you may need to add some extra actions to to your build.

For example. You have project that uses a DLL of another project of another solution. Sometimes you build your DLL in debug mode, sometimes you build your DLL in release mode. When you build your class library output directory depends on the build mode. Question is: Which DLL will be referenced by your project? To prevent this confusion you can add an copy operation to your post-build events. Then reference the copied DLL.

Here is the sample macro to do this:

cd $(OutDir)
copy $(TargetFileName) D:\Sources\DLLReferences\MyProjectOutpu

Just go to your project properties. Switch "Build Events" tab. Add this sample macro to Post-build event command line. When you build your it will copy result file to specified location.

build-events

Figure 1: Build events window of your project.

post-build-events-command-line-window

Figure 2: A Build event Command line window

You can find a list of macros and their descriptions here:

$(ConfigurationName)

The name of the current project configuration, for example, "Debug|Any CPU".

$(OutDir)

Path to the output file directory, relative to the project directory. This resolves to the value for the Output Directory property. It includes the trailing backslash '\'.

$(DevEnvDir)

The installation directory of Visual Studio 2005 (defined with drive and path); includes the trailing backslash '\'.

$(PlatformName)

The name of the currently targeted platform. For example, "AnyCPU".

$(ProjectDir)

The directory of the project (defined with drive and path); includes the trailing backslash '\'.

$(ProjectPath)

The absolute path name of the project (defined with drive, path, base name, and file extension).

$(ProjectName)

The base name of the project.

$(ProjectFileName)

The file name of the project (defined with base name and file extension).

$(ProjectExt)

The file extension of the project. It includes the '.' before the file extension.

$(SolutionDir)

The directory of the solution (defined with drive and path); includes the trailing backslash '\'.

$(SolutionPath)

The absolute path name of the solution (defined with drive, path, base name, and file extension).

$(SolutionName)

The base name of the solution.

$(SolutionFileName)

The file name of the solution (defined with base name and file extension).

$(SolutionExt)

The file extension of the solution. It includes the '.' before the file extension.

$(TargetDir)

The directory of the primary output file for the build (defined with drive and path). It includes the trailing backslash '\'.

$(TargetPath)

The absolute path name of the primary output file for the build (defined with drive, path, base name, and file extension).

$(TargetName)

The base name of the primary output file for the build.

$(TargetFileName)

The file name of the primary output file for the build (defined as base name and file extension).

$(TargetExt)

The file extension of the primary output file for the build. It includes the '.' before the file extension.

Reference: Pre-build Event/Post-build Event Command Line Dialog Box

Bu yazıyı ilk değerlendiren siz olun

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: , | Categories: Tip, SSS (FAQ), Web Uygulaması, Browsers Posted by okutbay on 18.02.2010 13:12 | Yorumlar (0)

If you hava a javascript like this:

    1 <script language="javascript" type="text/javascript">

    2 window.status ='some text';

    3 </script>

You will see firefox is not showing "some text" in the status bar. Too see your text you must enable it from "Advanced Javascript Settings" window.

Enable status bar with FF

 

Happy coding...

Bu yazıyı ilk değerlendiren siz olun

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories: Tip Posted by okutbay on 16.02.2010 15:00 | Yorumlar (0)

Here is a very handy extension method to remove white spaces from strings.

    1 public static string RemoveWhiteSpace(this string TextToRemoveWhiteSpaces)

    2 {

    3     string pattern = "\\s+";

    4     string replacement = " ";

    5     string result = Regex.Replace(TextToRemoveWhiteSpaces, pattern, replacement);

    6     return result;

    7 }

Adapted from http://msdn.microsoft.com/en-us/library/xwewhkd1.aspx

Happy coding.

Bu yazıyı ilk değerlendiren siz olun

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: , | Categories: Tip Posted by okutbay on 17.12.2009 18:16 | Yorumlar (0)
  1. \' - single quote, needed for character literals
  2. \" - double quote, needed for string literals
  3. \\ - backslash
  4. \0 - Unicode character 0
  5. \a - Alert (character 7)
  6. \b - Backspace (character 8)
  7. \f - Form feed (character 12)
  8. \n - New line (character 10)
  9. \r - Carriage return (character 13)
  10. \t - Horizontal tab (character 9)
  11. \v - Vertical quote (character 11)
  12. \uxxxx - Unicode escape sequence for character with hex value xxxx
  13. \xn[n][n][n] - Unicode escape sequence for character with hex value nnnn (variable length version of \uxxxx)
  14. \Uxxxxxxxx - Unicode escape sequence for character with hex value xxxxxxxx (for generating surrogates)

1 kişi tarafından 1.0 olarak değerlendirildi

  • Currently 1/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: , , | Categories: Tip Posted by okutbay on 03.12.2009 13:12 | Yorumlar (0)

If you want to delete (don't ask why) all of the .scc files you can use this simple MSDOS command.

At command prompt: DEL *.scc /s /ahr

This will delete all .scc files including subdirectories.

Happy coding...

Bu yazıyı ilk değerlendiren siz olun

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: , , , , , , , , | Categories: Programlama, SSS (FAQ), Tip Posted by okutbay on 13.11.2009 17:32 | Yorumlar (0)

Clipboard is a windows object. If you want to use clipboard in your .NET framework console applications you must reference `System.Windows.Forms` and mark your main method with `STAThreadAttribute` attribute.

Then you can use this class's methods e.g. Clipboard.SetText("some text to store in the clipboard");

Happy coding.

1 kişi tarafından 2.0 olarak değerlendirildi

  • Currently 2/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: , , | Categories: Tip Posted by okutbay on 12.11.2009 19:01 | Yorumlar (0)

if you are getting this exception "The type initializer for 'Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory' threw an exception." try to reference Microsoft.Practices.ObjectBuilder2.dll

Happy coding...

Bu yazıyı ilk değerlendiren siz olun

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: , , , , , , | Categories: SSS (FAQ), Tip, Web Uygulaması Posted by okutbay on 29.09.2009 21:46 | Yorumlar (0)

You can add the <location> element with the “inheritInChildApplications” attribute to the root web.config. This attribute will prevent child applications inherit some specified configuration from the root web.config.

The attribute must be placed in the <configuration> section of the web.config. It looks like this:
<location path="." inheritInChildApplications="false">
<system.web>
 <!--
     ……
     Your settings

  -->
</system.web >
</location>

Referance:

SectionInformation.InheritInChildApplications Property

Bu yazıyı ilk değerlendiren siz olun

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: | Categories: IDE, Programlama, SSS (FAQ), Tip Posted by okutbay on 11.09.2009 10:35 | Yorumlar (0)

While we are coding we used to delete blank lines with 'Shift + Del'. Shift + Del shortcut is same as 'Ctrl + X'. And if you copy something to clipboard before cutting the blank lines, it will be replaced by the blank line.

You can change this behaviour with VS 2008 settings. Tools > Option > Text Editor > All Languages (or just for specific language) > Uncheck 'Apply Cut or Copy commands to blank lines when there is no selection'



Happy coding...

Bu yazıyı ilk değerlendiren siz olun

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5