Пример #1
0
        CanSerializeClrProperty(
            Object serializableObject,
            TypePropertyCache property,
            ReachSerializationServices reachSerializationServices
            )
        {
            bool canSerialize = true;

            if (serializableObject != null &&
                property != null &&
                property.PropertyInfo != null)
            {
                String name = property.PropertyInfo.Name;

                Hashtable clrPropertiesTable = (Hashtable)reachSerializationServices.
                                               TypeNoneSerializableClrProperties[serializableObject.GetType()];

                if (clrPropertiesTable != null)
                {
                    if (clrPropertiesTable.Contains(name))
                    {
                        canSerialize = false;
                    }
                }
            }

            return(canSerialize);
        }
Пример #2
0
 CanSerializeClrProperty(
     Object serializableObject,
     TypePropertyCache property
     )
 {
     return(true);
 }
Пример #3
0
 CanSerializeClrProperty(
     Object serializableObject,
     TypePropertyCache property
     )
 {
     return(CanSerializeClrProperty(serializableObject, property, _reachSerializationServices));
 }
Пример #4
0
        GetClrSerializableProperties(
            Object serializableObject
            )
        {
            TypeCacheItem item = GetTypeCacheItem(serializableObject);

            TypePropertyCache[] clrProperties = item.GetClrSerializableProperties(this);
            int[] serializableIndeces         = new int[clrProperties.Length];
            int   serializablePropertiesIndex = 0;

            //
            // Not everything we get can be serializable, so we have to figure out which
            // ones are but checking if we can also serialize the value of the property
            // values would be added to the cache as well.
            //
            for (int indexInClrProperties = 0;
                 indexInClrProperties < clrProperties.Length;
                 indexInClrProperties++)
            {
                if (CanSerializeValue(serializableObject,
                                      clrProperties[indexInClrProperties]) &&
                    _serializationManager.CanSerializeClrProperty(serializableObject,
                                                                  clrProperties[indexInClrProperties]))
                {
                    serializableIndeces[serializablePropertiesIndex++] = indexInClrProperties;
                }
            }

            TypePropertyCache[] clrSerializableProperties = new TypePropertyCache[serializablePropertiesIndex];

            for (int indexInClrSerializableProperties = 0;
                 indexInClrSerializableProperties < serializablePropertiesIndex;
                 indexInClrSerializableProperties++)
            {
                TypePropertyCache propertyCache             = clrProperties[serializableIndeces[indexInClrSerializableProperties]];
                TypePropertyCache serializablePropertyCache = new TypePropertyCache(propertyCache.PropertyInfo,
                                                                                    propertyCache.Visibility,
                                                                                    propertyCache.SerializerTypeForProperty,
                                                                                    propertyCache.TypeConverterForProperty,
                                                                                    propertyCache.DefaultValueAttr,
                                                                                    propertyCache.DesignerSerializationOptionsAttr);

                serializablePropertyCache.PropertyValue = propertyCache.PropertyValue;

                clrSerializableProperties[indexInClrSerializableProperties] = serializablePropertyCache;
            }

            //
            // Clear all set values
            //
            for (int indexInClrProperties = 0;
                 indexInClrProperties < clrProperties.Length;
                 indexInClrProperties++)
            {
                clrProperties[indexInClrProperties].PropertyValue = null;
            }

            return(clrSerializableProperties);
        }
Пример #5
0
        CanSerializeValue(
            object serializableObject,
            TypePropertyCache propertyCache
            )
        {
            bool canSerializeValue = false;
            //
            // For readonly properties check for DesignerSerializationVisibility.Content
            //
            bool isReadOnly = !propertyCache.PropertyInfo.CanWrite;


            if ((isReadOnly &&
                 propertyCache.Visibility == DesignerSerializationVisibility.Content) ||
                propertyCache.DefaultValueAttr == null)
            {
                //
                // Populate the property value in this data structure
                //
                propertyCache.PropertyValue = propertyCache.PropertyInfo.GetValue(serializableObject, null);
                canSerializeValue           = true;
            }
            else
            {
                //
                // Populate the property value in this data structure
                // as it is required to evaluate the default value
                //
                propertyCache.PropertyValue = propertyCache.PropertyInfo.GetValue(serializableObject, null);
                // For Clr properties with a DefaultValueAttribute
                // check if the current value equals the default
                canSerializeValue = !object.Equals(propertyCache.DefaultValueAttr.Value,
                                                   propertyCache.PropertyValue);

                if (!canSerializeValue)
                {
                    propertyCache.PropertyValue = null;
                }
            }

            return(canSerializeValue);
        }
