Exemplo n.º 1
0
        public void Deserialize(IShapeObject shape, Dictionary <string, object> shapeState)
        {
            shape = shape ?? throw new ArgumentNullException(nameof(shape));

            var shapeType = shape.GetType();

            var props = propertyCache.GetProperties(shapeType);

            foreach ((string propName, object value) in shapeState)
            {
                props[propName].Setter.DynamicInvoke(shape, value);
            }
        }
        public static PropertyInfo GetIdentityField <T>(T obj)
        {
            PropertyCache propertyCache = PropertyService.Instance.GetInterfaceProperties <T>(obj);

            foreach (PropertyInfo prop in propertyCache.GetProperties())
            {
                object[] _attributes = prop.GetCustomAttributes(typeof(DbBinding), false);
                if (_attributes.Length > 0)
                {
                    if (_attributes[0] is DbBinding)
                    {
                        if (((DbBinding)_attributes[0]).IsIdentityField)
                        {
                            return(prop);
                        }
                    }
                }
            }
            return(null);
        }
Exemplo n.º 3
0
        //TODO:  Change to use NewtonSoft and append other objects
        public static string ToJson <TObject>(this TObject obj)

            where TObject : XapObjectCore
        {
            PropertyCache props = PropertyService.Instance.GetInterfaceProperties(obj);

            // Start the JSON object.
            StringBuilder json = new StringBuilder();

            json.AppendLine("{\"data\":{");

            // Add the properties.
            foreach (PropertyInfo prop in props.GetProperties())
            {
                json.AppendLine($"\"{prop.ShortName()}\":\"{prop.GetValue(obj, null).ToString()}\",");
            }

            json = json.RemoveLast(",");

            // Finish the JSON object.
            json.AppendLine("}}");
            return(json.ToString());
        }