Beispiel #1
0
 public object defaultAdapt(ReferenceCache refCache)
 {
     if (mappedType != null)
     {
         if (typedObject is ICacheableAdaptingType)
         {
             return(((ICacheableAdaptingType)typedObject).adapt(mappedType, refCache));
         }
         else
         {
             return(typedObject.adapt(mappedType));
         }
     }
     else
     {
         if (typedObject is ICacheableAdaptingType)
         {
             return(((ICacheableAdaptingType)typedObject).defaultAdapt(refCache));
         }
         else
         {
             return(typedObject.defaultAdapt());
         }
     }
 }
 public object defaultAdapt( ReferenceCache refCache )
   {
   if ( realType is ICacheableAdaptingType )
     return ( (ICacheableAdaptingType)realType ).defaultAdapt( refCache );
   else
     return realType.defaultAdapt();
   }
Beispiel #3
0
 public object adapt(Type type, ReferenceCache refCache)
 {
     if (mappedType != null && type.IsAssignableFrom(mappedType))
     {
         if (typedObject is ICacheableAdaptingType)
         {
             return(((ICacheableAdaptingType)typedObject).adapt(mappedType, refCache));
         }
         else
         {
             return(typedObject.adapt(mappedType));
         }
     }
     else
     {
         if (typedObject is ICacheableAdaptingType)
         {
             return(((ICacheableAdaptingType)typedObject).adapt(type, refCache));
         }
         else
         {
             return(typedObject.adapt(type));
         }
     }
 }
 public object adapt( Type type, ReferenceCache refCache )
   {
   if ( realType is ICacheableAdaptingType )
     return ( (ICacheableAdaptingType)realType ).adapt( type, refCache );
   else
     return realType.adapt( type );
   }
Beispiel #5
0
        public object defaultAdapt(ReferenceCache refCache)
        {
            // server side support for javascript class aliasing
            if (properties.Contains(ORBConstants.CLASS_NAME_FIELD))
            {
                string clientClassName = (string)((IAdaptingType)properties[ORBConstants.CLASS_NAME_FIELD]).defaultAdapt();
                Type   type            = ORBConfig.GetInstance().getTypeMapper()._getServerTypeForClientClass(clientClassName);
                if (type != null)
                {
                    return(adapt(type));
                }
            }

#if (FULL_BUILD)
            Hashtable hashtable = new Hashtable();
#else
            Dictionary <Object, Object> hashtable = new Dictionary <Object, Object>();
#endif

            if (refCache.HasObject(this))
            {
                return(refCache.GetObject(this));
            }
            else
            {
                refCache.AddObject(this, hashtable);
            }

            ICollection keys = properties.Keys;

            foreach (object key in keys)
            {
                object obj = properties[key];

                if (obj != null)
                {
                    if (obj is IAdaptingType && refCache.HasObject((IAdaptingType)obj))
                    {
                        obj = refCache.GetObject((IAdaptingType)obj);
                    }
                    else if (obj is ICacheableAdaptingType)
                    {
                        ICacheableAdaptingType cacheableType = (ICacheableAdaptingType)obj;
                        object result = cacheableType.defaultAdapt(refCache);
                        refCache.AddObject((IAdaptingType)obj, result);
                        obj = result;
                    }
                    else if (obj is IAdaptingType)
                    {
                        obj = ((IAdaptingType)obj).defaultAdapt();
                    }
                }

                hashtable[key] = obj;
            }

            return(hashtable);
        }
 public object adapt(Type type, ReferenceCache refCache)
 {
     if (realType is ICacheableAdaptingType)
     {
         return(((ICacheableAdaptingType)realType).adapt(type, refCache));
     }
     else
     {
         return(realType.adapt(type));
     }
 }
 public object defaultAdapt(ReferenceCache refCache)
 {
     if (realType is ICacheableAdaptingType)
     {
         return(((ICacheableAdaptingType)realType).defaultAdapt(refCache));
     }
     else
     {
         return(realType.defaultAdapt());
     }
 }
Beispiel #8
0
    public object adapt( Type type, ReferenceCache refCache )
    {
      if( Object != null )
      {
        bool isCachable = Object is ICacheableAdaptingType;
        IAdaptingType cacheKey = isCachable ? ( Object as ICacheableAdaptingType ).getCacheKey() : Object;

        if( refCache.HasObject( cacheKey, type ) )
          return refCache.GetObject( cacheKey, type );

        return isCachable ? ( Object as ICacheableAdaptingType ).adapt( type, refCache ) : Object.adapt( type );
      }
      
      return null;
    }
Beispiel #9
0
    public object defaultAdapt( ReferenceCache refCache )
    {
      if( Object != null )
      {
        bool isCachable = Object is ICacheableAdaptingType;
        IAdaptingType cacheKey = isCachable ? ( Object as ICacheableAdaptingType ).getCacheKey() : Object;

        if( refCache.HasObject( cacheKey ) )
          return refCache.GetObject( cacheKey );

        return isCachable? (Object as ICacheableAdaptingType).defaultAdapt(refCache) : Object.defaultAdapt();
      }

      return null;
    }
Beispiel #10
0
 public object adapt( Type type, ReferenceCache refCache )
   {
   if ( mappedType != null && type.IsAssignableFrom( mappedType ) )
     {
     if ( typedObject is ICacheableAdaptingType )
       return ( (ICacheableAdaptingType)typedObject ).adapt( mappedType, refCache );
     else
       return typedObject.adapt( mappedType );
     }
   else
     {
     if ( typedObject is ICacheableAdaptingType )
       return ( (ICacheableAdaptingType)typedObject ).adapt( type, refCache );
     else
       return typedObject.adapt( type );
     }
   }
Beispiel #11
0
 public object defaultAdapt( ReferenceCache refCache )
   {
   if ( mappedType != null )
     {
     if ( typedObject is ICacheableAdaptingType )
       return ( (ICacheableAdaptingType)typedObject ).adapt( mappedType, refCache );
     else
       return typedObject.adapt( mappedType );
     }
   else
     {
     if ( typedObject is ICacheableAdaptingType )
       return ( (ICacheableAdaptingType)typedObject ).defaultAdapt( refCache );
     else
       return typedObject.defaultAdapt();
     }
   }
Beispiel #12
0
        public object adapt(Type type, ReferenceCache refCache)
        {
            if (Object != null)
            {
                bool          isCachable = Object is ICacheableAdaptingType;
                IAdaptingType cacheKey   = isCachable ? (Object as ICacheableAdaptingType).getCacheKey() : Object;

                if (refCache.HasObject(cacheKey, type))
                {
                    return(refCache.GetObject(cacheKey, type));
                }

                return(isCachable ? (Object as ICacheableAdaptingType).adapt(type, refCache) : Object.adapt(type));
            }

            return(null);
        }
