Multiline JavaScript Tip:

Ever wanted to have multi-line strings in JavaScript? Ever been sitting there putting html into javascript and having finish out each like with a “+. Well here is a way to perform the the return line without any breaking quote. A continuous string across spanning multiple lines. The simple answer is escape the end of the line with a backslash \ this will cause JavaScript to look for the char to escape and allow you to have clean looking HTML in JavaScipt without quotes.

Problem description

Feature ‘optional parameter’ cannot be used because it is not part of the 3.0 C# language specification

Uable to use Optional parameters in a Project targeting .net 3.5 or .net 3.0. Often times the server will support optional parameters as well as Visual Studio 2010.

What are Optional Parameters

public void MyMethod(String requiredParam, String optionalParam = String.Empty, Int32 optionalInt = 0) {}
The parameters followed by = sign are known as optional parameters and value after the equals sign the default value, which was a nice feature of C that C# originally had not replicated.

My Specific Senario (SharePoint 2007 to 2010 upgrade)

My specific senario is a SharePoint 2010 Custom Project. Specifically a couple layouts based application pages.
I am upgrading form a SharePoint 2007 Solution. So optional parameters are also available in SharePoint 2007 and WSS 3.0.

This article explains how to create custom serialization and deserialization events without having to inherit iSerializable.
This allows you to skip serialization on a field and then fill it in upon deserialization.

[XmlIgnore()]

class SomeClass {
[XmlIgnore] int someID;
public string someString;}

Serializing Events

The gist is put these items before an property:

[Serializable()]

[NonSerialized()]

And these are events that get called by serialization: (place in front of methods)

Example Serializing Events

// This is the object that will be serialized and deserialized.
[Serializable()]
public class TestSimpleObject
{
// This member is serialized and deserialized with no change.
public int member1;
// The value of this field is set and reset during and
// after serialization.
private string member2;
// This field is not serialized. The OnDeserializedAttribute
// is used to set the member value after serialization.
[NonSerialized()]
public string member3;
// This field is set to null, but populated after deserialization.
private string member4;
// Constructor for the class.
public TestSimpleObject()
{
member1 = 11;
member2 = "Hello World!";
member3 = "This is a nonserialized value";
member4 = null;
}
public void Print()
{
Console.WriteLine("member1 = '{0}'", member1);
Console.WriteLine("member2 = '{0}'", member2);
Console.WriteLine("member3 = '{0}'", member3);
Console.WriteLine("member4 = '{0}'", member4);
}
[OnSerializing()]
internal void OnSerializingMethod(StreamingContext context)
{
member2 = "This value went into the data file during serialization.";
}
[OnSerialized()]
internal void OnSerializedMethod(StreamingContext context)
{
member2 = "This value was reset after serialization.";
}
[OnDeserializing()]
internal void OnDeserializingMethod(StreamingContext context)
{
member3 = "This value was set during deserialization";
}
[OnDeserialized()]
internal void OnDeserializedMethod(StreamingContext context)
{
member4 = "This value was set after deserialization.";
}
}

My goal was to figure out the difference between two DateTime objects, more specifically how many days form a specific date. I Originally searched for DateTime.CompareTo hoping that would be the answer, however DateTime.CompareTo returns (-1, 0, 1) (Less Then, Equal To, Greater Then) respectivly.

Converts the value of the current TimeSpan object to its equivalent string representation. (Overrides ValueType.ToString.) [-][d.]hh:mm:ss[.fffffff] where – if you want to show if there is a negative time span, d = days, and fffffff is fraction seconds.