public V Get(K key) { lock (this) { MapValue <V> value = null; dictionary.TryGetValue(key, out value); if (value == null) { return(default(V)); } else { return(value.Value); } } }
public V Put(K key, V value, long timeoutDurationInMilleseconds) { lock (this) { MapValue <V> mapValue = new MapValue <V>(value, DateTime.Now.AddMilliseconds(timeoutDurationInMilleseconds)); MapValue <V> oldValue = (dictionary[key] = mapValue); if (oldValue == null) { return(default(V)); } else { return(oldValue.Value); } } }
public void Translator_BasicMap_FromModel_ToStruct() { // Parse the basic map Node node = TaronParser.Parse(TestUtils.ReusableMapTest); Assert.IsNotNull(node); MapValue mapValue = node.As <MapValue>(); Assert.IsNotNull(mapValue); // Translate to a strongly-typed struct var t = new TaronTranslator(TaronTranslatorOptions.Default); var strct = (TestUtils.ReusableMapStruct)t.Deserialise(typeof(TestUtils.ReusableMapStruct), mapValue); strct.Test(); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: static java.time.Duration parseTransactionTimeout(org.neo4j.values.virtual.MapValue meta) throws org.neo4j.bolt.messaging.BoltIOException internal static Duration ParseTransactionTimeout(MapValue meta) { AnyValue anyValue = meta.Get(TX_TIMEOUT_KEY); if (anyValue == Values.NO_VALUE) { return(null); } else if (anyValue is LongValue) { return(Duration.ofMillis((( LongValue )anyValue).longValue())); } else { throw new BoltIOException(Org.Neo4j.Kernel.Api.Exceptions.Status_Request.Invalid, "Expecting transaction timeout value to be a Long value, but got: " + anyValue); } }
public override MapValue Properties() { MapValue m = _properties; if (m == null) { lock (this) { m = _properties; if (m == null) { m = _properties = ValueUtils.AsMapValue(_relationship.AllProperties); } } } return(m); }
private void AddMethodIntern(int inlet, Symbol sel, Kind k, Delegate d) { // add to map if (m_map.Length <= inlet) { ResizeArray(ref m_map, inlet + 1); } Hashtable h = m_map[inlet]; if (h == null) { m_map[inlet] = h = new Hashtable(); } h[sel] = new MapValue(k, d); methodflags |= MethodFlags.f_anything; }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleMapsWithLists() public virtual void ShouldHandleMapsWithLists() { // Given MapValue map = map(new string[] { "foo", "bar" }, new AnyValue[] { longValue(42L), list(stringValue("baz")) }); // When map.WriteTo(_converter); // Then //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.Map<?,?> value = (java.util.Map<?,?>) converter.value(); IDictionary <object, ?> value = (IDictionary <object, ?>)_converter.value(); assertThat(value["foo"], equalTo(42L)); assertThat(value["bar"], equalTo(singletonList("baz"))); assertThat(value.Count, equalTo(2)); }
private MapValue RandomValue() { int w = Random.Range(40, 52); int h = Random.Range(40, 52); w = w % 2 == 0 ? w + 1 : w; h = h % 2 == 0 ? h + 1 : h; int min = Random.Range(5, 10); int max = Random.Range(9, 12); min = min % 2 == 0 ? min + 1 : min; max = max % 2 == 0 ? max + 1 : max; MapValue value = new MapValue(w, h, min, max); return(value); }
public override void WriteNode(long nodeId, TextArray labels, MapValue properties) { Append(format("(id=%d", nodeId)); string sep = " "; for (int i = 0; i < labels.Length(); i++) { Append(sep); Append(":" + labels.StringValue(i)); sep = ""; } if (properties.Size() > 0) { Append(" "); properties.WriteTo(this); } Append(")"); }
/// <summary> /// Tests the specified array /// </summary> /// <typeparam name="T"></typeparam> /// <param name="testValues"></param> private void TestArray <T>(T[] testValues) { // Parse Node node; if (typeof(T) == typeof(string)) { node = TaronParser.Parse($"TestArray [ {string.Join(", ", testValues.Select(s => $"\"{s}\"")) } ]"); } else if (typeof(T) == typeof(bool)) { node = TaronParser.Parse($"TestArray [ {string.Join(", ", testValues.Select(s => s.ToString().ToLowerInvariant())) } ]"); } else { node = TaronParser.Parse($"TestArray [ {string.Join(", ", testValues)} ]"); } // Test type and size Assert.IsInstanceOfType(node, typeof(MapValue)); MapValue mapNode = node.As <MapValue>(); Assert.IsNotNull(mapNode); Assert.AreEqual(1, mapNode.Count); // Retrieve the array ValueNode arrayValueNode; Assert.IsTrue(mapNode.TryGetValue("TestArray", out arrayValueNode)); Assert.IsNotNull(arrayValueNode); Assert.IsInstanceOfType(arrayValueNode, typeof(ArrayValue)); ArrayValue arrayValue = arrayValueNode.As <ArrayValue>(); Assert.IsNotNull(arrayValue); // Test it's content Assert.AreEqual(testValues.Length, arrayValue.Count); for (int i = 0; i < testValues.Length; i++) { TestUtils.TestPrimitiveValue(arrayValue[i], testValues[i]); } }
public void Basic_Strings() { // Iterate each test value string[] testValues = new string[] { "", "test", " ", "TestString", "\\\"" }; foreach (string testValue in testValues) { // Parse Node node = TaronParser.Parse($"TestString = \"{testValue}\""); // Test type and size Assert.IsInstanceOfType(node, typeof(MapValue)); MapValue mapNode = node.As <MapValue>(); Assert.IsNotNull(mapNode); Assert.AreEqual(1, mapNode.Count); // Test property Assert.AreEqual("TestString", mapNode.Keys.First()); TestUtils.TestPrimitiveProperty(mapNode, "TestString", testValue); } }
public void Basic_Integers() { // Iterate each test value string[] testValues = new string[] { "0", "10", "5", "3456", "-7", "-0", "-01234", "024" }; foreach (string testValue in testValues) { // Parse Node node = TaronParser.Parse($"TestNumber = {testValue}"); // Test type and size Assert.IsInstanceOfType(node, typeof(MapValue)); MapValue mapNode = node.As <MapValue>(); Assert.IsNotNull(mapNode); Assert.AreEqual(1, mapNode.Count); // Test property Assert.AreEqual("TestNumber", mapNode.Keys.First()); TestUtils.TestPrimitiveProperty(mapNode, "TestNumber", int.Parse(testValue)); } }
public void Translator_BasicMap_FromModel_ToDict() { // Parse the basic map Node node = TaronParser.Parse(TestUtils.ReusableMapTest); Assert.IsNotNull(node); MapValue mapValue = node.As <MapValue>(); Assert.IsNotNull(mapValue); // Translate to weakly-typed dict var t = new TaronTranslator(TaronTranslatorOptions.Default); var dict = t.Deserialise(typeof(Dictionary <string, object>), mapValue) as Dictionary <string, object>; Assert.IsNotNull(dict); Assert.AreEqual(5, dict.Count); Assert.AreEqual(10.0, dict["DecimalVal"]); Assert.AreEqual(5, dict["IntegerVal"]); Assert.AreEqual("thingy", dict["StringVal"]); Assert.AreEqual(true, dict["BooleanVal"]); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: static java.util.Map<String,Object> parseTransactionMetadata(org.neo4j.values.virtual.MapValue meta) throws org.neo4j.bolt.messaging.BoltIOException internal static IDictionary <string, object> ParseTransactionMetadata(MapValue meta) { AnyValue anyValue = meta.Get(TX_META_DATA_KEY); if (anyValue == Values.NO_VALUE) { return(null); } else if (anyValue is MapValue) { MapValue mapValue = ( MapValue )anyValue; TransactionMetadataWriter writer = new TransactionMetadataWriter(); IDictionary <string, object> txMeta = new Dictionary <string, object>(mapValue.Size()); mapValue.Foreach((key, value) => txMeta.put(key, writer.ValueAsObject(value))); return(txMeta); } else { throw new BoltIOException(Org.Neo4j.Kernel.Api.Exceptions.Status_Request.Invalid, "Expecting transaction metadata value to be a Map value, but got: " + anyValue); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldIncludeBasicMetadata() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldIncludeBasicMetadata() { // Given QueryStatistics queryStatistics = mock(typeof(QueryStatistics)); when(queryStatistics.ContainsUpdates()).thenReturn(true); when(queryStatistics.NodesCreated).thenReturn(1); when(queryStatistics.NodesDeleted).thenReturn(2); when(queryStatistics.RelationshipsCreated).thenReturn(3); when(queryStatistics.RelationshipsDeleted).thenReturn(4); when(queryStatistics.PropertiesSet).thenReturn(5); when(queryStatistics.IndexesAdded).thenReturn(6); when(queryStatistics.IndexesRemoved).thenReturn(7); when(queryStatistics.ConstraintsAdded).thenReturn(8); when(queryStatistics.ConstraintsRemoved).thenReturn(9); when(queryStatistics.LabelsAdded).thenReturn(10); when(queryStatistics.LabelsRemoved).thenReturn(11); QueryResult result = mock(typeof(QueryResult)); when(result.FieldNames()).thenReturn(new string[0]); when(result.ExecutionType()).thenReturn(query(READ_WRITE)); when(result.QueryStatistics()).thenReturn(queryStatistics); when(result.Notifications).thenReturn(Collections.emptyList()); Clock clock = mock(typeof(Clock)); when(clock.millis()).thenReturn(0L, 1337L); TransactionalContext tc = mock(typeof(TransactionalContext)); CypherAdapterStream stream = new CypherAdapterStream(result, clock); // When MapValue meta = MetadataOf(stream); // Then assertThat(meta.Get("type"), equalTo(stringValue("rw"))); assertThat(meta.Get("stats"), equalTo(MapValues("nodes-created", intValue(1), "nodes-deleted", intValue(2), "relationships-created", intValue(3), "relationships-deleted", intValue(4), "properties-set", intValue(5), "indexes-added", intValue(6), "indexes-removed", intValue(7), "constraints-added", intValue(8), "constraints-removed", intValue(9), "labels-added", intValue(10), "labels-removed", intValue(11)))); assertThat(meta.Get("result_consumed_after"), equalTo(longValue(1337L))); }
private static void AssertMapEqualsWithDelta(MapValue a, MapValue b, double delta) { assertThat("Map should have same size", a.Size(), equalTo(b.Size())); a.Foreach((key, value) => { AnyValue aValue = value; AnyValue bValue = b.Get(key); if (aValue is MapValue) { assertThat("Value mismatch", bValue is MapValue); AssertMapEqualsWithDelta(( MapValue )aValue, ( MapValue )bValue, delta); } else if (aValue is DoubleValue) { assertThat("Value mismatch", (( DoubleValue )aValue).doubleValue(), closeTo(((DoubleValue)bValue).doubleValue(), delta)); } else { assertThat("Value mismatch", aValue, equalTo(bValue)); } }); }
private static object GetMapValueData(MapValue mapValue) { switch (mapValue.Type) { case DataType.UnknownType: return(mapValue.StrValue); case DataType.Integer: return(mapValue.Int32Value); case DataType.Real: return(mapValue.DoubleValue); case DataType.Character: return(mapValue.StrValue); case DataType.Point: return(mapValue.Point.ToString()); default: throw new System.Exception("DataType Default case not implemented!"); } }
public void SpawnSelf(EnemyData enemy_data, Transform parent_transform) { CharacterData character_data = new CharacterData(); character_data.name = enemy_data.enemyType.ToString(); character_data.moveSpeed = enemy_data.moveSpeed; character_data.jumpInitForce = enemy_data.jumpInitForce; character_data.maxJumpCnt = enemy_data.maxJumpCnt; character_data.atk = enemy_data.fire_atk; character_data.hp = enemy_data.hp; if (damageArea != null) { damageArea.Reset(enemy_data.hit_atk, DamageArea.DamageGroup.Enemy); } Reset(character_data); if (muzzle_ != null) { muzzle_.Reset(); } Clear(); // Faces left SetFaceRight(false, true /* force set */); transform.parent = parent_transform; transform.localPosition = new Vector2( // the center x axis of a unit length from (x to x + 1). MapValue.RealValue(enemy_data.spawnPosition.x + enemy_data.spawnPosition.x + 1) * 0.5f, MapValue.RealValue(enemy_data.spawnPosition.y)); transform.localScale = Vector3.one; is_action_ = false; is_visible_ = false; EventPool.Instance.Emit(Events.OnEnemyBorn, this); }
public void Basic_Booleans() { // Iterate each test value string[] testValues = new string[] { "true", "false" }; foreach (string testValue in testValues) { // Parse Node node = TaronParser.Parse($"TestBoolean = {testValue}"); // Test type and size Assert.IsInstanceOfType(node, typeof(MapValue)); MapValue mapNode = node.As <MapValue>(); Assert.IsNotNull(mapNode); Assert.AreEqual(1, mapNode.Count); // Test property Assert.AreEqual("TestBoolean", mapNode.Keys.First()); TestUtils.TestPrimitiveProperty(mapNode, "TestBoolean", bool.Parse(testValue)); } // Test error on invalid booleans Exception ex = null; try { TaronParser.Parse("TestBoolean = True"); TaronParser.Parse("TestBoolean = False"); } catch (Exception theEx) { ex = theEx; } finally { Assert.IsNotNull(ex); } }
public static DateTimeValue Truncate(TemporalUnit unit, TemporalValue input, MapValue fields, System.Func <ZoneId> defaultZone) { Pair <LocalDate, LocalTime> pair = GetTruncatedDateAndTime(unit, input, "date time"); LocalDate truncatedDate = pair.First(); LocalTime truncatedTime = pair.Other(); ZoneId zoneId = input.supportsTimeZone() ? input.getZoneId(defaultZone) : defaultZone(); ZonedDateTime truncatedZDT = ZonedDateTime.of(truncatedDate, truncatedTime, zoneId); if (fields.Size() == 0) { return(Datetime(truncatedZDT)); } else { // Timezone needs some special handling, since the builder will shift keeping the instant instead of the local time AnyValue timezone = fields.Get("timezone"); if (timezone != NO_VALUE) { truncatedZDT = truncatedZDT.withZoneSameLocal(TimezoneOf(timezone)); } return(UpdateFieldMapWithConflictingSubseconds(fields, unit, truncatedZDT, (mapValue, zonedDateTime) => { if (mapValue.size() == 0) { return Datetime(zonedDateTime); } else { return Build(mapValue.updatedWith("datetime", Datetime(zonedDateTime)), defaultZone); } })); } }
public void Basic_Decimals() { // Iterate each test value string[] testValues = new string[] { "0.1", "10.2", "5.43", "-400.3", "-0.5", "-0.0" }; foreach (string testValue in testValues) { // Parse Node node = TaronParser.Parse($"TestNumber = {testValue}"); // Test type and size Assert.IsInstanceOfType(node, typeof(MapValue)); MapValue mapNode = node.As <MapValue>(); Assert.IsNotNull(mapNode); Assert.AreEqual(1, mapNode.Count); // Test property Assert.AreEqual("TestNumber", mapNode.Keys.First()); TestUtils.TestPrimitiveProperty(mapNode, "TestNumber", double.Parse(testValue)); } // Test error on invalid numbers Exception ex = null; try { TaronParser.Parse("TestNumber = .2"); } catch (Exception theEx) { ex = theEx; } finally { Assert.IsNotNull(ex); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public org.neo4j.values.AnyValue apply(org.neo4j.kernel.api.proc.Context ctx, org.neo4j.values.AnyValue[] input) throws org.neo4j.internal.kernel.api.exceptions.ProcedureException public override AnyValue Apply(Context ctx, AnyValue[] input) { if (input == null) { return(NO_VALUE); } else if (input.Length == 1) { if (input[0] == NO_VALUE || input[0] == null) { return(NO_VALUE); } else if (input[0] is TextValue) { return(DurationValue.parse(( TextValue )input[0])); } else if (input[0] is MapValue) { MapValue map = ( MapValue )input[0]; return(DurationValue.build(map)); } } throw new ProcedureException(Org.Neo4j.Kernel.Api.Exceptions.Status_Procedure.ProcedureCallFailed, "Invalid call signature for " + this.GetType().Name + ": Provided input was " + Arrays.ToString(input)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldSetTxMetadata() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldSetTxMetadata() { // Given NegotiateBoltV3(); IDictionary <string, object> txMetadata = map("who-is-your-boss", "Molly-mostly-white"); IDictionary <string, object> msgMetadata = map("tx_metadata", txMetadata); MapValue meta = asMapValue(msgMetadata); Connection.send(Util.chunk(new BeginMessage(meta), new RunMessage("RETURN 1"), PullAllMessage.INSTANCE)); // When assertThat(Connection, Util.eventuallyReceives(msgSuccess(), msgSuccess(), msgRecord(eqRecord(equalTo(longValue(1L)))), msgSuccess())); // Then GraphDatabaseAPI gdb = ( GraphDatabaseAPI )Server.graphDatabaseService(); ISet <KernelTransactionHandle> txHandles = gdb.DependencyResolver.resolveDependency(typeof(KernelTransactions)).activeTransactions(); assertThat(txHandles.Count, equalTo(1)); foreach (KernelTransactionHandle txHandle in txHandles) { assertThat(txHandle.MetaData, equalTo(txMetadata)); } Connection.send(Util.chunk(ROLLBACK_MESSAGE)); }
private void AddMethodIntern(int inlet, Symbol sel, Kind k, Delegate d) { // add to map if (m_map.Length <= inlet) ResizeArray(ref m_map, inlet + 1); Hashtable h = m_map[inlet]; if(h == null) m_map[inlet] = h = new Hashtable(); h[sel] = new MapValue(k, d); methodflags |= MethodFlags.f_anything; }
public static DateValue Build(MapValue map, System.Func <ZoneId> defaultZone) { return(StructureBuilder.build(Builder(defaultZone), map)); }
public abstract Base MapMap(MapValue value);
// Recurse through maps and sequences public override AnyValue MapMap(MapValue value) { value.Foreach((k, v) => v.map(this)); return(value); }
/// <summary> /// Serialises the specified object into a value node /// </summary> /// <param name="obj"></param> /// <returns></returns> public ValueNode Serialise(object obj) { // Sanity check if (obj == null) { return(null); } Type t = obj.GetType(); // Is it a map type? if (typeof(IDictionary).IsAssignableFrom(t)) { // Create a map type MapValue mapVal = new MapValue(); IDictionary dict = obj as IDictionary; foreach (var key in dict.Keys) { if (key is string) { ValueNode tmp; if (translateOpts.Serialise(dict[key], out tmp)) { mapVal.Add(key as string, tmp); } else { mapVal.Add(key as string, null); } } } return(mapVal); } // Is it an array type? else if (t.IsArray) { // Create an array type ArrayValue arrVal = new ArrayValue(); var arr = obj as Array; for (int i = 0; i < arr.Length; i++) { ValueNode tmp; if (translateOpts.Serialise(arr.GetValue(i), out tmp)) { arrVal.Add(tmp); } else { arrVal.Add(null); } } return(arrVal); } else if (typeof(IList).IsAssignableFrom(t)) { // Create an array type ArrayValue arrVal = new ArrayValue(); var list = obj as IList; for (int i = 0; i < list.Count; i++) { ValueNode tmp; if (translateOpts.Serialise(list[i], out tmp)) { arrVal.Add(tmp); } else { arrVal.Add(null); } } return(arrVal); } else if (typeof(ICollection).IsAssignableFrom(t)) { // Create an array type ArrayValue arrVal = new ArrayValue(); var collection = obj as ICollection; foreach (object item in collection) { ValueNode tmp; if (translateOpts.Serialise(item, out tmp)) { arrVal.Add(tmp); } else { arrVal.Add(null); } } return(arrVal); } // Fill a map via reflection MapValue mapValue = new MapValue(); foreach (var field in t.GetFields(BindingFlags.Public | BindingFlags.Instance)) { ValueNode tmp; if (translateOpts.Serialise(field.GetValue(obj), out tmp) && tmp != null) { mapValue.Add(field.Name, tmp); } } foreach (var property in t.GetProperties(BindingFlags.Public | BindingFlags.Instance)) { if (property.GetGetMethod() != null) { ValueNode tmp; if (translateOpts.Serialise(property.GetValue(obj, null), out tmp) && tmp != null) { mapValue.Add(property.Name, tmp); } } } return(mapValue); }
/// <summary> /// Populates the a .NET object with the specified value node /// </summary> /// <param name="obj"></param> /// <param name="node"></param> public void Deserialise(object obj, ValueNode node) { // Sanity check if (obj == null) { return; } Type t = obj.GetType(); // Is it a map type? if (typeof(IDictionary).IsAssignableFrom(t) && node is MapValue) { IDictionary dict = obj as IDictionary; MapValue mapVal = node.As <MapValue>(); // Is it a generic dict? if (TranslateOptions.IsGenericType(typeof(IDictionary <,>), t)) { Type[] genArgs = t.GetGenericArguments(); if (genArgs[0] != typeof(string)) { return; // TODO: Throw error? } foreach (var pair in mapVal) { object val; if (translateOpts.Deserialise(genArgs[1], pair.Value, out val)) { dict[pair.Key] = val; } } } else { foreach (var pair in mapVal) { object val; if (translateOpts.Deserialise(null, pair.Value, out val)) { dict.Add(pair.Key, val); } } } } // Is it an array type? else if (t.IsArray) { Array arr = obj as Array; ArrayValue arrVal = node.As <ArrayValue>(); Type elementType = t.GetElementType(); for (int i = 0; i < Math.Min(arrVal.Count, arr.Length); i++) { object val; translateOpts.Deserialise(elementType == typeof(object) ? null : elementType, arrVal[i], out val); arr.SetValue(val, i); } } else if (typeof(IList).IsAssignableFrom(t)) { var list = obj as IList; ArrayValue arrVal = node.As <ArrayValue>(); list.Clear(); // Is it a generic list? if (TranslateOptions.IsGenericType(typeof(IList <>), t)) { Type elementType = t.GetGenericArguments()[0]; for (int i = 0; i < arrVal.Count; i++) { object val; translateOpts.Deserialise(elementType == typeof(object) ? null : elementType, arrVal[i], out val); list.Add(val); } } else { for (int i = 0; i < arrVal.Count; i++) { object val; translateOpts.Deserialise(null, arrVal[i], out val); list.Add(val); } } } else if (typeof(ICollection).IsAssignableFrom(t)) { throw new NotImplementedException("Can't deserialise into an ICollection"); } MapValue mapValue = node as MapValue; if (mapValue == null) { return; // Throw error? } foreach (var pair in mapValue) { MemberInfo member = t.GetMember(pair.Key, BindingFlags.Public | BindingFlags.Instance) .Where(m => m is FieldInfo || m is PropertyInfo) .SingleOrDefault(); if (member != null) { FieldInfo fieldInfo = member as FieldInfo; if (fieldInfo != null) { object val; translateOpts.Deserialise(fieldInfo.FieldType, pair.Value, out val); if ((val == null && !fieldInfo.FieldType.IsValueType) || fieldInfo.FieldType.IsAssignableFrom(val.GetType())) { fieldInfo.SetValue(obj, val); } } PropertyInfo propertyInfo = member as PropertyInfo; if (propertyInfo != null) { object val; translateOpts.Deserialise(propertyInfo.PropertyType, pair.Value, out val); if ((val == null && !propertyInfo.PropertyType.IsValueType) || propertyInfo.PropertyType.IsAssignableFrom(val.GetType())) { propertyInfo.SetValue(obj, val, null); } } } } }
/// <summary> /// Serialises the specified object into a value node /// </summary> /// <param name="obj"></param> /// <returns></returns> public ValueNode Serialise(object obj) { // Sanity check if (obj == null) return null; Type t = obj.GetType(); // Is it a map type? if (typeof(IDictionary).IsAssignableFrom(t)) { // Create a map type MapValue mapVal = new MapValue(); IDictionary dict = obj as IDictionary; foreach (var key in dict.Keys) { if (key is string) { ValueNode tmp; if (translateOpts.Serialise(dict[key], out tmp)) mapVal.Add(key as string, tmp); else mapVal.Add(key as string, null); } } return mapVal; } // Is it an array type? else if (t.IsArray) { // Create an array type ArrayValue arrVal = new ArrayValue(); var arr = obj as Array; for (int i = 0; i < arr.Length; i++) { ValueNode tmp; if (translateOpts.Serialise(arr.GetValue(i), out tmp)) arrVal.Add(tmp); else arrVal.Add(null); } return arrVal; } else if (typeof(IList).IsAssignableFrom(t)) { // Create an array type ArrayValue arrVal = new ArrayValue(); var list = obj as IList; for (int i = 0; i < list.Count; i++) { ValueNode tmp; if (translateOpts.Serialise(list[i], out tmp)) arrVal.Add(tmp); else arrVal.Add(null); } return arrVal; } else if (typeof(ICollection).IsAssignableFrom(t)) { // Create an array type ArrayValue arrVal = new ArrayValue(); var collection = obj as ICollection; foreach (object item in collection) { ValueNode tmp; if (translateOpts.Serialise(item, out tmp)) arrVal.Add(tmp); else arrVal.Add(null); } return arrVal; } // Fill a map via reflection MapValue mapValue = new MapValue(); foreach (var field in t.GetFields(BindingFlags.Public | BindingFlags.Instance)) { ValueNode tmp; if (translateOpts.Serialise(field.GetValue(obj), out tmp) && tmp != null) mapValue.Add(field.Name, tmp); } foreach (var property in t.GetProperties(BindingFlags.Public | BindingFlags.Instance)) { if (property.GetGetMethod() != null) { ValueNode tmp; if (translateOpts.Serialise(property.GetValue(obj, null), out tmp) && tmp != null) mapValue.Add(property.Name, tmp); } } return mapValue; }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void writeRelationship(long relationshipId, long startNodeId, long endNodeId, org.neo4j.values.storable.TextValue type, org.neo4j.values.virtual.MapValue properties) throws java.io.IOException public override void WriteRelationship(long relationshipId, long startNodeId, long endNodeId, TextValue type, MapValue properties) { PackStructHeader(RELATIONSHIP_SIZE, RELATIONSHIP); Pack(relationshipId); Pack(startNodeId); Pack(endNodeId); type.WriteTo(this); properties.WriteTo(this); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public RunMessage(String statement, org.neo4j.values.virtual.MapValue params) throws org.neo4j.bolt.messaging.BoltIOException public RunMessage(string statement, MapValue @params) : this(statement, @params, VirtualValues.EMPTY_MAP) { }