Beispiel #13
0
        public object defaultAdapt(ReferenceCache refCache)
        {
            if (Object != null)
            {
                bool          isCachable = Object is ICacheableAdaptingType;
                IAdaptingType cacheKey   = isCachable ? (Object as ICacheableAdaptingType).getCacheKey() : Object;

                if (refCache.HasObject(cacheKey))
                {
                    return(refCache.GetObject(cacheKey));
                }

                return(isCachable? (Object as ICacheableAdaptingType).defaultAdapt(refCache) : Object.defaultAdapt());
            }

            return(null);
        }
Beispiel #14
0
    private object adaptArrayComponent( object obj, Type componentType, ReferenceCache refCache )
      {
      if ( Log.isLogging( LoggingConstants.DEBUG ) )
        {
        if ( componentType == null )
          Log.log( LoggingConstants.DEBUG, "adapting array component. Component type is unknown, will use default type adaptation" );
        else
          Log.log( LoggingConstants.DEBUG, "adapting array component. Component type is " + componentType.FullName );
        }

      object result;

      if ( obj is ICacheableAdaptingType )
        {
        if ( componentType == null )
          result = ( (ICacheableAdaptingType)obj ).defaultAdapt( refCache );
        else
          result = ( (ICacheableAdaptingType)obj ).adapt( componentType, refCache );
        }
      else if ( obj is IAdaptingType )
        {
        if ( componentType == null )
          result = ( (IAdaptingType)obj ).defaultAdapt();
        else
          result = ( (IAdaptingType)obj ).adapt( componentType );
        }
      else
        {
        //Vector support
        try
          {
#if FULL_BUILD
          result = Convert.ChangeType( obj, componentType );
#else
        result = Convert.ChangeType( obj, componentType, null );
#endif
          }
        catch ( Exception e )
          {
          throw new Exception( "array element is not adapting type", e );
          }
        }

      if ( Log.isLogging( LoggingConstants.DEBUG ) )
        {
        if ( result != null )
          {
          Log.log( LoggingConstants.DEBUG, "array component has been adapted to type " + result.GetType().FullName );
          Log.log( LoggingConstants.DEBUG, "array component value is " + result );
          }
        else
          {
          Log.log( LoggingConstants.DEBUG, "array component has been adapted to null value" );
          }
        }

      return result;
      }
Beispiel #15
0
    public object defaultAdapt( ReferenceCache refCache )
      {      
      // server side support for javascript class aliasing
      if ( properties.Contains( ORBConstants.CLASS_NAME_FIELD ) )
        {
        string clientClassName = (string) ( (IAdaptingType) properties[ ORBConstants.CLASS_NAME_FIELD ] ).defaultAdapt();
        Type type = ORBConfig.GetInstance().getTypeMapper()._getServerTypeForClientClass( clientClassName );
        if ( type != null )
          return adapt( type );
        }

#if (FULL_BUILD)
      Hashtable hashtable = new Hashtable();
#else
      Dictionary<Object, Object> hashtable = new Dictionary<Object, Object>();
#endif

      if( refCache.HasObject( this ) )
        return refCache.GetObject( this );
      else
        refCache.AddObject( this, hashtable );

      ICollection keys = properties.Keys;

      foreach ( object key in keys )
        {
        object obj = properties[ key ];

        if ( obj != null )
          {
          if ( obj is IAdaptingType && refCache.HasObject( (IAdaptingType)obj ) )
            {
            obj = refCache.GetObject( (IAdaptingType)obj );
            }
          else if ( obj is ICacheableAdaptingType )
            {
              ICacheableAdaptingType cacheableType = (ICacheableAdaptingType) obj;
              object result = cacheableType.defaultAdapt( refCache );
              refCache.AddObject( (IAdaptingType) obj, result );
              obj = result;
            }
          else if ( obj is IAdaptingType )
            {
            obj = ( (IAdaptingType)obj ).defaultAdapt();
            }
          }

        hashtable[ key ] = obj;
        }

      return hashtable;
      }
Beispiel #16
0
        private object adaptArrayComponent(object obj, Type componentType, ReferenceCache refCache)
        {
            if (Log.isLogging(LoggingConstants.DEBUG))
            {
                if (componentType == null)
                {
                    Log.log(LoggingConstants.DEBUG, "adapting array component. Component type is unknown, will use default type adaptation");
                }
                else
                {
                    Log.log(LoggingConstants.DEBUG, "adapting array component. Component type is " + componentType.FullName);
                }
            }

            object result;

            if (obj is ICacheableAdaptingType)
            {
                if (componentType == null)
                {
                    result = ((ICacheableAdaptingType)obj).defaultAdapt(refCache);
                }
                else
                {
                    result = ((ICacheableAdaptingType)obj).adapt(componentType, refCache);
                }
            }
            else if (obj is IAdaptingType)
            {
                if (componentType == null)
                {
                    result = ((IAdaptingType)obj).defaultAdapt();
                }
                else
                {
                    result = ((IAdaptingType)obj).adapt(componentType);
                }
            }
            else
            {
                //Vector support
                try
                {
#if FULL_BUILD
                    result = Convert.ChangeType(obj, componentType);
#else
                    result = Convert.ChangeType(obj, componentType, null);
#endif
                }
                catch (Exception e)
                {
                    throw new Exception("array element is not adapting type", e);
                }
            }

            if (Log.isLogging(LoggingConstants.DEBUG))
            {
                if (result != null)
                {
                    Log.log(LoggingConstants.DEBUG, "array component has been adapted to type " + result.GetType().FullName);
                    Log.log(LoggingConstants.DEBUG, "array component value is " + result);
                }
                else
                {
                    Log.log(LoggingConstants.DEBUG, "array component has been adapted to null value");
                }
            }

            return(result);
        }
