public void SetupRegistry() { ABSRegistry.LoadedSegments.Clear(); var newSegment = new RegSegment(); StringItem = new RegString() { Data = "InRegistry" }; IntegerItem = new RegInteger() { Data = 12 }; DecimalItem = new RegDecimal() { Data = 12.3f }; BooleanGroupItem = new RegBooleanGroup(); BooleanGroupItem.SetItem(5, true); BooleanGroupItem.SetItem(6, false); ABSRegistry.LoadedSegments.Add("abc", newSegment); newSegment.AddItem("stringItm", StringItem); newSegment.AddItem("integerItm", IntegerItem); newSegment.AddItem("decimalItm", DecimalItem); newSegment.AddItem("booleanGroupItm", BooleanGroupItem); }
static unsafe bool GetSegmentByName(string segmentName, bool isAlias, out RegSegment segment) { if (isAlias) { return(SegmentAliases.TryGetValue(segmentName, out segment)); } else { return(LoadedSegments.TryGetValue(segmentName, out segment)); } }
public unsafe void GetSegment_Alias_Valid() { var newSegment = new RegSegment(); ABSRegistry.SegmentAliases.Add("abc", newSegment); char *ch = stackalloc char[4]; Assert.IsTrue(ABSRegistry.GetSegment("$abc:", ch, out int pos, out RegSegment segment)); Assert.AreEqual(newSegment, segment); Assert.AreEqual(5, pos); }
internal static unsafe bool GetSegment(string path, char *buffer, out int pos, out RegSegment segment) { pos = 0; segment = null; if (path.Length == 0) { return(false); } bool isAlias = false; if (path[0] == '$') { pos++; isAlias = true; } // Get the section's name. char *currentBuffer = buffer; for (; pos < path.Length; pos++) { if (path[pos] == ':') { pos++; return(GetSegmentByName(new string(buffer, 0, (int)(currentBuffer - buffer)), isAlias, out segment)); } else { *currentBuffer++ = path[pos]; } } // If we got to the end of the string without finding a ":". return(false); }