TESVSnip.Domain.Model.Record.InsertRecord C# (CSharp) Method

InsertRecord() public method

public InsertRecord ( int idx, BaseRecord br ) : void
idx int
br BaseRecord
return void
        public override void InsertRecord(int idx, BaseRecord br)
        {
            var sr = br as SubRecord;
            if (sr == null)
            {
                throw new TESParserException("Record to add was not of the correct type." + Environment.NewLine +
                                             "Records can only hold Subrecords.");
            }

            sr.Parent = this;
            this.SubRecords.Insert(idx, sr);
        }

Usage Example

示例#1
0
        public bool AddMaster(string masterName)
        {
            Record brcTES4 = this.Records.OfType <Record>().FirstOrDefault(x => x.Name == "TES4");

            if (brcTES4 == null)
            {
                throw new ApplicationException("Plugin lacks a valid TES4 record. Cannot continue.");
            }

            // find existing if already present
            foreach (var mast in brcTES4.SubRecords.Where(x => x.Name == "MAST"))
            {
                var path = mast.GetStrData();
                if (string.Compare(path, masterName, true) == 0)
                {
                    return(false);
                }
            }

            int idx = brcTES4.SubRecords.IndexOf(brcTES4.SubRecords.FirstOrDefault(x => x.Name == "INTV"));

            if (idx < 0)
            {
                idx = brcTES4.SubRecords.Count;
            }

            var sbrMaster = new SubRecord();

            sbrMaster      = new SubRecord();
            sbrMaster.Name = "DATA";
            sbrMaster.SetData(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 });
            brcTES4.InsertRecord(idx, sbrMaster);

            sbrMaster      = new SubRecord();
            sbrMaster.Name = "MAST";
            int intCount = Encoding.Instance.GetByteCount(masterName);
            var bteData  = new byte[intCount + 1];

            Array.Copy(Encoding.Instance.GetBytes(masterName), bteData, intCount);
            sbrMaster.SetData(bteData);
            brcTES4.InsertRecord(idx, sbrMaster);

            // Fix Masters
            // Update IDs for current record to be +1
            return(true);
        }
All Usage Examples Of TESVSnip.Domain.Model.Record::InsertRecord