Beispiel #17
0
        public object adapt(Type type, ReferenceCache refCache)
        {
            if (refCache.HasObject(this, type))
            {
                return(refCache.GetObject(this, type));
            }

            object obj = ObjectFactories.CreateArgumentObject(type, this);

            if (obj != null)
            {
                refCache.AddObject(this, type, obj);
                return(obj);
            }

            if (type.Equals(typeof(IAdaptingType)))
            {
                refCache.AddObject(this, type, obj);
                return(this);
            }

            if (!type.IsArray)
            {
                obj = ObjectFactories.CreateServiceObject(type);
                refCache.AddObject(this, type, obj);
            }

            //refCache[ this ] = obj;

            if (obj is IDictionary)
            {
                IDictionary dictionary = (IDictionary)obj;
                ICollection keys       = properties.Keys;

                foreach (object key in keys)
                {
                    object valueObj = properties[key];

                    if (valueObj != null)
                    {
                        if (type.IsGenericType)
                        {
                            Type[] args = type.GetGenericArguments();

                            if (valueObj is ICacheableAdaptingType)
                            {
                                valueObj = ((ICacheableAdaptingType)valueObj).adapt(args[1]);
                            }
                            else if (valueObj is IAdaptingType)
                            {
                                valueObj = ((IAdaptingType)valueObj).adapt(args[1]);
                            }
                        }
                        else
                        {
                            if (valueObj is ICacheableAdaptingType)
                            {
                                valueObj = ((ICacheableAdaptingType)valueObj).defaultAdapt(refCache);
                            }
                            else if (valueObj is IAdaptingType)
                            {
                                valueObj = ((IAdaptingType)valueObj).defaultAdapt();
                            }
                        }
                    }

                    object keyValue = key;

                    if (type.IsGenericType && key is IAdaptingType)
                    {
                        Type[] args = type.GetGenericArguments();
                        keyValue = ((IAdaptingType)key).adapt(args[0]);
                    }

                    dictionary.Add(keyValue, valueObj);
                }
            }
            else if (type.IsArray && canBeArray())
            {
                Type  elementType = type.GetElementType();
                Array newArray    = Array.CreateInstance(elementType, properties.Count);
                refCache.AddObject(this, type, newArray);

                foreach (String key in properties.Keys)
                {
                    int index;
                    int.TryParse(key, out index);
                    object valueObj = properties[key];

                    if (valueObj is ICacheableAdaptingType)
                    {
                        valueObj = ((ICacheableAdaptingType)valueObj).adapt(elementType, refCache);
                    }
                    else if (valueObj is IAdaptingType)
                    {
                        valueObj = ((IAdaptingType)valueObj).adapt(elementType);
                    }

                    newArray.SetValue(valueObj, index);
                }

                obj = newArray;
            }
            else if (type.BaseType == null)
            {
                return(defaultAdapt(refCache));
            }
#if (FULL_BUILD)
            else if (obj is StringDictionary || typeof(StringDictionary).IsAssignableFrom(type))
            {
                StringDictionary strDict = (StringDictionary)obj;
                ICollection      keys    = properties.Keys;

                foreach (object key in keys)
                {
                    string mappedValue;
                    object valueObj = properties[key];

                    if (valueObj is ICacheableAdaptingType)
                    {
                        mappedValue = (string)((ICacheableAdaptingType)valueObj).adapt(typeof(string), refCache);
                    }
                    else if (valueObj is IAdaptingType)
                    {
                        mappedValue = (string)((IAdaptingType)valueObj).adapt(typeof(string));
                    }
                    else
                    {
                        mappedValue = valueObj.ToString();
                    }

                    strDict.Add(key.ToString(), mappedValue);
                }
            }
#endif
            else
            {
                //if( accessCheckSuppressed )
                setFieldsDirect(obj, properties, refCache);
                //else
                //    setFieldsAsBean( obj, properties );
            }

            return(obj);
        }
Beispiel #18
0
    public object defaultAdapt( ReferenceCache refCache )
      {

      if ( refCache.HasObject( this ) )
        return refCache.GetObject( this );

      int size = arrayObject.Length;

      if ( isHomogeneous() )
        {
        Array array = Array.CreateInstance( getComponentType(), size );
        //refCache[ this ] = array;

        refCache.AddObject( this, array );
        for ( int i = 0; i < size; i++ )
          {
          object obj = arrayObject[ i ];

          if ( obj != null )
            {
            if ( obj is IAdaptingType && refCache.HasObject( (IAdaptingType)obj ) )
              {
              obj = refCache.GetObject( (IAdaptingType)obj );
              }
            else if ( obj is ICacheableAdaptingType )
              {
              object value = ( (ICacheableAdaptingType)obj ).defaultAdapt( refCache );
              //refCache[ obj ] = value;
              refCache.AddObject( (IAdaptingType)obj, value );
              obj = value;
              }
            else if ( obj is IAdaptingType )
              {
              obj = ( (IAdaptingType)obj ).defaultAdapt();
              }
            }

          array.SetValue( obj, i );
          }

        return array;
        }
      else
        {
        object[] array = new object[ size ];
        //refCache[ this ] = array;

        refCache.AddObject( this, array );

        for ( int i = 0; i < size; i++ )
          {
          object obj = arrayObject[ i ];

          if ( obj != null )
            {
            if ( obj is IAdaptingType && refCache.HasObject( (IAdaptingType)obj ) )
              {
              //obj = refCache[ obj ];

              obj = refCache.GetObject( (IAdaptingType)obj );
              }
            else if ( obj is ICacheableAdaptingType )
              {
              object val = ( (ICacheableAdaptingType)obj ).defaultAdapt();
              //refCache[ obj ] = val;

              refCache.AddObject( (IAdaptingType)obj, val );

              obj = val;
              }
            else if ( obj is IAdaptingType )
              {
              obj = ( (IAdaptingType)obj ).defaultAdapt();
              }
            }

          array[ i ] = obj;
          }

        return array;
        }
      }
Beispiel #19
0
        public object defaultAdapt(ReferenceCache refCache)
        {
            if (refCache.HasObject(this))
            {
                return(refCache.GetObject(this));
            }

            int size = arrayObject.Length;

            if (isHomogeneous())
            {
                Array array = Array.CreateInstance(getComponentType(), size);
                //refCache[ this ] = array;

                refCache.AddObject(this, array);
                for (int i = 0; i < size; i++)
                {
                    object obj = arrayObject[i];

                    if (obj != null)
                    {
                        if (obj is IAdaptingType && refCache.HasObject((IAdaptingType)obj))
                        {
                            obj = refCache.GetObject((IAdaptingType)obj);
                        }
                        else if (obj is ICacheableAdaptingType)
                        {
                            object value = ((ICacheableAdaptingType)obj).defaultAdapt(refCache);
                            //refCache[ obj ] = value;
                            refCache.AddObject((IAdaptingType)obj, value);
                            obj = value;
                        }
                        else if (obj is IAdaptingType)
                        {
                            obj = ((IAdaptingType)obj).defaultAdapt();
                        }
                    }

                    array.SetValue(obj, i);
                }

                return(array);
            }
            else
            {
                object[] array = new object[size];
                //refCache[ this ] = array;

                refCache.AddObject(this, array);

                for (int i = 0; i < size; i++)
                {
                    object obj = arrayObject[i];

                    if (obj != null)
                    {
                        if (obj is IAdaptingType && refCache.HasObject((IAdaptingType)obj))
                        {
                            //obj = refCache[ obj ];

                            obj = refCache.GetObject((IAdaptingType)obj);
                        }
                        else if (obj is ICacheableAdaptingType)
                        {
                            object val = ((ICacheableAdaptingType)obj).defaultAdapt();
                            //refCache[ obj ] = val;

                            refCache.AddObject((IAdaptingType)obj, val);

                            obj = val;
                        }
                        else if (obj is IAdaptingType)
                        {
                            obj = ((IAdaptingType)obj).defaultAdapt();
                        }
                    }

                    array[i] = obj;
                }

                return(array);
            }
        }