Пример #6
0
        InitializeSerializableClrProperties(
            )
        {
            TypePropertyCache[] clrProperties = _serializationManager.CacheManager.GetClrSerializableProperties(_target);

            if (clrProperties != null)
            {
                for (int indexInClrSerializableProperties = 0;
                     indexInClrSerializableProperties < clrProperties.Length;
                     indexInClrSerializableProperties++)
                {
                    TypePropertyCache propertyCache = clrProperties[indexInClrSerializableProperties];

                    //
                    // Create SerializablePropertyContext out of the cache retrieved
                    //
                    SerializablePropertyContext propertyContext = new SerializablePropertyContext(_target,
                                                                                                  propertyCache);

                    propertyContext.Name = propertyContext.TypePropertyCache.PropertyInfo.Name;

                    //
                    // We have to differentiate between simple properties and complex properties.
                    // o Simple properties would be considered as attributes within the markup and
                    //   would not require new writers
                    // o Complex properties would be considered elements within the markup and might
                    //   require a new writer
                    //
                    if (propertyContext.IsComplexProperty(_serializationManager))
                    {
                        propertyContext.IsComplex = true;
                        _complexPropertyCollection.Enqueue(propertyContext);
                    }
                    else
                    {
                        propertyContext.IsComplex = false;
                        _simplePropertyCollection.Enqueue(propertyContext);
                    }
                }
            }
        }
Пример #7
0
        SerializablePropertyContext(
            object target,
            TypePropertyCache propertyCache) :
            base()
        {
            //
            // Validate Input Arguments
            //
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            if (propertyCache == null)
            {
                throw new ArgumentNullException("propertyCache");
            }

            _targetObject   = target;
            _propertyInfo   = propertyCache;
            this._isComplex = false;
        }
Пример #8
0
        GetClrSerializableProperties(
            SerializersCacheManager serializersCacheManager
            )
        {
            if (clrSerializableProperties == null)
            {
                PropertyInfo[] properties = type.GetProperties();

                //
                // Separate out the serializable Clr properties
                //
                int   IndexOfSerializableProperties = 0;
                int[] propertiesIndex = new int[properties.Length];
                TypePropertyCache[] cachedProperties = new TypePropertyCache[properties.Length];


                for (int indexInProperties = 0;
                     indexInProperties < properties.Length;
                     indexInProperties++)
                {
                    PropertyInfo propertyInfo = properties[indexInProperties];

                    DesignerSerializationVisibility visibility      = DesignerSerializationVisibility.Visible;
                    Type                  serializerTypeForProperty = null;
                    TypeConverter         typeConverterForProperty  = null;
                    DefaultValueAttribute defaultValueAttr          = null;
                    DesignerSerializationOptionsAttribute
                        designerSerializationFlagsAttr = null;

                    if (CanSerializeProperty(propertyInfo,
                                             serializersCacheManager,
                                             out visibility,
                                             out serializerTypeForProperty,
                                             out typeConverterForProperty,
                                             out defaultValueAttr,
                                             out designerSerializationFlagsAttr) == true)
                    {
                        //
                        // Figure out the Serializer or TypeConverter associated with the
                        // type of that property. This would potentially be cached in 2
                        // different places
                        // 1. The Type Cache
                        // 2. The TypePropertyCache.
                        //
                        TypeCacheItem typeCacheItem = serializersCacheManager.GetTypeCacheItem(propertyInfo.PropertyType);

                        serializerTypeForProperty = typeCacheItem.SerializerType;
                        typeConverterForProperty  = typeCacheItem.TypeConverter;

                        //
                        // We create a cache of this property and all the information we
                        // deduced about it
                        //
                        TypePropertyCache propertyCache = new TypePropertyCache(propertyInfo,
                                                                                visibility,
                                                                                serializerTypeForProperty,
                                                                                typeConverterForProperty,
                                                                                defaultValueAttr,
                                                                                designerSerializationFlagsAttr);

                        propertiesIndex[IndexOfSerializableProperties]    = indexInProperties;
                        cachedProperties[IndexOfSerializableProperties++] = propertyCache;
                    }
                }

                clrSerializableProperties = new TypePropertyCache[IndexOfSerializableProperties];

                for (int indexInClrProperties = 0;
                     indexInClrProperties < IndexOfSerializableProperties;
                     indexInClrProperties++)
                {
                    clrSerializableProperties[indexInClrProperties] = cachedProperties[indexInClrProperties];
                }
            }

            return(clrSerializableProperties);
        }