public static NamedValueList <string> Decode(string formUrlEncodedString, string newLine = "\r\n") { const string encodedControlNameOrValuePattern = "((%[A-Fa-f0-9]{2})|[^%&=])*)"; const string encodedControlNameAndValuePattern = "(?<nameAndValue>(?<name>" + encodedControlNameOrValuePattern + ")=(?<value>" + encodedControlNameOrValuePattern + "))"; const string encodedPattern = "^(" + encodedControlNameAndValuePattern + "(&" + encodedControlNameAndValuePattern + ")*)?$"; var encodedRegEx = new Regex(encodedPattern); var match = encodedRegEx.Match(formUrlEncodedString); if (!match.Success) { throw new FormatException("The string '" + formUrlEncodedString + "' is not a valid form URL encoded string."); } var controlNameValuePairs = new NamedValueList <string>(); foreach (var controlNameValuePair in formUrlEncodedString.Split('&').Select(controlNameValuePairString => controlNameValuePairString.Split('='))) { controlNameValuePairs.Add( InternalDecode(controlNameValuePair[0], newLine), InternalDecode(controlNameValuePair[1], newLine)); } return(controlNameValuePairs); }
public NamedValueListControl() { InitializeComponent(); Items = new NamedValueList(); //ref.: (1) // This (1) is needed because: // http://msdn.microsoft.com/en-us/library/aa970563.aspx // Short explanation: // If your property is a reference type, the default value specified in dependency property // metadata is not a default value per instance; instead it is a default value that applies // to all instances of the type. // this.AutomaticRuntimeSize(); }
public static string Encode(NamedValueList <string> controls) { var sb = new StringBuilder(); var firstControl = true; foreach (var keyValuePair in controls) { var value = keyValuePair.Value; if (!firstControl) { sb.Append('&'); } sb.Append(InternalEncode(keyValuePair.Name, value)); firstControl = false; } return(sb.ToString()); }
private static void PopulateClassMembers(object p, NamedValueList namedValueList) { // public properties foreach (MemberInfo member in p.GetType().GetProperties()) { PropertyInfo pi = (PropertyInfo)member; namedValueList.Add(new NamedValuePair(member.Name, pi.GetValue(p, null), !pi.CanWrite)); } // public fields foreach (MemberInfo member in p.GetType().GetFields()) { FieldInfo fi = (FieldInfo)member; namedValueList.Add(new NamedValuePair(member.Name, fi.GetValue(p))); } // private fields foreach (MemberInfo member in p.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance)) { FieldInfo fi = (FieldInfo)member; namedValueList.Add(new NamedValuePair(member.Name, fi.GetValue(p))); } }
private void ApplySettings(object p, NamedValueList namedValueList) { // public properties foreach (MemberInfo member in p.GetType().GetProperties()) { PropertyInfo pi = (PropertyInfo)member; if (pi.CanWrite) { pi.SetValue(p, namedValueList[member.Name], null); } } // public fields foreach (MemberInfo member in p.GetType().GetFields()) { FieldInfo fi = (FieldInfo)member; fi.SetValue(p, namedValueList[member.Name]); } // private fields foreach (MemberInfo member in p.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance)) { FieldInfo fi = (FieldInfo)member; fi.SetValue(p, namedValueList[member.Name]); } }
private void ApplySettings(object p, NamedValueList namedValueList) { // public properties foreach (MemberInfo member in p.GetType().GetProperties()) { PropertyInfo pi = (PropertyInfo)member; if (pi.CanWrite) pi.SetValue(p, namedValueList[member.Name], null); } // public fields foreach (MemberInfo member in p.GetType().GetFields()) { FieldInfo fi = (FieldInfo)member; fi.SetValue(p, namedValueList[member.Name]); } // private fields foreach (MemberInfo member in p.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance)) { FieldInfo fi = (FieldInfo)member; fi.SetValue(p, namedValueList[member.Name]); } }