Beispiel #20
0
    public object adapt( Type type, ReferenceCache refCache )
      {
      if ( refCache.HasObject( this, type ) )
        {
        /*object obj = refCache[ this ];

        if( type.IsAssignableFrom( obj.GetType() ) )
            return obj;*/

        return refCache.GetObject( this, type );
        }

      if ( Log.isLogging( LoggingConstants.DEBUG ) )
        Log.log( LoggingConstants.DEBUG, "ArrayType.adapt, adapting type: " + type.FullName );

      int size = arrayObject.Length;

      if ( type.Equals( typeof( IAdaptingType ) ) )
        {
        if ( Log.isLogging( LoggingConstants.DEBUG ) )
          Log.log( LoggingConstants.DEBUG, "type is an adapting type" );

        return this;
        }
      else if ( type.IsArray )
        {
        if ( Log.isLogging( LoggingConstants.DEBUG ) )
          Log.log( LoggingConstants.DEBUG, "type is array" );

        Type componentType = type.GetElementType();

        if ( Log.isLogging( LoggingConstants.DEBUG ) )
          {
          if ( componentType != null )
            Log.log( LoggingConstants.DEBUG, "array element type is " + componentType.FullName );
          else
            Log.log( LoggingConstants.DEBUG, "array element type is null" );
          }

        Array newArray = Array.CreateInstance( componentType, size );
        //refCache[ this ] = newArray;

        refCache.AddObject( this, type, newArray );

        for ( int i = 0; i < size; i++ )
          newArray.SetValue( adaptArrayComponent( arrayObject[ i ], componentType, refCache ), i );

        return newArray;
        }
      else if ( type.IsGenericType && type.GetGenericArguments().Length == 2 )
        {
        Type constructedType = Types.Types.GetAbstractClassMapping( type );

        Type genericTypeDef = type.GetGenericTypeDefinition();
        Type[] genericArgs = type.GetGenericArguments();

        if ( constructedType == null )
          constructedType = genericTypeDef.MakeGenericType( genericArgs );

        object newDictionary = Activator.CreateInstance( constructedType );
        refCache.AddObject( this, type, newDictionary );
        Type keyValuePairType = typeof( KeyValuePair );
        MethodInfo addMethod = constructedType.GetMethod( "Add", genericArgs );
        object[] args = new object[ 2 ];

        for ( int i = 0; i < arrayObject.Length; i++ )
          {
          KeyValuePair kvPair = (KeyValuePair)( (IAdaptingType)arrayObject[ i ] ).adapt( keyValuePairType );

          args[ 0 ] = kvPair.key.adapt( genericArgs[ 0 ] );
          args[ 1 ] = kvPair.value.adapt( genericArgs[ 1 ] );

          addMethod.Invoke( newDictionary, args );
          }

        return newDictionary;
        }
      else if ( type.GetInterface( "ICollection`1", true ) != null )
        {
        Type genericCollection = type.GetInterface( "ICollection`1", true );
        Type elementType = genericCollection.GetGenericArguments()[ 0 ];
        object collection = ObjectFactories.CreateServiceObject( type );

        if( Log.isLogging( LoggingConstants.DEBUG ) )
          Log.log( LoggingConstants.DEBUG, "created service object which is a collection" );

        refCache.AddObject( this, type, collection );
        MethodInfo addMethod = type.GetMethod( "Add", new Type[] { elementType } );

        if ( addMethod == null )
          addMethod = collection.GetType().GetMethod( "Add", new Type[] { elementType } );

        object[] args = new object[ 1 ];

        for ( int i = 0; i < arrayObject.Length; i++ )
          {
          //args[ 0 ] = ((IAdaptingType) arrayObject[ i ]).adapt( elementType );
          args[ 0 ] = adaptArrayComponent( arrayObject[ i ], elementType, refCache );

          if( Log.isLogging( LoggingConstants.DEBUG ) )
            Log.log( LoggingConstants.DEBUG, "invoking method Add to add item to collection" );

          addMethod.Invoke( collection, args );

          if( Log.isLogging( LoggingConstants.DEBUG ) )
            Log.log( LoggingConstants.DEBUG, "item has been added" );
          }

        return collection;
        }
      else if ( typeof( IList ).IsAssignableFrom( type ) )
        {
#if FULL_BUILD
        if(!(type is WebORBArrayCollection) && this is ArrayCollectionType)
        {
          return ((ArrayCollectionType) this).GetArrayType().adapt(type);
        }
#endif
        IList listObject = (IList)ObjectFactories.CreateServiceObject( type );
        //refCache[ this ] = listObject;

        refCache.AddObject( this, type, listObject );

        if ( Log.isLogging( LoggingConstants.DEBUG ) )
          Log.log( LoggingConstants.DEBUG, "will populate service objects with elements. got " + size + " items" );

        Type componentType = null;

        if ( type.IsGenericType )
          componentType = type.GetGenericArguments()[ 0 ];

        for ( int i = 0; i < size; i++ )
          {
          if ( Log.isLogging( LoggingConstants.DEBUG ) )
            Log.log( LoggingConstants.DEBUG, "element " + i + "   " + arrayObject[ i ] );

          listObject.Add( adaptArrayComponent( arrayObject[ i ], componentType, refCache ) );
          }

        if ( Log.isLogging( LoggingConstants.DEBUG ) )
          Log.log( LoggingConstants.DEBUG, "returning list. list size is " + listObject.Count );

        return listObject;
        }
#if (FULL_BUILD)
      else if ( typeof( Queue ).IsAssignableFrom( type ) )
        {
        if ( Log.isLogging( LoggingConstants.DEBUG ) )
          Log.log( LoggingConstants.DEBUG, "type is Queue" );

        Queue qObject = (Queue)ObjectFactories.CreateServiceObject( type );
        //refCache[ this ] = qObject;

        refCache.AddObject( this, type, qObject );

        for ( int i = 0; i < size; i++ )
          qObject.Enqueue( adaptArrayComponent( arrayObject[ i ], null, refCache ) );

        return qObject;
        }
      else if ( typeof( Stack ).IsAssignableFrom( type ) )
        {
        if ( Log.isLogging( LoggingConstants.DEBUG ) )
          Log.log( LoggingConstants.DEBUG, "type is Stack" );

        Stack stackObject = (Stack)ObjectFactories.CreateServiceObject( type );
        //refCache[ this ] = stackObject;

        refCache.AddObject( this, type, stackObject );

        for ( int i = 0; i < size; i++ )
          stackObject.Push( adaptArrayComponent( arrayObject[ i ], null, refCache ) );

        return stackObject;
        }
      else if ( typeof( SortedList ).IsAssignableFrom( type ) )
        {
        if ( Log.isLogging( LoggingConstants.DEBUG ) )
          Log.log( LoggingConstants.DEBUG, "type is SortedList" );

        SortedList sortedList = (SortedList)ObjectFactories.CreateServiceObject( type );
        //refCache[ this ] = sortedList;

        refCache.AddObject( this, type, sortedList );

        for ( int i = 0; i < size; i++ )
          {
          object obj = adaptArrayComponent( arrayObject[ i ], null, refCache );
          sortedList.Add( obj, obj );
          }

        return sortedList;
        }
#endif
      else if ( type.GetInterface( "Iesi.Collections.ISet", true ) != null || type.FullName.Equals( "Iesi.Collections.ISet" ) )
        {
        if ( Log.isLogging( LoggingConstants.DEBUG ) )
          Log.log( LoggingConstants.DEBUG, "type is Iesi.Collections.ISet" );

        Object iSet = ObjectFactories.CreateServiceObject( type );

        refCache.AddObject( this, type, iSet );
        MethodInfo addMethod = iSet.GetType().GetMethod( "Add", new Type[] { typeof( Object ) } );
        Object[] args = new Object[ 1 ];

        for ( int i = 0; i < size; i++ )
          {
          args[ 0 ] = adaptArrayComponent( arrayObject[ i ], null, refCache );
          addMethod.Invoke( iSet, args );
          }

        return iSet;
        }
#if (FULL_BUILD)
      // this is a hack for Flash Builder 4
      else if ( typeof( IDictionary ).IsAssignableFrom( type ) && ( arrayObject == null || arrayObject.Length == 0 ) )
        {
        return new Hashtable();
        }
#endif
      else
        {
        if ( Log.isLogging( LoggingConstants.DEBUG ) )
          Log.log( LoggingConstants.DEBUG, "will do default adaptation" );

        return defaultAdapt( refCache );
        }
      }
