Esempio n. 1
0
        // property serialization defaults


        /// <summary>
        /// Returns true if the given property should be serialized.
        ///
        /// Override to tweak behavior.
        /// </summary>
        protected virtual bool ShouldSerialize(TypeInfo forType, PropertyInfo property)
        {
            if (property.GetMethod == null)
            {
                return(false);
            }

            var ignoreDataMember = property.GetCustomAttribute <IgnoreDataMemberAttribute>();

            if (ignoreDataMember != null)
            {
                return(false);
            }

            var dataMember = property.GetCustomAttribute <DataMemberAttribute>();

            if (dataMember != null)
            {
                return(true);
            }

            return
                (property.GetMethod.IsPublic &&
                 !property.GetMethod.IsStatic &&
                 property.GetMethod.GetParameters().Length == 0 &&
                 property.GetMethod.ReturnType != Types.VoidType &&
                 SerializableMember.GetDefaultFormatter(property.GetMethod.ReturnType.GetTypeInfo()) != null);
        }
Esempio n. 2
0
 // common serialization defaults
 private static MethodInfo GetFormatter(TypeInfo t)
 => SerializableMember.GetDefaultFormatter(t);