Пример #1
0
        public static void CheckTypeCache()
        {
            //SL.Log("Getting implementations of SLPackCategory in all assemblies...");
            var allTypes = At.GetImplementationsOf(typeof(SLPackCategory));

            if (allTypes.Count == s_lastTypeCount)
            {
                return;
            }

            s_lastTypeCount = allTypes.Count;

            var list = new List <SLPackCategory>();

            //var lateList = new List<SLPackCategory>();

            foreach (var type in allTypes)
            {
                try
                {
                    SLPackCategory ctg;
                    if (s_slPackCategories != null && s_slPackCategories.ContainsKey(type))
                    {
                        ctg = s_slPackCategories[type];
                    }
                    else
                    {
                        ctg = (SLPackCategory)At.TryCreateDefault(type);
                    }

                    if (ctg != null)
                    {
                        list.Add(ctg);
                        //if (ctg.HasLateContent)
                        //    lateList.Add(ctg);
                    }
                    else
                    {
                        SL.Log("SLPack categories internal: could not create instance of type '" + type.FullName + "'");
                    }
                }
                catch (Exception ex)
                {
                    SL.LogWarning("Exception checking SLPackCategory '" + type.FullName + "'");
                    SL.LogInnerException(ex);
                }
            }

            s_slPackCategories = new Dictionary <Type, SLPackCategory>();
            foreach (var instance in list.OrderBy(it => it.LoadOrder))
            {
                s_slPackCategories.Add(instance.GetType(), instance);
            }

            //s_slPackLateCategories = new Dictionary<Type, SLPackCategory>();
            //if (lateList.Any())
            //    foreach (var instance in lateList.OrderBy(it => it.LoadOrder))
            //        s_slPackLateCategories.Add(instance.GetType(), instance);
        }
        internal void AddEntry()
        {
            if (m_typeToAdd == null)
            {
                SL.LogWarning("No type selected!");
                return;
            }

            if (RefIList == null)
            {
                SL.LogWarning("Cannot add to " + this.Value.GetType());
                return;
            }

            object newValue = At.TryCreateDefault(m_typeToAdd);

            if (RefIList.IsFixedSize)
            {
                if (this.FallbackType.IsArray)
                {
                    var array = Value as Array;
                    Resize(ref array, RefIList.Count + 1, -1);
                    Value = array;

                    RefIList = Value as IList;
                    RefIList[RefIList.Count - 1] = newValue;
                }
                else
                {
                    SL.LogWarning("Cannot add to this type: " + FallbackType.GetType());
                    return;
                }
            }
            else
            {
                RefIList.Add(newValue);
            }

            ApplyFromRefIList();
        }
        public void GetCacheEntries()
        {
            if (m_entries.Any())
            {
                // maybe improve this, probably could be more efficient i guess

                foreach (var entry in m_entries)
                {
                    entry.Destroy();
                }

                m_entries.Clear();
            }

            if (RefIList != null)
            {
                int index = 0;
                foreach (var entry in RefIList)
                {
                    object entryToUse = entry;
                    if (entryToUse == null)
                    {
                        entryToUse = At.TryCreateDefault(this.m_baseEntryType);
                    }

                    var cache = new CacheEnumerated(index, this, RefIList, this.m_listContent);
                    cache.CreateIValue(entryToUse, m_baseEntryType);
                    m_entries.Add(cache);

                    cache.Disable();

                    index++;
                }
            }

            RefreshDisplay();
        }