Beispiel #21
0
    private void setFieldsDirect( object obj, IDictionary properties, ReferenceCache referenceCache )
      {
        if( ReportUnderflow )
        {
          Dictionary<object, object> propertiesCopy = new Dictionary<object, object>();

          foreach (object key in properties.Keys)
            propertiesCopy.Add( key, properties[ key ] );

          properties = propertiesCopy;
        }

      Type type = obj.GetType();

      

      bool logDebug = Log.isLogging( LoggingConstants.DEBUG );

      while ( !Object.ReferenceEquals( type, typeof( object ) ) )
        {
        FieldInfo[] fields = type.GetFields( BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static );

        foreach ( FieldInfo field in fields )
          {
            if( (field.Attributes & FieldAttributes.Literal) == FieldAttributes.Literal )
              continue;

          IMemberRenameAttribute[] renamers = (IMemberRenameAttribute[])field.GetCustomAttributes( typeof( IMemberRenameAttribute ), true );
          string memberName = field.Name;

          if ( renamers.Length > 0 )
            memberName = renamers[ 0 ].GetClientName( type, field );

          object fieldValue = properties[ memberName ];

          if ( fieldValue == null )
            {
#if(FULL_BUILD)
            SerializationConfigHandler serializationConfig = (SerializationConfigHandler)ORBConfig.GetInstance().GetConfig( "weborb/serialization" );

            if( serializationConfig != null && serializationConfig.Keywords.Contains( memberName ) )
              {
              memberName = serializationConfig.PrefixForKeywords + memberName;
              fieldValue = properties[ memberName ];

              if ( fieldValue == null )
                continue;
              }
            else
              {
              continue;
              }
#endif
#if( SILVERLIGHT || PURE_CLIENT_LIB || WINDOWS_PHONE8 )
                      continue;
#endif
            }

          if ( fieldValue is IAdaptingType )
            {
            if ( logDebug )
              {
              Log.log( LoggingConstants.DEBUG, "initializing field " + field.Name );
              Log.log( LoggingConstants.DEBUG, "field type - " + field.FieldType.FullName );
              }

            object val = ObjectFactories.CreateArgumentObject( field.FieldType, (IAdaptingType)fieldValue );

            if ( val != null )
              {
              if ( logDebug )
                Log.log( LoggingConstants.DEBUG, "argument factory created object for the field " + val );

              //referenceCache[ fieldValue ] = val;

              referenceCache.AddObject( (IAdaptingType)fieldValue, field.FieldType, val );

              fieldValue = val;
              }
            else
              {
              if ( logDebug )
                Log.log( LoggingConstants.DEBUG, "argument factory is missing or returned no value. will use type adaptation" );

              if ( fieldValue is ICacheableAdaptingType )
                fieldValue = ( (ICacheableAdaptingType)fieldValue ).adapt( field.FieldType, referenceCache );
              else
                fieldValue = ( (IAdaptingType)fieldValue ).adapt( field.FieldType );
              }
            }

          if( ReportUnderflow )
            properties.Remove( memberName );

          try
            {
            field.SetValue( obj, fieldValue );
            }
          catch ( Exception e )
            {
            if ( Log.isLogging( LoggingConstants.INFO ) )
              Log.log( LoggingConstants.INFO, "field name - " + field.Name );
            throw e;
            }
          }

        PropertyInfo[] props = type.GetProperties( BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static );

        foreach ( PropertyInfo prop in props )
          {
          if ( !prop.CanWrite )
            continue;

          IMemberRenameAttribute[] renamers = (IMemberRenameAttribute[])prop.GetCustomAttributes( typeof( IMemberRenameAttribute ), true );
          string memberName = prop.Name;

          if ( renamers.Length > 0 )
            memberName = renamers[ 0 ].GetClientName( type, prop );

          object propValue = properties[ memberName ];

          if ( propValue == null )
            {
#if(FULL_BUILD)
            SerializationConfigHandler serializationConfig = (SerializationConfigHandler)ORBConfig.GetInstance().GetConfig( "weborb/serialization" );

            if( serializationConfig != null && serializationConfig.Keywords.Contains( memberName ) )
              {
              memberName = serializationConfig.PrefixForKeywords + memberName;
              propValue = properties[ memberName ];

              if ( propValue == null )
                continue;
              }
            else
              {
              continue;
              }
#endif
#if(SILVERLIGHT || PURE_CLIENT_LIB || WINDOWS_PHONE8 )
              continue;
#endif
            }

          if ( propValue is IAdaptingType )
            {
            if ( logDebug )
              {
              Log.log( LoggingConstants.DEBUG, "initializing property " + prop.Name );
              Log.log( LoggingConstants.DEBUG, "property type - " + prop.PropertyType.FullName );
              }

            object val = ObjectFactories.CreateArgumentObject( prop.PropertyType, (IAdaptingType)propValue );

            if ( val != null )
              {
              if ( logDebug )
                Log.log( LoggingConstants.DEBUG, "argument factory created object for the field " + val );

              //referenceCache[ propValue ] = val;
              referenceCache.AddObject( (IAdaptingType)propValue, prop.PropertyType, val );

              propValue = val;
              }
            else
              {
              if ( logDebug )
                Log.log( LoggingConstants.DEBUG, "argument factory is missing or returned no value. will use type adaptation" );

              if ( propValue is ICacheableAdaptingType )
                propValue = ( (ICacheableAdaptingType)propValue ).adapt( prop.PropertyType, referenceCache );
              else
                propValue = ( (IAdaptingType)propValue ).adapt( prop.PropertyType );
              }
            }

          if( ReportUnderflow )
            properties.Remove( memberName );

          prop.SetValue( obj, propValue, null );
          }

        type = type.BaseType;
        }

      if( ReportUnderflow && properties.Count > 0 )
        ReportObjectUnderflow( obj, properties );
      }
