예제 #1
0
 /// <summary>
 /// Cause this XML writer to use the given <see cref="T:Northwoods.Go.Xml.IGoXmlTransformer" /> for
 /// objects of the type given by <paramref name="t" />.
 /// </summary>
 /// <param name="t">a <c>Type</c> representing a class; must not be null</param>
 /// <param name="g">
 /// an <see cref="T:Northwoods.Go.Xml.IGoXmlTransformer" />;
 /// if null, removes any existing transformer for the type <paramref name="t" />
 /// </param>
 /// <remarks>
 /// Although it's most common to use <see cref="M:Northwoods.Go.Xml.GoXmlReaderWriterBase.AddTransformer(Northwoods.Go.Xml.IGoXmlTransformer)" /> to register
 /// an <see cref="T:Northwoods.Go.Xml.IGoXmlTransformer" /> for a class Type, if you want to share
 /// the same transformer for multiple Types, you can do so using this method.
 /// </remarks>
 public IGoXmlTransformer SetTransformer(Type t, IGoXmlTransformer g)
 {
     if (t == null)
     {
         throw new ArgumentNullException("t");
     }
     myTransformers.TryGetValue(t, out IGoXmlTransformer value);
     if (g == null)
     {
         myTransformers.Remove(t);
     }
     else
     {
         if (this is GoXmlReader)
         {
             g.Reader = (GoXmlReader)this;
         }
         if (this is GoXmlWriter)
         {
             g.Writer = (GoXmlWriter)this;
         }
         g.TransformerType = t;
         myTransformers[t] = g;
     }
     return(value);
 }
예제 #2
0
 /// <summary>
 /// Cause this XML writer to use the given <see cref="T:Northwoods.Go.Xml.IGoXmlTransformer" /> for
 /// objects of the type given by the transformer's <see cref="P:Northwoods.Go.Xml.IGoXmlTransformer.TransformerType" />.
 /// </summary>
 /// <param name="g">an <see cref="T:Northwoods.Go.Xml.IGoXmlTransformer" /></param>
 public void AddTransformer(IGoXmlTransformer g)
 {
     if (g != null)
     {
         SetTransformer(g.TransformerType, g);
     }
 }
예제 #3
0
        /// <summary>
        /// Returns the first <see cref="T:Northwoods.Go.Xml.IGoXmlTransformer" /> associated with a given type or its base types.
        /// </summary>
        /// <param name="t">a <c>Type</c>, or null if <paramref name="t" /> is null</param>
        /// <returns>
        /// a <see cref="T:Northwoods.Go.Xml.IGoXmlTransformer" />, or null if the type and none of its
        /// base <c>Type</c>s have a transformer associated with it, as returned by
        /// calls to <see cref="M:Northwoods.Go.Xml.GoXmlReaderWriterBase.GetTransformer(System.Type)" />
        /// </returns>
        public IGoXmlTransformer FindTransformer(Type t)
        {
            Type type = t;

            while (type != null)
            {
                IGoXmlTransformer transformer = GetTransformer(type);
                if (transformer != null)
                {
                    return(transformer);
                }
                type = type.BaseType;
            }
            return(null);
        }