UrlEncodedParameterWriter.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Services / Web / System / Web / Services / Protocols / UrlEncodedParameterWriter.cs / 1305376 / UrlEncodedParameterWriter.cs

                            //------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------------------- 

namespace System.Web.Services.Protocols { 
    using System.IO; 
    using System;
    using System.Text; 
    using System.Xml.Serialization;
    using System.Reflection;
    using System.Collections;
    using System.Web.Services; 

    ///  
    ///  
    ///    [To be supplied.]
    ///  
    public abstract class UrlEncodedParameterWriter : MimeParameterWriter {
        ParameterInfo[] paramInfos;
        int numberEncoded;
        Encoding encoding; 

        ///  
        public override Encoding RequestEncoding { 
            get { return encoding; }
            set { encoding = value; } 
        }

        /// 
        ///  
        ///    [To be supplied.]
        ///  
        public override object GetInitializer(LogicalMethodInfo methodInfo) { 
            if (!ValueCollectionParameterReader.IsSupported(methodInfo)) return null;
            return methodInfo.InParameters; 
        }

        /// 
        ///  
        ///    [To be supplied.]
        ///  
        public override void Initialize(object initializer) { 
            this.paramInfos = (ParameterInfo[])initializer;
        } 

        /// 
        /// 
        ///    [To be supplied.] 
        /// 
        protected void Encode(TextWriter writer, object[] values) { 
            numberEncoded = 0; 
            for (int i = 0; i < paramInfos.Length; i++) {
                ParameterInfo paramInfo = paramInfos[i]; 
                if (paramInfo.ParameterType.IsArray) {
                    Array array = (Array)values[i];
                    for (int j = 0; j < array.Length; j++) {
                        Encode(writer, paramInfo.Name, array.GetValue(j)); 
                    }
                } 
                else { 
                    Encode(writer, paramInfo.Name, values[i]);
                } 
            }
        }

        ///  
        protected void Encode(TextWriter writer, string name, object value) {
            if (numberEncoded > 0) writer.Write('&'); 
            writer.Write(UrlEncode(name)); 
            writer.Write('=');
            writer.Write(UrlEncode(ScalarFormatter.ToString(value))); 
            numberEncoded++;
        }

        string UrlEncode(string value) { 
            if (encoding != null)
                return UrlEncoder.UrlEscapeString(value, encoding); 
            else 
                return UrlEncoder.UrlEscapeStringUnicode(value);
        } 
    }

}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK