Beispiel #1
0
        /// <summary>
        /// Resolves composite data into CLR object
        /// </summary>
        public virtual object CompositeToNative(CompositeData data)
        {
            if (data==null) return null;
            if (data.ExistingReference)
               return CompositeToNative(data.Referenced);

            var result = data.__CLRObject;

            if (result==null)
            {
                //1. Construct
                result = ConstructObject(data);
                data.__CLRObject = result;

                //2. Fill with data
                if (data is CompositeCustomData)
                    DeserializeObjectFromCompositeCustomData(result, (CompositeCustomData)data);
                else if (data is CompositeArrayData)
                    DeserializeArray((Array)result, (CompositeArrayData)data);
                else
                    DeserializeObjectFromCompositeReflectedData(result, (CompositeReflectedData)data);
            }

            return result;
        }
Beispiel #2
0
        /// <summary>
        /// Constructs object out of CompositeData. This implementation calls ResolveType then tries to invoke attribute constructor first
        /// then create instance using default ctor
        /// </summary>
        public virtual object ConstructObject(CompositeData data)
        {
            object result = null;

            var clrType =  ResolveType( data.Type );
          
            //1 check for attribute ---------------
            var attr = (PortableObjectDocumentDeserializationTransform)clrType
                                                                       .GetCustomAttributes(typeof(PortableObjectDocumentDeserializationTransform), false)
                                                                       .FirstOrDefault();

            if (attr!=null)
                result = attr.ConstructObjectInstance(data);
            
            if (result==null)
            {
                //2 call the dfault .ctor
                if (data is CompositeArrayData)
                    result = MakeNewArrayInstance( (CompositeArrayData)data );
                else
                    result = MakeNewObjectInstanceUsingDefaultCtor( clrType );
            }
            
            //3 call OnDeserializing
            if (result!=null)
            {
                List<MethodInfo> methodsOnDeserializing = SerializationUtils.FindSerializationAttributedMethods( result.GetType(), typeof(OnDeserializingAttribute));
                if (methodsOnDeserializing!=null)
                    SerializationUtils.InvokeSerializationAttributedMethods(methodsOnDeserializing, result, data.Document.m_StreamingContext);
            }
            
            return result; 
        }  
Beispiel #3
0
        /// <summary>
        /// Constructs object out of CompositeData. This implementation calls ResolveType then tries to invoke attribute constructor first
        /// then create instance using default ctor
        /// </summary>
        public virtual object ConstructObject(CompositeData data)
        {
            object result = null;

            var clrType = ResolveType(data.Type);

            //1 check for attribute ---------------
            var attr = (PortableObjectDocumentDeserializationTransform)clrType
                       .GetCustomAttributes(typeof(PortableObjectDocumentDeserializationTransform), false)
                       .FirstOrDefault();

            if (attr != null)
            {
                result = attr.ConstructObjectInstance(data);
            }

            if (result == null)
            {
                //2 call the dfault .ctor
                if (data is CompositeArrayData)
                {
                    result = MakeNewArrayInstance((CompositeArrayData)data);
                }
                else
                {
                    result = MakeNewObjectInstanceUsingDefaultCtor(clrType);
                }
            }

            //3 call OnDeserializing
            if (result != null)
            {
                List <MethodInfo> methodsOnDeserializing = SerializationUtils.FindSerializationAttributedMethods(result.GetType(), typeof(OnDeserializingAttribute));
                if (methodsOnDeserializing != null)
                {
                    SerializationUtils.InvokeSerializationAttributedMethods(methodsOnDeserializing, result, data.Document.m_StreamingContext);
                }
            }

            return(result);
        }
Beispiel #4
0
        /// <summary>
        /// Resolves composite data into CLR object
        /// </summary>
        public virtual object CompositeToNative(CompositeData data)
        {
            if (data == null)
            {
                return(null);
            }
            if (data.ExistingReference)
            {
                return(CompositeToNative(data.Referenced));
            }

            var result = data.__CLRObject;

            if (result == null)
            {
                //1. Construct
                result           = ConstructObject(data);
                data.__CLRObject = result;

                //2. Fill with data
                if (data is CompositeCustomData)
                {
                    DeserializeObjectFromCompositeCustomData(result, (CompositeCustomData)data);
                }
                else if (data is CompositeArrayData)
                {
                    DeserializeArray((Array)result, (CompositeArrayData)data);
                }
                else
                {
                    DeserializeObjectFromCompositeReflectedData(result, (CompositeReflectedData)data);
                }
            }

            return(result);
        }
 /// <summary>
 /// Override to construct new object instance from CompositeData.
 /// Return null to let the default implementatiom/ctor be invoked by the framework
 /// </summary>
 public abstract object ConstructObjectInstance(CompositeData data);
Beispiel #6
0
 /// <summary>
 /// Override to construct new object instance from CompositeData.
 /// Return null to let the default implementatiom/ctor be invoked by the framework
 /// </summary>
 public abstract object ConstructObjectInstance(CompositeData data);