예제 #1
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);
 }
예제 #2
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);
        }