Пример #1
0
            /// <summary>
            /// Can the given type be meaningfully with protobuf-net?
            /// </summary>
            public static bool CanSerialize(Type type)
            {
                if (type == null)
                {
                    throw new ArgumentNullException("type");
                }
                if (type.IsValueType)
                {
                    return(false);
                }

                // serialize as item?
                if (Serializer.IsEntityType(type))
                {
                    return(true);
                }

                // serialize as list?
                bool enumOnly;
                Type itemType = PropertyFactory.GetListType(type, out enumOnly);

                if (itemType != null &&
                    (!enumOnly || Serializer.HasAddMethod(type, itemType)) &&
                    Serializer.IsEntityType(itemType))
                {
                    return(true);
                }
                return(false);
            }