Click here to Skip to main content
15,895,192 members
Home / Discussions / C#
   

C#

 
Questionhi need some suggestion regaurding my project Pin
srichakram_harsha28-Sep-09 1:01
srichakram_harsha28-Sep-09 1:01 
AnswerRe: hi need some suggestion regaurding my project Pin
Pete O'Hanlon28-Sep-09 1:17
mvePete O'Hanlon28-Sep-09 1:17 
AnswerRe: hi need some suggestion regaurding my project Pin
musefan28-Sep-09 1:56
musefan28-Sep-09 1:56 
GeneralRe: hi need some suggestion regaurding my project Pin
J4amieC28-Sep-09 2:31
J4amieC28-Sep-09 2:31 
GeneralRe: hi need some suggestion regaurding my project Pin
musefan28-Sep-09 2:44
musefan28-Sep-09 2:44 
GeneralRe: hi need some suggestion regaurding my project Pin
Richard MacCutchan28-Sep-09 3:42
mveRichard MacCutchan28-Sep-09 3:42 
Questionwhat is the best and the short way to limit textbox for only numbers Pin
E_Gold27-Sep-09 21:17
E_Gold27-Sep-09 21:17 
AnswerRe: what is the best and the short way to limit textbox for only numbers Pin
Sachin Dubey27-Sep-09 21:23
Sachin Dubey27-Sep-09 21:23 
AnswerRe: what is the best and the short way to limit textbox for only numbers Pin
Abhijit Jana27-Sep-09 21:23
professionalAbhijit Jana27-Sep-09 21:23 
AnswerRe: what is the best and the short way to limit textbox for only numbers Pin
DaveyM6927-Sep-09 22:04
professionalDaveyM6927-Sep-09 22:04 
AnswerRe: what is the best and the short way to limit textbox for only numbers Pin
molesworth27-Sep-09 23:33
molesworth27-Sep-09 23:33 
QuestionStartupMode for Services Pin
Vijjuuu.27-Sep-09 20:58
Vijjuuu.27-Sep-09 20:58 
AnswerRe: StartupMode for Services Pin
Abhijit Jana27-Sep-09 21:20
professionalAbhijit Jana27-Sep-09 21:20 
GeneralRe: StartupMode for Services Pin
Vijjuuu.27-Sep-09 21:24
Vijjuuu.27-Sep-09 21:24 
GeneralRe: StartupMode for Services Pin
Abhijit Jana27-Sep-09 21:40
professionalAbhijit Jana27-Sep-09 21:40 
AnswerRe: StartupMode for Services Pin
Calla27-Sep-09 21:48
Calla27-Sep-09 21:48 
GeneralRe: StartupMode for Services Pin
Abhijit Jana27-Sep-09 22:00
professionalAbhijit Jana27-Sep-09 22:00 
GeneralRe: StartupMode for Services Pin
Calla27-Sep-09 22:09
Calla27-Sep-09 22:09 
QuestionTranslation Of C# Class to XML And Vice versa Pin
Sachin Dubey27-Sep-09 19:59
Sachin Dubey27-Sep-09 19:59 
AnswerRe: Translation Of C# Class to XML And Vice versa Pin
Christian Graus27-Sep-09 20:24
protectorChristian Graus27-Sep-09 20:24 
GeneralRe: Translation Of C# Class to XML And Vice versa Pin
Sachin Dubey27-Sep-09 20:32
Sachin Dubey27-Sep-09 20:32 
GeneralRe: Translation Of C# Class to XML And Vice versa Pin
Christian Graus27-Sep-09 20:40
protectorChristian Graus27-Sep-09 20:40 
GeneralRe: Translation Of C# Class to XML And Vice versa Pin
Sachin Dubey27-Sep-09 20:44
Sachin Dubey27-Sep-09 20:44 
GeneralRe: Translation Of C# Class to XML And Vice versa Pin
0x3c027-Sep-09 21:04
0x3c027-Sep-09 21:04 
AnswerRe: Translation Of C# Class to XML And Vice versa Pin
freakyit27-Sep-09 23:27
freakyit27-Sep-09 23:27 
here i have an example for you to serialize and deserialize a class