Beispiel #22
0
        public object adapt(Type type, ReferenceCache refCache)
        {
            if (refCache.HasObject(this, type))
            {
                /*object obj = refCache[ this ];
                 *
                 * if( type.IsAssignableFrom( obj.GetType() ) )
                 *  return obj;*/

                return(refCache.GetObject(this, type));
            }

            if (Log.isLogging(LoggingConstants.DEBUG))
            {
                Log.log(LoggingConstants.DEBUG, "ArrayType.adapt, adapting type: " + type.FullName);
            }

            int size = arrayObject.Length;

            if (type == typeof(IAdaptingType))
            {
                if (Log.isLogging(LoggingConstants.DEBUG))
                {
                    Log.log(LoggingConstants.DEBUG, "type is an adapting type");
                }

                return(this);
            }
            else if (type.IsArray)
            {
                if (Log.isLogging(LoggingConstants.DEBUG))
                {
                    Log.log(LoggingConstants.DEBUG, "type is array");
                }

                Type componentType = type.GetElementType();

                if (Log.isLogging(LoggingConstants.DEBUG))
                {
                    if (componentType != null)
                    {
                        Log.log(LoggingConstants.DEBUG, "array element type is " + componentType.FullName);
                    }
                    else
                    {
                        Log.log(LoggingConstants.DEBUG, "array element type is null");
                    }
                }

                Array newArray = Array.CreateInstance(componentType, size);
                //refCache[ this ] = newArray;

                refCache.AddObject(this, type, newArray);

                for (int i = 0; i < size; i++)
                {
                    newArray.SetValue(adaptArrayComponent(arrayObject[i], componentType, refCache), i);
                }

                return(newArray);
            }
            else if (type.IsGenericType && type.GetGenericArguments().Length == 2)
            {
                Type constructedType = Types.Types.GetAbstractClassMapping(type);

                Type   genericTypeDef = type.GetGenericTypeDefinition();
                Type[] genericArgs    = type.GetGenericArguments();

                if (constructedType == null)
                {
                    constructedType = genericTypeDef.MakeGenericType(genericArgs);
                }

                object newDictionary = Activator.CreateInstance(constructedType);
                refCache.AddObject(this, type, newDictionary);
                Type       keyValuePairType = typeof(KeyValuePair);
                MethodInfo addMethod        = constructedType.GetMethod("Add", genericArgs);
                object[]   args             = new object[2];

                for (int i = 0; i < arrayObject.Length; i++)
                {
                    KeyValuePair kvPair = (KeyValuePair)((IAdaptingType)arrayObject[i]).adapt(keyValuePairType);

                    args[0] = kvPair.key.adapt(genericArgs[0]);
                    args[1] = kvPair.value.adapt(genericArgs[1]);

                    addMethod.Invoke(newDictionary, args);
                }

                return(newDictionary);
            }
            else if (type.GetInterface("System.Collections.Generic.ICollection`1") != null)
            {
                Type   genericCollection = type.GetInterface("System.Collections.Generic.ICollection`1");
                Type   elementType       = genericCollection.GetGenericArguments()[0];
                object collection        = ObjectFactories.CreateServiceObject(type);

                if (Log.isLogging(LoggingConstants.DEBUG))
                {
                    Log.log(LoggingConstants.DEBUG, "created service object which is a collection");
                }

                refCache.AddObject(this, type, collection);
                MethodInfo addMethod = type.GetMethod("Add", new Type[] { elementType });

                if (addMethod == null)
                {
                    addMethod = collection.GetType().GetMethod("Add", new Type[] { elementType });
                }

                object[] args = new object[1];

                for (int i = 0; i < arrayObject.Length; i++)
                {
                    //args[ 0 ] = ((IAdaptingType) arrayObject[ i ]).adapt( elementType );
                    args[0] = adaptArrayComponent(arrayObject[i], elementType, refCache);

                    if (Log.isLogging(LoggingConstants.DEBUG))
                    {
                        Log.log(LoggingConstants.DEBUG, "invoking method Add to add item to collection");
                    }

                    addMethod.Invoke(collection, args);

                    if (Log.isLogging(LoggingConstants.DEBUG))
                    {
                        Log.log(LoggingConstants.DEBUG, "item has been added");
                    }
                }

                return(collection);
            }
            else if (typeof(IList).IsAssignableFrom(type))
            {
#if FULL_BUILD
                if (!(type is WebORBArrayCollection) && this is ArrayCollectionType)
                {
                    return(((ArrayCollectionType)this).GetArrayType().adapt(type));
                }
#endif
                IList listObject = (IList)ObjectFactories.CreateServiceObject(type);
                //refCache[ this ] = listObject;

                refCache.AddObject(this, type, listObject);

                if (Log.isLogging(LoggingConstants.DEBUG))
                {
                    Log.log(LoggingConstants.DEBUG, "will populate service objects with elements. got " + size + " items");
                }

                Type componentType = null;

                if (type.IsGenericType)
                {
                    componentType = type.GetGenericArguments()[0];
                }

                for (int i = 0; i < size; i++)
                {
                    if (Log.isLogging(LoggingConstants.DEBUG))
                    {
                        Log.log(LoggingConstants.DEBUG, "element " + i + "   " + arrayObject[i]);
                    }

                    listObject.Add(adaptArrayComponent(arrayObject[i], componentType, refCache));
                }

                if (Log.isLogging(LoggingConstants.DEBUG))
                {
                    Log.log(LoggingConstants.DEBUG, "returning list. list size is " + listObject.Count);
                }

                return(listObject);
            }
#if (FULL_BUILD)
            else if (typeof(Queue).IsAssignableFrom(type))
            {
                if (Log.isLogging(LoggingConstants.DEBUG))
                {
                    Log.log(LoggingConstants.DEBUG, "type is Queue");
                }

                Queue qObject = (Queue)ObjectFactories.CreateServiceObject(type);
                //refCache[ this ] = qObject;

                refCache.AddObject(this, type, qObject);

                for (int i = 0; i < size; i++)
                {
                    qObject.Enqueue(adaptArrayComponent(arrayObject[i], null, refCache));
                }

                return(qObject);
            }
            else if (typeof(Stack).IsAssignableFrom(type))
            {
                if (Log.isLogging(LoggingConstants.DEBUG))
                {
                    Log.log(LoggingConstants.DEBUG, "type is Stack");
                }

                Stack stackObject = (Stack)ObjectFactories.CreateServiceObject(type);
                //refCache[ this ] = stackObject;

                refCache.AddObject(this, type, stackObject);

                for (int i = 0; i < size; i++)
                {
                    stackObject.Push(adaptArrayComponent(arrayObject[i], null, refCache));
                }

                return(stackObject);
            }
            else if (typeof(SortedList).IsAssignableFrom(type))
            {
                if (Log.isLogging(LoggingConstants.DEBUG))
                {
                    Log.log(LoggingConstants.DEBUG, "type is SortedList");
                }

                SortedList sortedList = (SortedList)ObjectFactories.CreateServiceObject(type);
                //refCache[ this ] = sortedList;

                refCache.AddObject(this, type, sortedList);

                for (int i = 0; i < size; i++)
                {
                    object obj = adaptArrayComponent(arrayObject[i], null, refCache);
                    sortedList.Add(obj, obj);
                }

                return(sortedList);
            }
#endif
            else if (type.GetInterface("Iesi.Collections.ISet") != null || type.FullName.Equals("Iesi.Collections.ISet"))
            {
                if (Log.isLogging(LoggingConstants.DEBUG))
                {
                    Log.log(LoggingConstants.DEBUG, "type is Iesi.Collections.ISet");
                }

                Object iSet = ObjectFactories.CreateServiceObject(type);

                refCache.AddObject(this, type, iSet);
                MethodInfo addMethod = iSet.GetType().GetMethod("Add", new Type[] { typeof(Object) });
                Object[]   args      = new Object[1];

                for (int i = 0; i < size; i++)
                {
                    args[0] = adaptArrayComponent(arrayObject[i], null, refCache);
                    addMethod.Invoke(iSet, args);
                }

                return(iSet);
            }
#if (FULL_BUILD)
            // this is a hack for Flash Builder 4
            else if (typeof(IDictionary).IsAssignableFrom(type) && (arrayObject == null || arrayObject.Length == 0))
            {
                return(new Hashtable());
            }
#endif
            else
            {
                if (Log.isLogging(LoggingConstants.DEBUG))
                {
                    Log.log(LoggingConstants.DEBUG, "will do default adaptation");
                }

                return(defaultAdapt(refCache));
            }
        }
