Monday, July 30, 2007

Experts exchange solutions

These are the best solutions provided by the experts in the www.experts-exchange.com for the last week.

Remember that if you want to see the solution you must register in the site first.

.NET
ASP.NET
VB.NET
C#
.NET Compact

Some good links July 30

Moving Projects/Solutions between Orcas and Visual Studio 2005 - http://www.west-wind.com/weblog/posts/122975.aspx

Nothin but .NET - Tips and Tricks - Day 3 - http://weblogs.asp.net/bsimser/archive/2007/07/26/nothin-but-net-tips-and-tricks-day-3.aspx

How to Use Web.Config in ASP.NET and ASP - http://vgbsoft.blogspot.com/2007/07/how-to-use-webconfig-in-aspnet-and-asp.html

A Generic State Machine and Attempt to Generic Component - http://www.codeproject.com/useritems/GenericStateMachine.asp

AWUI - a simple web user interface library with AJAX support - http://www.codeproject.com/Ajax/awui.asp

Using AJAX to populate a drop-down list in ASP.NET - http://www.codeproject.com/Ajax/PopulatingDropDownLists.asp

Email templates - http://www.codeproject.com/useritems/mailtemplates.asp

Sorting collection of custom types generically - http://www.codeproject.com/useritems/sorting_custom_types.asp

Nice VS 2008 Code Editing Improvements - http://weblogs.asp.net/scottgu/archive/2007/07/28/nice-vs-2008-code-editing-improvements.aspx

Dynamic Message Display (ASP.NET) - http://www.codeproject.com/useritems/Dynamic_Message_Display.asp

Diffrence between Oracle and sql server 2000 - http://www.dotnetspider.com/kb/Article3289.aspx

Monday, July 23, 2007

Interview questions

Long time ago Scott Hanselman post a blog's articles about ASP.NET Interview Questions and more generic questions about .net.
Today I have read another blog's post of Rodney Vinyard that gives more questions about interview about .Net framework - check it out.

New : Giving and taking an Interview (A brief article on interviewing both as an interviewer and interviewee)
New : IIS and .NET 2.0 interview questions Interview questions for .NET (Update 13/08/2007)

Wednesday, July 18, 2007

.NET Tips & Tricks by Michael Nemtsev

Today I've been reading about new features in .NET Framework, how the things can become better from a developer point of view and discovered an article written by Michael Nemtsev, Microsoft MVP that is collect a really huge list of facts and tips about .NET Framework - general issues, thrading, web applications, etc. Also this list become much more valued with the attached links with more information about each tip.

You must read and try to learn it as much as you can.

Monday, July 16, 2007

Count .NET projects lines

When developing an application using either C#, Visual Basic or C++ in .NET projects we discard to think about what is the amount of the code that we produce, what of the code is commented, etc.
However it is very usefull to have information how many lines of code are written in a file or in a project. Also how many lines of comments are included and so on.
This kind of information will not change anything in your project but should you direct you if the things are going well and can quickly answer you some simple questions - Is there any comments in this file/project? What is the total amount of code lines produced from the beginning of the project? What is the correlation between the autogenerated code and your 'true' code.

I've found a very nice utility that counts the number of lines in a C#, VB or C++ .NET solutions or projects related with the above questions.

Check this out.

How I am becoming a better developer, part 1 of infinity

Today I've read some very useful blog post that show me a Justice Gray's post about what and how a professional can be more than professional. Read this post! It's worth!! Also there are links to very cool and usefull books.

Friday, July 13, 2007

Create an ASP.NET ProgressBar

I was facing a lot of questions like "How to see the progress of uploading large files on my web site?" or "Can I integrate an upload progress in my web pages?" and etc. I have found a very good article for creating such progress bar on CodeProject but today reading the help.net blog finds out that it can be much easier to do that stuff. Check this article and make your life happier.

New (24/7/07): Here is another progress bar using ajax: AJAX file upload

Thursday, June 14, 2007

Do you know what has .NET Framework in it?

I just have found such a perfect post:
The Most Useful .NET Utility Classes Developers Tend To Reinvent Rather Than Reuse written by Phil Haack. This is a wonderful discussion with samples what is included in the .NET Framework that we should use direct from the System namespaces instead of writting custom methods.
I sugest you to read the comments too. There are some very useful notes.

Wednesday, May 9, 2007

Friday, January 12, 2007

Reflection: Modify value types by reflection

