示例#1
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>(Collections.ReferenceEqualityComparer <object> .Default);
                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());
            }
        }
示例#2
0
 internal CompositeArrayData(PortableObjectDocument document, Array data, int metaTypeIndex = -1)
     : base(document, data, metaTypeIndex)
 {
     if (!ExistingReference)
     {
         serializeArray(data);
     }
 }
示例#3
0
 internal CompositeCustomData(PortableObjectDocument document, object data, int metaTypeIndex = -1)
     : base(document, data, metaTypeIndex)
 {
     if (!ExistingReference)
     {
         serializeFromTransform(data);
     }
 }
示例#4
0
 internal MetaType(PortableObjectDocument document, Type type)
 {
     __CLRType               = type;
     m_Document              = document;
     m_Name                  = type.Name;
     m_Namespace             = type.Namespace;
     m_AssemblyQualifiedName = type.AssemblyQualifiedName;
 }
示例#5
0
 internal CompositeReflectedData(PortableObjectDocument document, object data, int metaTypeIndex = -1)
     : base(document, data, metaTypeIndex)
 {
     if (!ExistingReference)
     {
         serializeFields(data);
     }
 }
示例#6
0
        /// <summary>
        /// Obtains new or existing instance of MetaType that represents a Type in the document instance
        /// </summary>
        internal static int GetExistingOrNewMetaTypeIndex(PortableObjectDocument document, Type type)
        {
            var dict = document.m_TypesDict;

            if (dict == null)
            {
                dict = new Dictionary <Type, int>();
                document.m_TypesDict = dict;
            }

            int result;

            if (dict.TryGetValue(type, out result))
            {
                return(result);
            }

            MetaType mtp;

            if (type.IsPrimitive || type == typeof(string) || type == typeof(DateTime) || type == typeof(TimeSpan))
            {
                mtp = new MetaPrimitiveType(document, type);
            }
            else
            {
                mtp = new MetaComplexType(document, type);
            }

            //1. add to dict so no infinite loop happens during recursive call to this func
            result = document.m_Types.Count;
            document.m_Types.Add(mtp);
            dict.Add(type, result);

            //2. Build the type inner structures
            mtp.Build();

            return(result);
        }
示例#7
0
 /// <summary>
 /// Override to provide custome seriallization of type marked with this attribute into custom name/value bag
 /// </summary>
 /// <param name="document">Document context that this operation executes under</param>
 /// <param name="source">Source native data to serialize / populate data from</param>
 /// <param name="data">Name/value bag to write data into</param>
 public abstract void SerializeCustomObjectData(PortableObjectDocument document, object source, Dictionary <string, CustomTypedEntry> data);
示例#8
0
 internal MetaComplexType(PortableObjectDocument document, Type type) : base(document, type)
 {
 }
示例#9
0
 internal MetaPrimitiveType(PortableObjectDocument document, Type type) : base(document, type)
 {
 }