Пример #1
0
        /// <summary>
        /// Must construct one of these with a Type. Private constructor means that only this class may create an
        /// object of this type.
        /// </summary>
        /// <param name="_type">The Type to generate data for</param>
        private CTypeData(Type _type)
        {
            Type = _type;

            GenerateAttributeData();
            GenerateFieldData();
            GenerateBaseClassData();
            GetImplicitSurrogate();
            GetPrivateDefaultConstructor();

            if (!m_dynamicFieldRenamer) // If there is no dynamic field renamer, then...
            {
                m_renamer = null;       //  make sure that the object created to rename fields is released for GC
            }
        }
Пример #2
0
        /// <summary>
        /// For the m_type, analyse the attributes on the Type and store the useful ones in this object
        /// </summary>
        private void GenerateAttributeData()
        {
            var attrList = Type.GetCustomAttributes(false);

            foreach (var a in attrList)
            {
                if (a is AExplicitlySerialize)
                {
                    m_onlySerializeExplicitFields = true;
                }
                else if (a is ADoNotSerialize)
                {
                    m_doNotSerialize = true;
                }
                else if (a is AUseFieldRenamer renamerAttr)
                {
                    m_renamer             = (IFieldRenamer)Activator.CreateInstance(renamerAttr.RenamerType);
                    m_dynamicFieldRenamer = renamerAttr.DynamicRenaming;
                }
            }
        }