Yestarday I have seen a post in Experts-Exchange related with using reflection on structure in .net. The guy is trying to modify the content of the structure via reflection by passing an instance of the structure to a method. On first sight this is something real normal - using reflection go through fields, properties, etc., change values, invoke members and at the end of the method you will have complete new data in your structure.

Yes, but no thanks. This could not happend because the structure is value type and not reference type. In this case the code

MyStruct _name = new MyStruct();
_name.familyName = "Smith";
_name.givenName = "John";
foreach (FieldInfo fi in _name.GetType().GetFields())
{
fi.SetValue(_name, "set value test");
}

will not change the content of the structure at all. But this work perfect if you would use class instead of structure. I've decided to check if anybody on the net is trying to do things lilke this and of cource I saw a lot of articles on the net where programmers are talking about using ValueType object to work with strucutre in this situation.

So trying to move forward I have written this:

MyStruct _name = new MyStruct();
_name.familyName = "Smith";
_name.givenName = "John";

ValueType vt = _name;
FieldInfo[] fis = _name.GetType().GetFields();
for (int i = 0; i <>
{
FieldInfo fi = fis[i];
if (_name.GetType().IsValueType)
{
fi.SetValue(vt, "set value test");
fi.SetValue(_name, "Test");
}
}

This code should work like a sharp. In the above code when is using

fi.SetValue(_name, "Test");

the content of the structure will not be changed. But - the vt variable which is ValueType will be changed via the line

fi.SetValue(vt, "set value test");

So I believe this was the right way and the task is finished. I wanted to help the guy to change the values of the structure, I have found that using ValueType class is the right direction to do this and at the end of the code above I have the changed structure's fields.

Opps! I do not have the structure's fields changed! I do have changed the fields of the ValueType variable changed. So because the ValueType class is the base class of all value types, it is normal that you can not cast the variable vt back to the structure MyStructure type.

So at the end of writting this code I had changed the values of the fields but the result that had to return was not of type MyStruct and of type ValueType. What a hell? It is obviously that you could not change the structure's fields by reflection - BECAUSE IT IS A VALUE TYPE!

Ok! But there should be a way! There must be a way of passing to a method strucutre instance and return as a result instance of the same strucutre with changed by Reflection values.

All I had moving around is in some way calling the constructor of the structure by passing parammeters. Using Reflection is it not possible. Why? BECAUSE IT IS A VALUE TYPE!. And the code of using ConstructorInfo.Invoke will produce the same result like the code above - No change to the structure instance. Is there any other way a constructor can be called?

Yes! There is a way! In System namespace there is a class called Activator. And was happy to read the brief description of this class:
"Contains methods to create types of objects locally or remotely, or obtain references to existing remote objects. This class cannot be inherited."

So researching the class' methods I have found that there is a method CreateInstance that return the newly created instance (see that when using reflection and call the ConstructorInfo.Invoke you do not return any instance.The reflection is used the passed object and is trying to create the new instance on the passed variable).

So after reading a while and trying it I have finally written this which works like a charm:


public static MyStruct ChangeValues(MyStruct previousVersion)
{
MyStruct changedVersion = default(MyStruct);
ValueType valueType = previousVersion;

MemberInfo[] members = valueType.GetType().GetMembers();

for (int memberIndex = 0; memberIndex < style="color:#3333ff;">if (members[memberIndex].MemberType == MemberTypes.Field)
{
if (valueType.GetType().GetField(members[memberIndex].Name).FieldType == typeof(String))
{
changedVersion = (MyStruct)Activator.CreateInstance(changedVersion.GetType(), new object[] { "test", 3 });
}
}
}
return changedVersion;
}


public struct MyStruct
{
public String variableString;
public Int32 variableInt32;
public Boolean variableBoolean;

public MyStruct(String var1, Int32 var2)
{
variableString = var1;
variableInt32 = var2;
variableBoolean = false;
}
}

This finally, I think, finish the task of passing parameter of structure to the method and return a changed instance of the same structure using Reflection.

Regards

Tuesday, January 9, 2007

Debugging problems in .NET

I have faced very often these days problems when I started my Studio in Debuging mode.
Also many time in ExpertsExchange I'm talking with members in exaclty the same problems.

One of the very good document I have founded on the net is "my best friend" in all these situations. And when yestarday I found that is really hard to find this document out i decided to add another link to this document.

It is really cool to read it. Here it is