GetBinaryConstructorType() public static method

Returns the Type of the constructor with exact one parameter which is either a byte[] or a Stream.
A a non-null returnvalue is also an inducator, that the given Type has a constructor with a binary parameter.
public static GetBinaryConstructorType ( Type type ) : Type
type System.Type
return System.Type
Beispiel #1
0
        /// <summary>
        /// Serializes an Object and appends it to the specified XmlNode.
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="name"></param>
        /// <param name="parent"></param>
        public void Serialize(object obj, String name, XmlNode parent)
        {
            //Reset();

            XmlDocument doc = parent.OwnerDocument;

            XmlElement root = doc.CreateElement(taglib.OBJECT_TAG);

            parent.AppendChild(root);

            XmlComment comment = root.OwnerDocument.CreateComment(" Data section : Don't edit any attributes ! ");

            root.AppendChild(comment);

            SetObjectInfoAttributes(name, obj.GetType(), root);

            Type ctortype = TypeInfo.GetBinaryConstructorType(obj.GetType());

            if (ctortype != null)
            {
                SerializeBinaryObject(obj, ctortype, root);
            }
            else
            {
                SerializeProperties(obj, root);
            }

            WriteTypeDictionary(root);
        }
Beispiel #2
0
        /// <summary>
        /// Sets a property.
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="value"></param>
        /// <param name="pi"></param>
        /// <param name="parent"></param>
        /// <remarks>
        /// This is the central method which is called recursivly!
        /// </remarks>
        protected void SetProperty(object obj, object value, PropertyInfo pi, XmlNode parent)
        {
            //      object val = value; ??

            try
            {
                // Empty values are ignored (no need to restore null references or empty Strings)
                if (value == null || value.Equals(string.Empty))
                {
                    return;
                }

                // Get the Type
                //Type pt = pi.PropertyType;
                Type pt = value.GetType();

                // Check whether this property can be serialized and deserialized
                if (CheckPropertyHasToBeSerialized(pi) && (pt.IsSerializable || IgnoreSerializableAttribute) && (pi.CanWrite) &&
                    ((pt.IsPublic) || (pt.IsEnum)))
                {
                    XmlElement prop = parent.OwnerDocument.CreateElement(taglib.PROPERTY_TAG);

                    SetObjectInfoAttributes(pi.Name, pt, prop);

                    // Try to find a constructor for binary data.
                    // If found remember the parameter's Type.
                    Type binctortype = TypeInfo.GetBinaryConstructorType(pt);

                    if (binctortype != null)                     // a binary contructor was found
                    {
                        /*
                         * b. Trying to handle binary data
                         */

                        SerializeBinaryObject(pi.GetValue(obj, null), binctortype, prop);
                    }
                    else if (TypeInfo.IsCollection(pt))
                    {
                        /*
                         * a. Collections ask for a specific handling
                         */
                        SetCollectionItems(obj, (ICollection)value, prop);
                    }
                    else
                    {
                        /*
                         * c. "normal" classes
                         */

                        SetXmlElementFromBasicPropertyValue(prop, pt, value, parent);
                    }
                    // Append the property node to the paren XmlNode
                    parent.AppendChild(prop);
                }
            }
            catch (Exception)
            {
                if (!IgnoreSerialisationErrors)
                {
                    throw;
                }
            }
        }