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

AddRecord() public method

public AddRecord ( BaseRecord br ) : void
br BaseRecord
return void
        public override void AddRecord(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.Add(sr);
        }

Usage Example

示例#1
0
        public static bool CompileResultScript(SubRecord sr, out Record r2, out string msg)
        {
            msg = null;
            r2 = null;
            r = new Record();
            string script = sr.GetStrData();
            locals.Clear();
            localList.Clear();
            edidRefs.Clear();
            refcount = 0;
            errors.Clear();

            ts = new TokenStream(script, errors);
            if (errors.Count > 0)
            {
                return OutputErrors(out msg);
            }

            schr = new SubRecord();
            schr.Name = "SCHR";
            r.AddRecord(schr);
            scda = new SubRecord();
            scda.Name = "SCDA";
            r.AddRecord(scda);
            sr = (SubRecord)sr.Clone();
            r.AddRecord(sr);

            bw = new BinaryWriter(new MemoryStream());

            while (ts.PeekNextStatement().Length > 0)
            {
                try
                {
                    HandleResultsBlock();
                }
                catch (Exception ex)
                {
                    return ReturnError(ex.Message, out msg);
                }
            }

            if (errors.Count > 0)
            {
                return OutputErrors(out msg);
            }

            var header = new byte[20];
            TypeConverter.si2h(refcount, header, 4);
            TypeConverter.i2h((uint)bw.BaseStream.Length, header, 8);
            TypeConverter.si2h(localList.Count, header, 12);
            TypeConverter.si2h(0x10000, header, 16);
            schr.SetData(header);
            byte[] compileddata = ((MemoryStream)bw.BaseStream).GetBuffer();
            if (compileddata.Length != bw.BaseStream.Length)
            {
                Array.Resize(ref compileddata, (int)bw.BaseStream.Length);
            }

            scda.SetData(compileddata);
            bw.Close();
            r2 = r;
            return true;
        }
All Usage Examples Of TESVSnip.Domain.Model.Record::AddRecord