/// <summary> /// Tries the get value. /// </summary> /// <param name="object">The object.</param> /// <param name="propertyName">Name of the property.</param> /// <param name="value">The value.</param> /// <returns>True if the value is returned, false otherwise.</returns> public bool TryGetValue(Dynamo @object, string propertyName, out object?value) { var objectType = @object.GetType(); var Key = objectType.GetHashCode(); if (!Types.ContainsKey(Key)) { value = null; return(false); } var ReturnValue = Types[Key].TryGetValue(@object, propertyName, out var TempValue); value = TempValue; return(ReturnValue); }
/// <summary> /// Setups the type. /// </summary> /// <param name="object">The @object.</param> public void SetupType(Dynamo @object) { var objectType = @object.GetType(); var Key = objectType.GetHashCode(); if (Types.ContainsKey(Key) || objectType == typeof(Dynamo)) { return; } lock (LockObject) { var TempObject = (typeof(DynamoProperties <>).MakeGenericType(objectType).Create() as IDynamoProperties) !; TempObject.SetupValues(); Types.Add(Key, TempObject); } }
public void Serialize() { var Serializer = new JsonSerializer(); dynamic Object = new { A = 5, B = "ASDF" }; Assert.Equal("{\"A\":5,\"B\":\"ASDF\"}", Serializer.Serialize(Object.GetType(), Object)); Object = new TestObject { A = 5, B = "ASDF" }; Assert.Equal("{\"A\":5,\"B\":\"ASDF\"}", Serializer.Serialize(Object.GetType(), Object)); Object = new ExpandoObject(); Object.A = 5; Object.B = "ASDF"; Assert.Equal("{\"A\":5,\"B\":\"ASDF\"}", Serializer.Serialize(Object.GetType(), Object)); Object = new Dynamo(); Object.A = 5; Object.B = "ASDF"; Assert.Equal("{\"A\":5,\"B\":\"ASDF\"}", Serializer.Serialize(Object.GetType(), Object)); }