示例#1
0
        protected override void Build()
        {
            var type = this.__CLRType;

            m_BuildInformation = new BuildInformation(type.Assembly, throwError: false);
            m_IsValueType      = type.IsValueType;
            m_IsVisible        = type.IsVisible;
            m_IsArray          = type.IsArray;
            m_IsAbstract       = type.IsAbstract;

            if (m_IsArray)
            {
                m_ArrayRank             = type.GetArrayRank();
                m_ArrayElementTypeIndex = MetaType.GetExistingOrNewMetaTypeIndex(m_Document, type.GetElementType());
            }

            m_Fields = new List <MetaField>();

            var fields = SerializationUtils.GetSerializableFields(type);

            foreach (var fld in fields)
            {
                var mf = new MetaField(this, fld);
                m_Fields.Add(mf);
                mf.m_Index = m_Fields.Count - 1;
            }

            m_MethodsOnSerializing = SerializationUtils.FindSerializationAttributedMethods(type, typeof(OnSerializingAttribute));
            m_MethodsOnSerialized  = SerializationUtils.FindSerializationAttributedMethods(type, typeof(OnSerializedAttribute));
        }
示例#2
0
        internal CompositeData(PortableObjectDocument document, object data, int metaTypeIndex = -1)
        {
            if (data == null)
            {
                throw new InvalidOperationException("No need to allocate CompositeData from NULL data. Write null directly"); //todo Refactor execption type,text etc...
            }
            m_Document = document;

            var tp = data.GetType();

            if (tp.IsPrimitive)
            {
                throw new InvalidOperationException("Can not allocate CompositeData from primitive type: " + tp.FullName); //todo Refactor execption type,text etc...
            }
            var dict = document.m_CompositeDataDict;

            if (dict == null)
            {
                dict = new Dictionary <object, int>(ReferenceEqualityComparer <object> .Instance);
                document.m_CompositeDataDict = dict;
            }

            int existingIndex;

            if (dict.TryGetValue(data, out existingIndex))
            {
                m_ExistingReferenceIndex = existingIndex;
            }
            else
            {
                document.m_CompositeData.Add(this);
                dict.Add(data, document.m_CompositeData.Count - 1);
                m_MetaTypeIndex = metaTypeIndex >= 0 ? metaTypeIndex :  MetaType.GetExistingOrNewMetaTypeIndex(document, data.GetType());
            }
        }
示例#3
0
 internal MetaField(MetaComplexType declaringType, FieldInfo fieldInfo)
 {
     m_DeclaringType      = declaringType;
     m_FieldInfo          = fieldInfo;
     m_FieldName          = fieldInfo.Name;
     m_FieldMetaTypeIndex = MetaType.GetExistingOrNewMetaTypeIndex(declaringType.Document, fieldInfo.FieldType);
 }
示例#4
0
        private void serializeFromISerializable(ISerializable data)
        {
            m_CustomData = new Dictionary <string, CustomTypedEntry>();

            var info = new SerializationInfo(data.GetType(), new FormatterConverter());
            StreamingContext streamingContext = new StreamingContext(StreamingContextStates.Persistence);

            data.GetObjectData(info, streamingContext);

            var senum = info.GetEnumerator();

            while (senum.MoveNext())
            {
                var value = new CustomTypedEntry();
                value.TypeIndex          = MetaType.GetExistingOrNewMetaTypeIndex(m_Document, senum.ObjectType);
                value.Data               = m_Document.NativeDataToPortableData(senum.Value);
                m_CustomData[senum.Name] = value;
            }
        }
示例#5
0
        //20140717 DKh commented. Why was this .ctor EVER needed?
        //it started failing after deserializer started to call not only pub ctor but also private
        //as needed to init field assignments
        ////////internal PortableObjectDocument()
        ////////{
        ////////    MetaType.GetExistingOrNewMetaTypeIndex(this, typeof(object));
        ////////}


        /// <summary>
        /// Creates a new instance of object document from the graph of arbitrary CLR objects serializing them into well-known POD object types
        /// </summary>
        public PortableObjectDocument(object graph, DateTime?creationDate = null, string notes = null)
        {
            try
            {
                m_BuildInfo        = BuildInformation.ForFramework;
                m_CreationDate     = creationDate ?? App.LocalizedTime;
                m_Notes            = notes;
                m_Types            = new List <MetaType>();
                m_CompositeData    = new List <CompositeData>();
                m_StreamingContext = new StreamingContext();

                MetaType.GetExistingOrNewMetaTypeIndex(this, typeof(object));

                if (graph != null)
                {
                    m_Root = nativeDataToPortableData(graph, out m_RootMetaTypeIndex);
                }
            }
            finally
            {
                purgeCaches();    //drop all temp objects
            }
        }
示例#6
0
 /// <summary>
 /// Obtains new or existing MetaType instance that represents a Type in this document instance.
 /// If this document instance already has this type registered, then existing MetaType instance is returned, otherwise
 ///  the new MetaType instance that represents the supplied CLR Type is created and registered under the document-unique index
 /// </summary>
 public MetaType GetExistingOrNewMetaType(Type type)
 {
     return(m_Types[MetaType.GetExistingOrNewMetaTypeIndex(this, type)]);
 }
示例#7
0
 /// <summary>
 /// Obtains new or existing index of MetaType that represents a Type in this document instance.
 /// If this document instance already has this type registered, then existing index is returned, otherwise
 ///  the new MetaType instance that represents the supplied CLR Type is created and registered under the document-unique index
 /// </summary>
 public int GetExistingOrNewMetaTypeIndex(Type type)
 {
     return(MetaType.GetExistingOrNewMetaTypeIndex(this, type));
 }