예제 #1
0
        public IlInstanceHolderPool(Type itemType, int count, string typeName = null)
        {
            ItemType      = itemType;
            CapacityCount = count;
            if (typeName == null)
            {
                typeName = "DynamicType" + _autoincrement++;
            }
            var typeBuilder = ModuleBuilder.DefineType(typeName,
                                                       TypeAttributes.Sealed | TypeAttributes.Public | TypeAttributes.Class);

            _fieldInfos = new IlInstanceHolderPoolItem[count];
            var names = new string[count];

            for (var n = 0; n < count; n++)
            {
                names[n] = $"V{n}";
                typeBuilder.DefineField(names[n], itemType, FieldAttributes.Public | FieldAttributes.Static);
            }

            var holderType = typeBuilder.CreateType();

            var fields = holderType.GetFields();

            for (var n = 0; n < count; n++)
            {
                _fieldInfos[n] = new IlInstanceHolderPoolItem(this, n, fields[n]);
                _freeItems.AddLast(n);
            }
        }
예제 #2
0
 internal void Free(IlInstanceHolderPoolItem item) => _freeItems.AddLast(item.Index);
 public IlInstanceHolderPoolItem(IlInstanceHolderPoolItem item) => _item = item;