Archive for Gennaio 8th, 2008

Serilizer class using generics

CodeKeep C# Feed Gennaio 8th, 2008

Description: Serilize/deserialize an object to xml or xml to an object

Link: http://www.codekeep.net/snippets/1cb1b84b-dde7-4efe-931d-f7c4b1157a39.aspx

public class Serializer<T>
    {
        /// <summary>
        /// Converts the XML into an object
        /// </summary>
        /// <param name="xml">The XML representation of an object.</param>
        /// <returns>An object of type T.</returns>
        public static T Deserialize(string xml)
        {
            // convert to the serializable object
            T item;

            using (StringReader reader = new StringReader(xml))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(T));
                item = (T)serializer.Deserialize(reader);
            }

            return item;
        }

        /// <summary>
        /// Converts an object into XML.
        /// </summary>
        /// <param name="obj">The object to convert.</param>
        /// <returns>The XML representation of the object.</returns>
        public static string Serialize(T obj)
        {
            StringBuilder data = new StringBuilder();

            using (StringWriter writer = new StringWriter(data))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(T));
                serializer.Serialize(writer, obj);
            }

            return data.ToString();
        }
    }

WPF Double animation

CodeKeep C# Feed Gennaio 8th, 2008

Description: WPF Double animation

Link: http://www.codekeep.net/snippets/dd0f2fc3-e08a-4ed0-a72e-c3d0f84c6c6d.aspx

            DoubleAnimation da = new DoubleAnimation()
            {
                To = 0.0,
                Duration = TimeSpan.FromMilliseconds(1000),
                DecelerationRatio = .4
            };            
            this.logicalParent.fixedPanelHeaders.BeginAnimation(Canvas.TopProperty, da);

Review: Ajax Starter Kit

WebReference News Gennaio 8th, 2008

The term Ajax is often referred to as a new type of technology, but is actually several technologies that work together. How it does so is the subject of this article. By Lee Underwood. 1114

StartProcess

CodeKeep C# Feed Gennaio 8th, 2008

Description: Starts a new process

Link: http://www.codekeep.net/snippets/4a67750c-3dc4-447b-b517-2717622e0fe0.aspx

public void StartProcess(string fileName, ProcessWindowStyle windowStyle, object syncObject)
        {
            Process proc = new Process();
            ProcessStartInfo procInfo = new ProcessStartInfo(fileName);
            procInfo.WindowStyle = windowStyle;
            proc.SynchronizingObject = syncObject;
            proc.EnableRaisingEvents = true;
            proc.Start(procInfo);
        }