コード例 #1
0
ファイル: ValidationHelper.cs プロジェクト: taori/WMPR
        internal static void ClearErrors(System.Collections.Generic.IDictionary <string, HashSet <string> > errors, ISupportValidation isv, string propertyName)
        {
            errors.Remove(propertyName);

            Execute.OnUIThread(() =>
            {
                isv.RaiseErrorsChanged(propertyName);
            });
        }
コード例 #2
0
        protected override void OnPageEncountered(Uri url, System.Collections.Generic.IDictionary <string, string> query, System.Collections.Generic.IDictionary <string, string> fragment)
        {
            // Remove state from dictionaries.
            // We are ignoring request state forgery status
            // as we're hitting an ASP.NET service which forwards
            // to a third-party OAuth service itself
            if (query.ContainsKey("state"))
            {
                query.Remove("state");
            }

            if (fragment.ContainsKey("state"))
            {
                fragment.Remove("state");
            }

            base.OnPageEncountered(url, query, fragment);
        }
コード例 #3
0
        /// <summary>生成有效签名</summary>
        /// <param name="@params"></param>
        /// <param name="secret"></param>
        /// <returns></returns>
        public static string Signature(System.Collections.Generic.IDictionary <string, string> @params, string secret, string signName)
        {
            string result = null;

            if (@params == null)
            {
                return(result);
            }
            // remove sign parameter
            @params.Remove(signName);

            IDictionary <string, string> treeMap = new SortedList <string, string>();

            //treeMap.PutAll(@params);
            foreach (KeyValuePair <string, string> kvp in @params)
            {
                treeMap.Add(kvp.Key, kvp.Value);
            }

            System.Collections.IEnumerator iter  = @treeMap.Keys.GetEnumerator();
            System.Text.StringBuilder      orgin = new System.Text.StringBuilder(secret);
            while (iter.MoveNext())
            {
                string name  = (string)iter.Current;
                string value = @treeMap[name];

                orgin.Append(name).Append(value);
            }
            try
            {
                result = Md5Hex(orgin.ToString());
            }
            catch (System.Exception)
            {
                throw new System.Exception("sign error !");
            }
            return(result);
        }
コード例 #4
0
        private static object ConvertDictionaryToObject(System.Collections.Generic.IDictionary <string, object> dictionary, System.Type type, JavaScriptSerializer serializer)
        {
            System.Type type2 = type;
            string      text  = null;
            object      obj   = dictionary;
            object      o;

            if (dictionary.TryGetValue("__type", out o))
            {
                text = (ObjectConverter.ConvertObjectToType(o, typeof(string), serializer) as string);
                if (text != null)
                {
                    if (serializer.TypeResolver != null)
                    {
                        type2 = serializer.TypeResolver.ResolveType(text);
                        if (type2 == null)
                        {
                            throw new System.InvalidOperationException();
                        }
                    }
                    dictionary.Remove("__type");
                }
            }
            JavaScriptConverter javaScriptConverter = null;
            object result;

            if (type2 != null && serializer.ConverterExistsForType(type2, out javaScriptConverter))
            {
                result = javaScriptConverter.Deserialize(dictionary, type2, serializer);
            }
            else
            {
                if (text != null || (type2 != null && ObjectConverter.IsClientInstantiatableType(type2, serializer)))
                {
                    obj = System.Activator.CreateInstance(type2);
                }
                System.Collections.Generic.List <string> list = new System.Collections.Generic.List <string>(dictionary.Keys);
                if (type != null && type.IsGenericType && (typeof(System.Collections.IDictionary).IsAssignableFrom(type) || type.GetGenericTypeDefinition() == ObjectConverter._idictionaryGenericType) && type.GetGenericArguments().Length == 2)
                {
                    System.Type type3 = type.GetGenericArguments()[0];
                    if (type3 != typeof(string) && type3 != typeof(object))
                    {
                        throw new System.InvalidOperationException(string.Format(System.Globalization.CultureInfo.InvariantCulture, "Type '{0}' is not supported for serialization/deserialization of a dictionary, keys must be strings or objects.", new object[]
                        {
                            type.FullName
                        }));
                    }
                    System.Type type4 = type.GetGenericArguments()[1];
                    System.Collections.IDictionary dictionary2 = null;
                    if (ObjectConverter.IsClientInstantiatableType(type, serializer))
                    {
                        dictionary2 = (System.Collections.IDictionary)System.Activator.CreateInstance(type);
                    }
                    else
                    {
                        System.Type type5 = ObjectConverter._dictionaryGenericType.MakeGenericType(new System.Type[]
                        {
                            type3,
                            type4
                        });
                        dictionary2 = (System.Collections.IDictionary)System.Activator.CreateInstance(type5);
                    }
                    if (dictionary2 != null)
                    {
                        foreach (string current in list)
                        {
                            dictionary2[current] = ObjectConverter.ConvertObjectToType(dictionary[current], type4, serializer);
                        }
                        result = dictionary2;
                        return(result);
                    }
                }
                if (type != null && !type.IsAssignableFrom(obj.GetType()))
                {
                    System.Reflection.ConstructorInfo constructor = type.GetConstructor(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public, null, ObjectConverter.s_emptyTypeArray, null);
                    if (constructor == null)
                    {
                        throw new System.MissingMethodException(string.Format(System.Globalization.CultureInfo.InvariantCulture, "No parameterless constructor defined for type of '{0}'.", new object[]
                        {
                            type.FullName
                        }));
                    }
                    throw new System.InvalidOperationException(string.Format(System.Globalization.CultureInfo.InvariantCulture, "Cannot deserialize object graph into type of '{0}'.", new object[]
                    {
                        type.FullName
                    }));
                }
                else
                {
                    foreach (string current in list)
                    {
                        object propertyValue = dictionary[current];
                        ObjectConverter.AssignToPropertyOrField(propertyValue, obj, current, serializer);
                    }
                    result = obj;
                }
            }
            return(result);
        }