Beispiel #23
0
        private void setFieldsDirect(object obj, IDictionary properties, ReferenceCache referenceCache)
        {
            if (ReportUnderflow)
            {
                Dictionary <object, object> propertiesCopy = new Dictionary <object, object>();

                foreach (object key in properties.Keys)
                {
                    propertiesCopy.Add(key, properties[key]);
                }

                properties = propertiesCopy;
            }

            Type type = obj.GetType();



            bool logDebug = Log.isLogging(LoggingConstants.DEBUG);

            while (!Object.ReferenceEquals(type, typeof(object)))
            {
                FieldInfo[] fields = type.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);

                foreach (FieldInfo field in fields)
                {
                    if ((field.Attributes & FieldAttributes.Literal) == FieldAttributes.Literal)
                    {
                        continue;
                    }

                    IMemberRenameAttribute[] renamers = (IMemberRenameAttribute[])field.GetCustomAttributes(typeof(IMemberRenameAttribute), true);
                    string memberName = field.Name;

                    if (renamers.Length > 0)
                    {
                        memberName = renamers[0].GetClientName(type, field);
                    }

                    object fieldValue = properties[memberName];

                    if (fieldValue == null)
                    {
#if (FULL_BUILD)
                        SerializationConfigHandler serializationConfig = (SerializationConfigHandler)ORBConfig.GetInstance().GetConfig("weborb/serialization");

                        if (serializationConfig != null && serializationConfig.Keywords.Contains(memberName))
                        {
                            memberName = serializationConfig.PrefixForKeywords + memberName;
                            fieldValue = properties[memberName];

                            if (fieldValue == null)
                            {
                                continue;
                            }
                        }
                        else
                        {
                            continue;
                        }
#endif
#if (SILVERLIGHT || PURE_CLIENT_LIB || WINDOWS_PHONE8)
                        continue;
#endif
                    }

                    if (fieldValue is IAdaptingType)
                    {
                        if (logDebug)
                        {
                            Log.log(LoggingConstants.DEBUG, "initializing field " + field.Name);
                            Log.log(LoggingConstants.DEBUG, "field type - " + field.FieldType.FullName);
                        }

                        object val = ObjectFactories.CreateArgumentObject(field.FieldType, (IAdaptingType)fieldValue);

                        if (val != null)
                        {
                            if (logDebug)
                            {
                                Log.log(LoggingConstants.DEBUG, "argument factory created object for the field " + val);
                            }

                            //referenceCache[ fieldValue ] = val;

                            referenceCache.AddObject((IAdaptingType)fieldValue, field.FieldType, val);

                            fieldValue = val;
                        }
                        else
                        {
                            if (logDebug)
                            {
                                Log.log(LoggingConstants.DEBUG, "argument factory is missing or returned no value. will use type adaptation");
                            }

                            if (fieldValue is ICacheableAdaptingType)
                            {
                                fieldValue = ((ICacheableAdaptingType)fieldValue).adapt(field.FieldType, referenceCache);
                            }
                            else
                            {
                                fieldValue = ((IAdaptingType)fieldValue).adapt(field.FieldType);
                            }
                        }
                    }

                    if (ReportUnderflow)
                    {
                        properties.Remove(memberName);
                    }

                    try
                    {
                        field.SetValue(obj, fieldValue);
                    }
                    catch (Exception e)
                    {
                        if (Log.isLogging(LoggingConstants.INFO))
                        {
                            Log.log(LoggingConstants.INFO, "field name - " + field.Name);
                        }
                        throw e;
                    }
                }

                PropertyInfo[] props = type.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);

                foreach (PropertyInfo prop in props)
                {
                    if (!prop.CanWrite)
                    {
                        continue;
                    }

                    IMemberRenameAttribute[] renamers = (IMemberRenameAttribute[])prop.GetCustomAttributes(typeof(IMemberRenameAttribute), true);
                    string memberName = prop.Name;

                    if (renamers.Length > 0)
                    {
                        memberName = renamers[0].GetClientName(type, prop);
                    }

                    object propValue = properties[memberName];

                    if (propValue == null)
                    {
#if (FULL_BUILD)
                        SerializationConfigHandler serializationConfig = (SerializationConfigHandler)ORBConfig.GetInstance().GetConfig("weborb/serialization");

                        if (serializationConfig != null && serializationConfig.Keywords.Contains(memberName))
                        {
                            memberName = serializationConfig.PrefixForKeywords + memberName;
                            propValue  = properties[memberName];

                            if (propValue == null)
                            {
                                continue;
                            }
                        }
                        else
                        {
                            continue;
                        }
#endif
#if (SILVERLIGHT || PURE_CLIENT_LIB || WINDOWS_PHONE8)
                        continue;
#endif
                    }

                    if (propValue is IAdaptingType)
                    {
                        if (logDebug)
                        {
                            Log.log(LoggingConstants.DEBUG, "initializing property " + prop.Name);
                            Log.log(LoggingConstants.DEBUG, "property type - " + prop.PropertyType.FullName);
                        }

                        object val = ObjectFactories.CreateArgumentObject(prop.PropertyType, (IAdaptingType)propValue);

                        if (val != null)
                        {
                            if (logDebug)
                            {
                                Log.log(LoggingConstants.DEBUG, "argument factory created object for the field " + val);
                            }

                            //referenceCache[ propValue ] = val;
                            referenceCache.AddObject((IAdaptingType)propValue, prop.PropertyType, val);

                            propValue = val;
                        }
                        else
                        {
                            if (logDebug)
                            {
                                Log.log(LoggingConstants.DEBUG, "argument factory is missing or returned no value. will use type adaptation");
                            }

                            if (propValue is ICacheableAdaptingType)
                            {
                                propValue = ((ICacheableAdaptingType)propValue).adapt(prop.PropertyType, referenceCache);
                            }
                            else
                            {
                                propValue = ((IAdaptingType)propValue).adapt(prop.PropertyType);
                            }
                        }
                    }

                    if (ReportUnderflow)
                    {
                        properties.Remove(memberName);
                    }

                    prop.SetValue(obj, propValue, null);
                }

                type = type.BaseType;
            }

            if (ReportUnderflow && properties.Count > 0)
            {
                ReportObjectUnderflow(obj, properties);
            }
        }
