Techie Talks

Sunday, August 19, 2007

Mysterious disappearance of \r in new line during deserialization

I was trying to deserialize an XML into a business object, and found that all my multiline strings have "\n" as the new line character as opposed to the expected "\r\n".

The culprit turned out to be the reader used for deserialization. This issue will go away if XmlTextReader is used to read the xml (instead of TextReader or StreamReader).

Labels: , ,

Tuesday, July 25, 2006

Mapping a business object onto a Windows Forms DataGridViewComboBoxCell

Well, after about two weeks of fighting to solve this issue, I found a solution today.

Issue: Mapping a business object onto a Windows Forms DataGridViewComboBoxCell.

The crux of the issue arises from the fact that a DataGridViewComboBoxCell doesn't have a SelectedItem property.

Solution: Got it from here.

Overview: Add a proprety to the business object that refers to itself, and map it to the DataGridViewComboBoxCell's Value property.

E.g:

public class Dimension
{

    ...
    ...

    public Dimension Self
    { return this; }

   ...
   ...

}


Thursday, July 06, 2006

Using a router as a switch

In order to use a router to be used as a switch, do the following:

1) Disable DHCP in the router
2) Connect the connection to be swtiched to one of the output ports of the router.
3) Set a static IP for the router
4) Connect the devices receiving the switched connection to one of the remaining output ports

This way, the number of switced ports available would be total number of router output ports - 1.
(The WAN port of the router will be dumb, unused).

Advantages:
1. Make use of one of the "lying around" router as a switch.

Disadvantage:
1. Routers are costlier than switch. So, next time a router is needed, make sure you buy a switch instead and pull the router off this make-shift arrangement and use it.

Monday, July 03, 2006

Suggestion: Encapsulate-only field

How about a way of ensuring that a programmer uses only a property encapsulating a variable as opposed to directly acessing a variable?

e.g.:

// The property-only descriptor is the desired feature.
// The variable must be readable only in a fixed descriptor (MyInt)
// mentioned within the angle brackets.
private property-only<MyInt> int myInt;
public int MyInt
{
get { return myInt; } //OK to access the variable inside the descriptor
set { myInt = value; }
}

public int SecondAccessor
{
get { return myInt; } //Compiler must issue an error.
}

private void foo()
{
....
this.myInt = 10; //Compiler must issue an error
this.MyInt = 10; //OK
....
}

This way, it is ensured during compile time itself that no direct access to a particular variable within the code (except in the predetermined property) is allowed. This will be helpful

1) In cases in where reference variables are lazy initialized.
(eg: in get of MyRef property, if(myRef == null) myRef = new Ref(); return myRef;).

2) Moreover, ensures that the variables are initialized properly.

3) Also, it ensures access-time checking of variables - for bounds, value ranges, value legality etc.

4) Any "side-effect" code within the accessors are fired, for sure.

(Of course, for 2 and 3 the initialization/validation must be coded inside appropriate acessors. This method ensures that they are fired each time the local variable needs to be accessed, by protecting accidental access to local variable instead of the accessor.)

Update:

The current way of handling this issue is to name the private variable starting with an underscore ( _ ).

e.g.:
private int _myInt;
public int MyInt
{
get { return _myInt; }
set { _myInt = value; }
}

This does prevent ease of the local variable access to a great extent within the code. Yet, it doesn't warrant prevention against accidental access. However, since most of the errors would be happening while using autocomplete, I guess the underscore strategy would be good enough.

technorati tags:, , ,

Wednesday, June 21, 2006

ID3 Tag editing using Windows Explorer - Not anymore!?!

God help us all! I have been so used to using Windows Explorer to edit the ID3 tags of my music files.

Well, enter Windows XP 64bit, the facility is gone!! Why? Because WMP 10 has tag editing?? God knows!

Got a work around by opening the 32bit version of explorer by "run"ning "C:\windows\syswow64\explorer.exe /separate"

[Source: http://www.msfn.org/board/index.php?showtopic=56224]

Blogged with Flock

Wednesday, June 14, 2006

Google and Colors

Lemme keep this short. I have my personlized google page as my home page. I see the page atleast 200 times a day. Well, as a matter of fact, the sight of the page has become a bit insipid these days. A color burn kind of thing! There is absolutely nothing "wrong" with the color. But, with everything and anything customizeable these days, why not give an option to change from the default light-blue to something else?

Is there a way to do that already? Well, let me google for that... :D

technorati tags:,

Blogged with Flock

Test blog from Flock

Testing blogging from a new browser by name Flock from Mozilla. The blog input system is integrated into the browser as a tool :)

technorati tags:

Blogged with Flock

Cool! Flock rocks!

Tried this cool new browser today! Flock!! Amazing! Pretty neat features and keeping with Mozilla's (Oh! Did I mention that was Flock was by Mozilla) reputation of stability!

technorati tags:,

Blogged with Flock

Friday, April 28, 2006

Creating custom events for dum(m)i(e)s

Purpose: To explain the process of creating and handling custom events.
Steps:

1. Create a new class that extends the EventArgs class
e.g.:

public class DataLockReleasedEventArgs : EventArgs
{
//Add extra properties and construtors
}

2. Define the handler delegate
e.g.:

public delegate void DataLockReleasedEventHandler(object o, DataLockReleasedEventArgs e);

3. In the class that will be generating the event, define the event
e.g.:

public event DataLockReleasedEventHandler DataLockReleased;

4. In the class that will be generating the event, create the "On" method (normally protected)
e.g.:

protected static void OnDataLockReleased(DataLockReleasedEventArgs e)
{
if(DataLockReleased != null)
DataLockReleased(new object(), e); //Instead of new object, pass a meaningful object
}

5. In the class that will be generating the event, generate the event when appropriate
e.g.:

public void EventGenerationMethod(...)
{
...
...
DataLockReleasedEventArgs dlrEventArgs = new DataLockReleasedEventArgs(); //Use appr constr
//Fill in the eventargs properties as necessary
OnDataLockReleased(dlrEventArgs);
...
...
}

6. In the class that will be receiving the events, subscribe to the event, usually during the creation of the event defining class's object
e.g.:

public void CreationMethod()
{
EventDefiningClass evDefClass = new EventDefiningClass();
evDefClass.DataLockReleased += new DataLockReleasedEventHandler(evDefClass_DataLockReleased);
}

7. In the class that will be receiving the events, define the event handling method
e.g.:

void evDefClass_DataLockReleased(object o, DataLockReleasedEventArgs e)
{
//Handle the event
}