コード例 #1
0
        public static FreeDocument UnsafeDictSerialize(this object item)
        {
            var type = item.GetType();

            if (type != lastType)
            {
                propertys =
                    type.GetProperties().Where(
                        d => d.CanRead && d.CanWrite && AttributeHelper.IsPOCOType(d.PropertyType)).ToArray();
            }
            lastType = type;

            var doc = new FreeDocument();

            foreach (var propertyInfo in propertys)
            {
                var v = propertyInfo.GetValue(item, null);
                if (v != null)
                {
                    doc.Add(propertyInfo.Name, v);
                }
            }

            return(doc);
        }
コード例 #2
0
        public static void UnsafeDictDeserialize(this object item, IDictionary <string, object> dict)
        {
            var type = item.GetType();

            if (type != lastType)
            {
                propertys =
                    type.GetProperties().Where(
                        d => d.CanRead && d.CanWrite && AttributeHelper.IsPOCOType(d.PropertyType)).ToArray();
            }
            lastType = type;

            foreach (var propertyInfo in propertys)
            {
                propertyInfo.SetValue(
                    item,
                    dict.Set(propertyInfo.Name, propertyInfo.GetValue(item, null), propertyInfo.PropertyType),
                    null);
            }
        }