Skip to main content

Posts

Showing posts from 2008

Static in C#

Staic Member: You can access static member through the name of the class in which it is declared. E.g. className.StaticMethod(); You cannot access a static member through the instance of its class. In C# there are no global methods. Static methods are similar to global method but with the advantage that they have access to local members. Equivalent of Static in VB.Net is Shared (and not Static which creates a variable that exists throughout the lifecycle of the program. Also it is not shared among different instance of the class.) For static methods to access the non static methods of the same class, they must create instance of the class. Static Constructor: It is guarnteed to run before the instance of the class is created. You cannot control when it will run though. No access modifiers are allowed on static contructors. You can use initializer instead of static constructor. Static class: useful in creating small utility class holding static methods. Also it makes sure that you dont

Copy Constructor

C# doesn't have Copy constructor like C++. Instead it provides ICloneable interface which has Clone method. Class that supports the idea of copy constructor should implement ICloneable interface and then implement Clone method either using Shallow Copy (??) calling MemberwiseClone or Deep copy (??) i.e hand coping all members. Shallow Copy Deep Copy

Microsoft Naming Conventions

Microsoft recommends following naming conventions Variables : use came case e.g. someName Method : use Pascal case e.g. SomeMethod. Also name the method by the action they perform e.g. WriteLine. Microsoft does not recommends Hungarian notation e.g. iSomeInteger or underscore e.g. Some_Integer. Coding standard: Always use this to refer to the members of current class. Never make a member field as public. Always create properties or methods to allow access to member fields.

XML to PDF in .Net

Has anyone used XALAN.Net to generate PDF from XML? It is working fine generating Pdf from FO but I am having problems if I generate FO using XslCompiledTransform to convert XML to FO. The FO file generated by using XslCompiledTransform is different compared to the file generated using XALAN in java. Both are using same style sheet. I am still scratching me head....any tip would be useful. I will post the solution if I can find any... Raj

Resources in ASP.Net

XML resouces provided for Global.asax and web forms. Resource name is webformname.aspx.resx and for Global.asaz it is Global.asax.resx You must add culture specific resources manually as there is no IDE support for this for web forms. Naming convention for culture specific resource is same as in windows application e.g. webformname.culture.resx. If these naming conventions are not followed, resource manager will not be able to find the resources. Main assembly will be deployed in \bin folder with culture specific assemblies beneith it e.g. \bin\en-US, \bin\en.

Resources for Windows Application

Resources are created automatically by default by VS.Net for Windows forms. They can be plain text files for string resources or XML files for string and binary resources. You can select language for each form and have different layout for each language. This creates satiellite assemblies for each language which are used by runtime depending on the culture selected. Each satellite assembly resides in a culture specific folder which uses ISO naming convention for e.g. for UK English it will be en-GB and for US English it would be en-US. There is no code in the resource dll. Main assembly will use resourse dll in sub directories e.g. en-GB\assemblyName.resources.dll. You can add custom resources. Naming convention for custom resource file [resourceType].[culture].resx. This way the culture specific custom resouce files will be compile in the satellite assemblies [undocumented feature]. Resouces files are deployed in \[culture] fodler for windows forms and \bin\[culture] folder for asp.ne

Setting up ASP.net for Globalization

You can set Globalization using <globalization> element in Machine.Config or Web.Config <globalization culture="en-US" uiCulture="en-US"/> By setting the culture to en-US, a date will be displayed on mm/dd/yyyy format. If we change the culture to en-GB, the date will be displayed as dd/mm/yyyy format. You can set Globalization setting for a specific folder using by using <location> element You can overwrite <globalization> setting by setting culture in <pages> element You can overwrite config setting at runtime.

Localization, Globalization and Internationalization

Often you need to develop web application which need to be in more than one language or display information depending on which country they are being accessed from. A simple classic way is to have folder files for each language. But this method is error prone and very difficult to manage as the number of language to display in grows. There is where ASP.net Globalization comes handy. Localization is the process of adapting the text and applications of a product or service to enable its acceptability for a particular cultural or linguistic market. Translation is the central activity of localization. Internationalization is planning and implementing products and services so that they can easily be localized for specific languages and cultures. Globalization is an approach to business strategy that aims to address all of the logistical and organizational challenges an enterprise faces as it expands its supporting content, assets and message across cultures and markets to new clients. Globa

Regular express in Oracle

I wanted to test a regular expression for post code validation against some real data. I have a list of postcodes from ONS in a database. I had an option to write a small vb program to query the database and then test each value against the regular express and then report pass or fail. But then I thought let see if Oracle provides some support for regular expression in the query. Eureka!!! Here it is to test a column against a regular expression.... SELECT zip FROM zipcode WHERE REGEXP_LIKE(zip, '[^[:digit:]]') The above query will bring all records matching the RE. For more details, visit http://www.oracle.com/technology/oramag/webcolumns/2003/techarticles/rischert_regexp_pt1.html