Beispiel #24
0
    public object adapt( Type type, ReferenceCache refCache )
      {
      if ( refCache.HasObject( this, type ) )
        return refCache.GetObject( this, type );

      object obj = ObjectFactories.CreateArgumentObject( type, this );

      if ( obj != null )
        {
        refCache.AddObject( this, type, obj );
        return obj;
        }

      if ( type.Equals( typeof( IAdaptingType ) ) )
        {
        refCache.AddObject( this, type, obj );
        return this;
        }

      if ( !type.IsArray )
        {
        obj = ObjectFactories.CreateServiceObject( type );
        refCache.AddObject( this, type, obj );
        }

      //refCache[ this ] = obj;

      if ( obj is IDictionary )
        {
        IDictionary dictionary = (IDictionary)obj;
        ICollection keys = properties.Keys;

        foreach ( object key in keys )
          {
          object valueObj = properties[ key ];

          if ( valueObj != null )
            {
            if ( type.IsGenericType )
              {
              Type[] args = type.GetGenericArguments();

              if ( valueObj is ICacheableAdaptingType )
                valueObj = ( (ICacheableAdaptingType)valueObj ).adapt( args[ 1 ] );
              else if ( valueObj is IAdaptingType )
                valueObj = ( (IAdaptingType)valueObj ).adapt( args[ 1 ] );
              }
            else
              {
              if ( valueObj is ICacheableAdaptingType )
                valueObj = ( (ICacheableAdaptingType)valueObj ).defaultAdapt( refCache );
              else if ( valueObj is IAdaptingType )
                valueObj = ( (IAdaptingType)valueObj ).defaultAdapt();
              }
            }

          object keyValue = key;

          if ( type.IsGenericType && key is IAdaptingType )
            {
            Type[] args = type.GetGenericArguments();
            keyValue = ( (IAdaptingType)key ).adapt( args[ 0 ] );
            }

          dictionary.Add( keyValue, valueObj );
          }
        }
      else if ( type.IsArray && canBeArray() )
        {
        Type elementType = type.GetElementType();
        Array newArray = Array.CreateInstance( elementType, properties.Count );
        refCache.AddObject( this, type, newArray );

        foreach ( String key in properties.Keys )
          {
          int index;
          int.TryParse( key, out index );
          object valueObj = properties[ key ];

          if ( valueObj is ICacheableAdaptingType )
            valueObj = ( (ICacheableAdaptingType)valueObj ).adapt( elementType, refCache );
          else if ( valueObj is IAdaptingType )
            valueObj = ( (IAdaptingType)valueObj ).adapt( elementType );

          newArray.SetValue( valueObj, index );
          }

        obj = newArray;
        }
      else if ( type.BaseType == null )
        {
        return defaultAdapt( refCache );
        }
#if( FULL_BUILD)
      else if ( obj is StringDictionary || typeof( StringDictionary ).IsAssignableFrom( type ) )
        {
        StringDictionary strDict = (StringDictionary)obj;
        ICollection keys = properties.Keys;

        foreach ( object key in keys )
          {
          string mappedValue;
          object valueObj = properties[ key ];

          if ( valueObj is ICacheableAdaptingType )
            mappedValue = (string)( (ICacheableAdaptingType)valueObj ).adapt( typeof( string ), refCache );
          else if ( valueObj is IAdaptingType )
            mappedValue = (string)( (IAdaptingType)valueObj ).adapt( typeof( string ) );
          else
            mappedValue = valueObj.ToString();

          strDict.Add( key.ToString(), mappedValue );
          }
        }
#endif
      else
        {
        //if( accessCheckSuppressed )
        setFieldsDirect( obj, properties, refCache );
        //else
        //    setFieldsAsBean( obj, properties );
        }

      return obj;
      }