Пример #1
0
        /// <summary>
        /// Creates and returns a dynamic surrogate for the given <paramref name="type"/> parameter.
        /// </summary>
        /// <param name="type">The <see cref="Type"/> to generate the surrogate for</param>
        /// <returns>A dynamically generated <see cref="SerializationSurrogate"/></returns>
        public static SerializationSurrogate CreateTypeSurrogate(Type type, Hashtable attributeOrder, Hashtable nonCompactFields)
        {
            if (attributeOrder != null)
            {
                _attributeOrder = new Hashtable();
            }

            if (nonCompactFields != null)
            {
                _nonCompactFields = new Hashtable();
            }


            //'attributeOrder' contains definition of attributes of all classes registered to the compact framework, we only reguire of that specific type which is to be registered at the moment
            //FYI: _attributeOrder is global within this class and attributeOrder is the passed in parameter
            if (_attributeOrder != null && attributeOrder != null)
            {
                _attributeOrder.Add(type, attributeOrder[type.FullName]);
            }

            if (_nonCompactFields != null && nonCompactFields != null)
            {
                _nonCompactFields.Add(type, nonCompactFields);
            }

            Type surrogateType;

            if (type.IsValueType)
            {
                surrogateType = typeof(DynamicValueTypeSurrogate <>);
            }
            else
            {
                surrogateType = typeof(DynamicRefTypeSurrogate <>);
            }
            return((SerializationSurrogate)SurrogateHelper.CreateGenericTypeInstance(surrogateType, type));
        }