示例#1
0
        /// <summary>
        /// This is used to acquire a <c>Converter</c> instance from
        /// the registry. All instances are cached to reduce the overhead
        /// of lookups during the serialization process. Converters are
        /// lazily instantiated and so are only created if demanded.
        /// </summary>
        /// <param name="type">
        /// this is the type to find the converter for
        /// </param>
        /// <returns>
        /// this returns the converter instance for the type
        /// </returns>
        public Converter Create(Class type)
        {
            Converter converter = binder.Lookup(type);

            if (converter != null)
            {
                cache.cache(type, converter);
            }
            return(converter);
        }
示例#2
0
        /// <summary>
        /// This is used to instantiate the converter based on the type
        /// provided. If the type provided can not be instantiated for
        /// some reason then an exception is thrown from this method.
        /// </summary>
        /// <param name="type">
        /// this is the converter type to be instantiated
        /// </param>
        /// <param name="factory">
        /// this is the constructor used to instantiate
        /// </param>
        /// <returns>
        /// this returns an instance of the provided type
        /// </returns>
        public Converter GetConverter(Class type, Constructor factory)
        {
            Converter converter = (Converter)factory.newInstance();

            if (converter != null)
            {
                cache.cache(type, converter);
            }
            return(converter);
        }