Exemplo n.º 1
0
        /// <summary>
        /// Construct the field data from a FieldInfo object. Internal Constructor means that noone outside this library
        /// should be creating objects of this class.
        /// </summary>
        /// <param name="_fieldInfo">The FieldInfo object</param>
        /// <param name="_typeData">The TypeData object that is constructing this CFieldData</param>
        internal CFieldData(FieldInfo _fieldInfo, CTypeData _typeData)
        {
            Field       = _fieldInfo;
            m_typeData  = _typeData;
            m_fieldName = null;

            var attributeList = _fieldInfo.GetCustomAttributes(false);

            foreach (var attr in attributeList)
            {
                if (attr is ADoNotSerialize)
                {
                    DoNotSerialize = true;
                }
                else if (attr is AExplicitlySerialize)
                {
                    ExplicitlySerialize = true;
                }
                else if (attr is ASerializedName renamer)
                {
                    m_fieldName = renamer.NewName; // This actually overrides an AFieldRenamer on the Parent Type
                }
            }

            if (m_fieldName == null && !m_typeData.m_dynamicFieldRenamer)
            {
                // If we are NOT changing the renaming algorithm at runtime, then-
                m_fieldName = m_typeData.RenameField(Field.Name, Field);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// The External interface into this class- Find a CTypeData object for a given Type. Uses the cache to
        /// limit the amount of processing performed.
        /// </summary>
        /// <param name="_type">The Type to search for</param>
        /// <returns>A CTypeData object containing interesting features of the Type</returns>
        internal static CTypeData GetTypeData(Type _type)
        {
            lock (sm_typeTable)
            {
                if (sm_typeTable.TryGetValue(_type, out var typeData))
                {
                    return(typeData);
                }

                typeData = new CTypeData(_type);
                sm_typeTable.Add(_type, typeData);
                return(typeData);
            }
        }