/// <summary>
	    /// Method to convert a custom Object to XML string
	    /// </summary>
	    /// <param name="pObject">Object that is to be serialized to XML</param>
	    /// <returns>XML string</returns>
	    public string SerializeObject ( Object pObject, Type et )
	    {
	        try
	        {
	            String XmlizedString = null;
	            MemoryStream memoryStream = new MemoryStream ( );
	            XmlSerializer xs = new XmlSerializer ( et );
	            XmlTextWriter xmlTextWriter = new XmlTextWriter ( memoryStream, Encoding.UTF8 );
	            xmlTextWriter.Formatting = Formatting.Indented;
	            xmlTextWriter.Indentation = 4;
	            xs.Serialize ( xmlTextWriter, pObject );
	            memoryStream = ( MemoryStream ) xmlTextWriter.BaseStream;
	            XmlizedString = UTF8ByteArrayToString ( memoryStream.ToArray ( ) );
	            return XmlizedString;
	        }
	        catch ( Exception e )
	        {
	            System.Console.WriteLine ( e );
	            throw new Exception(e.Message,e);
	           // return null;
	        }
	    } 
	    
	    /// <summary>
	    /// Method to reconstruct an Object from XML string
	    /// </summary>
	    /// <param name="pXmlizedString"></param>
	    /// <returns></returns>
	    public Object DeserializeObject ( String pXmlizedString, Type e )
	    {
	        XmlSerializer xs = new XmlSerializer ( e );
	        MemoryStream memoryStream = new MemoryStream ( StringToUTF8ByteArray ( pXmlizedString ) );
	                
	        XmlTextWriter xmlTextWriter = new XmlTextWriter ( memoryStream , Encoding.UTF8 );
	 
	        return xs.Deserialize ( memoryStream );
	    }


and here the class how it looks.

[Serializable()]
[XmlRoot("Attrib")]
public class AttributeClass
{
    string sIdentifier;
    string sAlias;

    [XmlElement("Identifier")]
    public string Identifier {
        get { return sIdentifier; }
        set { sIdentifier = value; }
    }

    [XmlElement("Alias")]
    public string Alias {
        get { return sAlias; }
        set { sAlias = value; }
    }

}


and here the AttributeCollection as Class to serialize it..

	[Serializable()]
	[XmlRoot("AttribsList")]
	[XmlInclude(typeof(AttributeClass)),
	 XmlInclude(typeof(System.Collections.Generic.List<AttributeClass>))]
	public class AttribsList : System.Collections.Generic.List<AttributeClass>
	{
		/// <summary>
		/// Deserilizes the saved Xml AttribsList file to an object
		/// </summary>
		/// <param name="path">Path of the serilized XmlDataModelLayoutFile</param>
		/// <returns>XmlDataModelLayout object</returns>
		public static AttribsList LoadLayoutFromFile(string path)
		{
			try
			{
				string data_str = Core.SerializeHelper.ReadFromFile(path);
				Core.SerializeHelper sh = new Core.SerializeHelper();
				AttribsList list = (AttribsList)sh.DeserializeObject(data_str,typeof(AttribsList));
				
				return list;
			}
			catch
			{
				return null;
			}
		}
	
		/// <summary>
		/// Serilizes the Xml AttribsList object to file
		/// </summary>
		/// <param name="layout">XmlDataModelLayout object</param>
		/// <param name="path">FilePath to save object</param>
		public static void SaveLayout(AttribsList lst, string path)
		{
			Core.SerializeHelper sh = new Core.SerializeHelper();
			string data_str = sh.SerializeObject(lst,typeof(AttribsList ));
			
			Core.SerializeHelper.SaveToFile(path,data_str);
		}
       }
}

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.