Example #1
0
        protected Section(SectionMode mode, T data = default)
        {
            var type = GetType();

            SectionInfo = SectionRegistry.GetOrRegisterSectionInfo(type);

            Mode  = mode;
            mData = data;

            if (Mode == SectionMode.Write && mData == null)
            {
                throw new ArgumentNullException("Data object must be provided in write mode", nameof(data));
            }
        }
Example #2
0
        internal SubSectionInfo(PropertyInfo propertyInfo)
        {
            var subSectionAttribute = propertyInfo.GetCustomAttribute <SubSectionAttribute>();

            Type genericType = null;

            for (var type = propertyInfo.PropertyType; type != null; type = type.BaseType)
            {
                if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List <>))
                {
                    genericType = type.GetGenericArguments()[0];
                    break;
                }
            }

            if (genericType != null)
            {
                IsListType    = true;
                IsSectionType = typeof(ISection).IsAssignableFrom(genericType);

                if (IsSectionType)
                {
                    SectionInfo = SectionRegistry.GetOrRegisterSectionInfo(genericType);
                }
                else
                {
                    SectionInfo = SectionRegistry.GetOrRegisterSectionInfo(subSectionAttribute.SectionType);
                }
            }
            else
            {
                IsSectionType = typeof(ISection).IsAssignableFrom(propertyInfo.PropertyType);

                if (IsSectionType)
                {
                    SectionInfo = SectionRegistry.GetOrRegisterSectionInfo(propertyInfo.PropertyType);
                }
                else
                {
                    SectionInfo = SectionRegistry.GetOrRegisterSectionInfo(subSectionAttribute.SectionType);
                }
            }

            PropertyInfo = propertyInfo;
            Priority     = subSectionAttribute.Priority;
        }