Exemplo n.º 1
0
        public void GetValuesFrom(object instance)
        {
            Properties = new Dictionary <string, object>();
            TypeName   = instance.GetType().Name;
            if (instance is IGuid guidable)
            {
                Guid = guidable.Guid;
            }

            PropertyInfo[] properties = instance.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
            foreach (PropertyInfo propertyInfo in properties)
            {
                if (!propertyInfo.CanWrite || !propertyInfo.CanRead)
                {
                    continue;
                }

                Newtonsoft.Json.JsonIgnoreAttribute jsonIgnore = propertyInfo.GetCustomAttribute <Newtonsoft.Json.JsonIgnoreAttribute>();
                if (jsonIgnore != null)
                {
                    continue;
                }

                Properties.Add(propertyInfo.Name, propertyInfo.GetValue(instance));
            }
            // TODO: More here...
        }
        static bool IsIgnoreAttribute(PropertyInfo pi)
        {
            var piType = pi.PropertyType;

            object[] attrs = pi.GetCustomAttributes(true);
            foreach (object attr in attrs)
            {
                Newtonsoft.Json.JsonIgnoreAttribute jsonIgnoreAttr = attr as Newtonsoft.Json.JsonIgnoreAttribute;
                if (jsonIgnoreAttr != null)
                {
                    return(true);
                }

                System.Xml.Serialization.XmlIgnoreAttribute xmlIgnore = attr as System.Xml.Serialization.XmlIgnoreAttribute;
                if (xmlIgnore != null)
                {
                    return(true);
                }
            }

            return(false);
        }