Esempio n. 1
0
    internal static ITypeWriter getWriter( Type type, IProtocolFormatter formatter, bool checkInterfaces )
      {
      // class can be null only when we traverse class hierarchy.
      // when we get to the ver root of it, the superclass is null.
      // return null here, so the outer code can use a default writer
      if ( type == null )
        return null;

      // perform the lookup. Let protocol formatter do the check for any
      // protocol specific type bindings
      ITypeWriter writer = null;

      if ( formatter != null )
        writer = formatter.getWriter( type );

      // check against the additional lookup table (this will override main table)
      if ( writer == null )
        additionalWriters.TryGetValue( type, out writer );

      // check against the main lookup table
      if ( writer == null )
        writers.TryGetValue( type, out writer );

      // if we have a writer - use it
      if ( writer != null )
        return writer;

      if ( type.IsArray )
        {
        if ( logSer )
          Log.log( LoggingConstants.SERIALIZATION, "object is an array returning ArrayWriter" );

        return arrayWriter;
        }
      else if ( typeof( Enum ).IsAssignableFrom( type ) )
        {
        if ( logSer )
          Log.log( LoggingConstants.SERIALIZATION, "object is an enumeration type" );

        return enumWriter;
        }

      if ( checkInterfaces )
        writer = matchInterfaces( type.GetInterfaces() );

      if ( writer != null )
        {
        if ( logSer )
          Log.log( LoggingConstants.SERIALIZATION, "found a writer for an interface - " + writer );

        return writer;
        }

      // go to the super class as the last resort
      return getWriter( type.BaseType, formatter, true );
      }
Esempio n. 2
0
        internal static ITypeWriter getWriter(Type type, IProtocolFormatter formatter, bool checkInterfaces)
        {
            // class can be null only when we traverse class hierarchy.
            // when we get to the ver root of it, the superclass is null.
            // return null here, so the outer code can use a default writer
            if (type == null)
            {
                return(null);
            }

            // perform the lookup. Let protocol formatter do the check for any
            // protocol specific type bindings
            ITypeWriter writer = null;

            if (formatter != null)
            {
                writer = formatter.getWriter(type);
            }

            // check against the additional lookup table (this will override main table)
            if (writer == null)
            {
                additionalWriters.TryGetValue(type, out writer);
            }

            // check against the main lookup table
            if (writer == null)
            {
                writers.TryGetValue(type, out writer);
            }

            // if we have a writer - use it
            if (writer != null)
            {
                return(writer);
            }

            if (type.IsArray)
            {
                if (logSer)
                {
                    Log.log(LoggingConstants.SERIALIZATION, "object is an array returning ArrayWriter");
                }

                return(arrayWriter);
            }
            else if (typeof(Enum).IsAssignableFrom(type))
            {
                if (logSer)
                {
                    Log.log(LoggingConstants.SERIALIZATION, "object is an enumeration type");
                }

                return(enumWriter);
            }

            if (checkInterfaces)
            {
                writer = matchInterfaces(type.GetInterfaces());
            }

            if (writer != null)
            {
                if (logSer)
                {
                    Log.log(LoggingConstants.SERIALIZATION, "found a writer for an interface - " + writer);
                }

                return(writer);
            }

            // go to the super class as the last resort
            return(getWriter(type.BaseType, formatter, true));
        }