Wednesday, December 3, 2008

Compiling C# and VB code together in asp.net

Yesterday i was working on a web application which uses vb classes. I have added a c# class added but asp.net compiler does not compile it as app_code folder becomes a single assembly so it allows only vb or C#.

Tip:
To compile both C# and VB, add this in web.config.

<compilation debug="false">
<codesubdirectories>
<add directoryname="VBCode">
<add directoryname="CSCode">
</add>
</add></codesubdirectories></compilation>


For more information, see this post.

Monday, December 1, 2008

The Eight Commandments of Source Code Control

Yesterday I read source code control tips which are helpful for developers working in a team environment. Link was sent by my friend Awais. I am posting here to share this.

1. You shall check in early and check in often. You anger your coworkers when you check out a file and insist on keeping it checked out until some future point in time that is measured using variables that exist solely in your brain.

2. You shall never check in code that breaks the build. If you code does not compile, it does not belong in the source control repository.

3. You shall not go home for the day with files checked out, nor shall you depart for the weekend or for a vacation, with files checked out.

4. You shall leave a descriptive comment when checking in your code. You need not include your name or the date in the comment as that information is already tracked.

5. You shall use the 'Undo Checkout' option if you check out a file and do not make any changes. It displeases your coworkers when you check in code that has not changed at all from the original.

6. You shall not use comments to 'save' defunct code. Fear not, for the code you delete still exists in the source control code history and can be retrieved if needed.

7. You shall use source control for more than archiving just code. The source code control repository makes an excellent storage for technical docs, SQL scripts, and other documents and files related to the project.

8. You shall religiously backup your source code control database on a regular basis and store a copy in an off-site location.

Source: http://scottonwriting.net/sowblog/posts/13581.aspx

Tuesday, November 25, 2008

fedora 10 released

Yesterday the fedora 10 released. click Here to download it.

Generate properties from class variables

One of the nice thing about Visual studio is its macro support. You can create and use macros in visaul studio .net to increase the productivity. One feature which most developers wants a quick property generation from list of class variables but Visual Studio .NET has no shortcut for it. To achieve this, you have record or create a macro.

So below is the Macro that generate the automatic properties from the member variables.

Just copy the text below and then open VS.NET.Go to Tools-> Macro->Macros IDE menu item.
A new window will be open. click on mymacros and paste the below text and build it.

After building, open your VS project. Go to Tools->Options. A dialog will be appeard. click on keyboard in Environment. Select your macro and assign a shortcut. For example Shift + F2.

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Imports System.Text


Public Module Expand
Public Sub ExpandPrivateMembersFronSelection()
Dim TS As TextSelection =

DTE.ActiveDocument.Selection
Dim strResult As String, Line As String
Dim Lines() As String =

TS.Text.Split(vbNewLine)
For Each Line In Lines
strResult &= GetstrResult(Line)
Next
TS.EndOfLine()
TS.NewLine()
TS.Insert(vbCrLf & "#region ""Public

Properties""" & vbCrLf & strResult &

"#endregion" & vbCrLf)


DTE.ExecuteCommand("Edit.FormatDocument")
End Sub

Private Function GetstrResult(ByVal text As

String) As String
Try
If (text.Contains("private")) Then
text = text.Replace("private",

"")
End If
If (text.Contains(";")) Then
text = text.Replace(";", "")
End If
Dim words() As String =

text.Trim.Split()


'System.Windows.Forms.MessageBox.Show(words(1))
If words.Length < 2 Then
Return ""
Else
Dim strResult As New

StringBuilder
strResult.AppendLine()


strResult.AppendLine(String.Format("public {0}

{1}", words(0), StrConv(words(1)(0),

VbStrConv.ProperCase)) & words(1).Substring(1))
strResult.AppendLine(vbTab & "{

get { ")
strResult.AppendLine(vbTab &

vbTab & "return " & words(1) & ";")
strResult.AppendLine(vbTab &

"}")


strResult.AppendLine(String.Format(vbTab &

"set"))
strResult.AppendLine(vbTab &

vbTab & " { " & words(1) & " = value;")
strResult.AppendLine(vbTab &

"}")
strResult.AppendLine("}")
Return strResult.ToString
End If
Catch ex As Exception


System.Windows.Forms.MessageBox.Show(ex.ToString

)
End Try

End Function

End Module


Issues:
Currently it will gives you incorrect result if the input is

string p = string.Empty;

You can customize macro according to your needs. The valid inputs are

string p;

private string q;

Just select and press your assigned shortcut.