C# Coding Standards
Posted in C#, Uncategorized on September 29, 2006 | No Comments »
C# Coding Standards here
Posted in C#, Uncategorized on September 29, 2006 | No Comments »
C# Coding Standards here
Posted in JavaScript, Uncategorized on September 29, 2006 | No Comments »
This is a cool script that gives the same effect as the C# string formating with multiple parameters. Check it out:
function format(str)
{
for(i = 1; i < arguments.length; i++)
{
str = str.replace(’{’ + (i - 1) + ‘}’, arguments[i]);
}
return str;
}
Example: <font color=”#008000″>greeting = format(’Hello {0} & {1} ‘, ‘John’, ‘Jane’);</font>
Posted in C#, Uncategorized on September 29, 2006 | No Comments »
This class can instantiate any class, from any namespace, with any kind and amount of parameters.
You only need to have in the instantiated class constructor, the code you need to execute without having to do a reflection on methods of the class and call them in a second step:
public class Factory
{
public Factory(object[] args, string [...]
Posted in C#, XML, XSLT on September 28, 2006 | No Comments »
Many things cannot be done in xslt directly due to a lack of manipulation functions. In order to cure that, Microsoft has provided a way to include c# code directly in xslt. Here’s an example:
<?xml version=“1.0“ encoding=“utf-8“ ?>
<xsl:stylesheet version=“1.0“ xmlns:xsl=“http://www.w3.org/1999/XSL/Transform“ xmlns:msxsl=“urn:schemas-microsoft-com:xslt“ xmlns:ClassNameHere=“dummy namespace here“>
<msxsl:script language=“C#“ implements-prefix=“ClassNameHere“>
<![CDATA[
public string MethodName(/* some parameters here*/)
[...]
Posted in XML, XSLT on September 19, 2006 | No Comments »
<?xml version=“1.0“ encoding=“UTF-8“ ?>
<xsl:stylesheet version=“1.0“ xmlns:xsl=“http://www.w3.org/1999/XSL/Transform“>
<xsl:output method=“xml“/>
<xsl:template match=“/“ >
<xsl:copy-of select=“.“/>
</xsl:template>
</xsl:stylesheet>
Posted in .Net, C#, Uncategorized on September 19, 2006 | No Comments »
Create .resx file and use this code:
string myValue = Resources.Messages.ResourceManager.GetString(myKey);
Where in resource file:
<data name=“myKey“ xml:space=“preserve“>
<value>myValue</value>
</data>
Posted in C#, XML on September 18, 2006 | No Comments »
Use this following static method to convert any xml to its object representation
public static object ToObject(Type objectType, string xml)
{
object obj = null;
try
{
XmlSerializer xs = new XmlSerializer(objectType);
obj = xs.Deserialize(new StringReader(xml));
}
catch (Exception ex)
{
}
return obj;
}
Posted in Uncategorized on September 18, 2006 | No Comments »
class Test
{
[STAThread]static void Main(string[] args)
{
ItemList myList = new ItemList();
myList.AddItem(new Item(“first”, 1));
myList.AddItem(new Item(“second”, 2));
myList.AddItem(new Item(“third”, 3));
// Serialization
XmlSerializer xs = new XmlSerializer(typeof(ItemList));
TextWriter tw = new StreamWriter(@”c:\list.xml”);
xs.Serialize(tw, myList);
tw.Close();
// Deserialization
ItemList newList;
TextReader tr = new StreamReader(@”c:\list.xml”);
newList = (ItemList)xs.Deserialize(tr);
tr.Close();
}
}
[XmlRoot("itemList")]
public class ItemList
{
private ArrayList listItem;
[...]
Posted in C#, XML on September 18, 2006 | No Comments »
Use this following static method to convert any serilizable object into its string representation
public static string ToString(object xmlObject)
{
XmlSerializer xs = new XmlSerializer(xmlObject.GetType());
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
string str = string.Empty;
try
{
xs.Serialize(sw, xmlObject);
str = sw.ToString();
}
catch (Exception ex)
{
}
return str;
}
Posted in C#, Uncategorized on September 18, 2006 | No Comments »
To convert an ArrayList to an array of strings, simply do the following:
string[] stringArray = (string[])arrayList.ToArray(typeof(string));
Where arrayList is an ArrayList of strings and stringArray is an array of strings.