GetText() public method

This is used to acquire a text value for the specified object. This will convert the object to a string using the transformer so that it can be deserialized from the generate XML document. However if the type is an Enum type then the text value is taken from Enum.name so it can later be deserialized easily using the enumeration class and name.
public GetText ( Object source ) : String
source Object /// this is the object instance to get the value of ///
return String
コード例 #1
0
ファイル: Primitive.cs プロジェクト: restlet/simplexml
        /// <summary>
        /// This <c>write</c> method will serialize the contents of
        /// the provided object to the given XML element. This will use
        /// the <c>String.valueOf</c> method to convert the object to
        /// a string if the object represents a primitive, if however the
        /// object represents an enumerated type then the text value is
        /// created using <c>Enum.name</c>.
        /// </summary>
        /// <param name="source">
        /// this is the object to be serialized
        /// </param>
        /// <param name="node">
        /// this is the XML element to have its text set
        /// </param>
        public void Write(OutputNode node, Object source)
        {
            String text = factory.GetText(source);

            if (text != null)
            {
                node.setValue(text);
            }
        }
コード例 #2
0
ファイル: PrimitiveKey.cs プロジェクト: restlet/simplexml
        /// <summary>
        /// This method is used to write the value to the specified node.
        /// This will write the item as an attribute to the provided node,
        /// the name of the attribute is taken from the annotation.
        /// </summary>
        /// <param name="node">
        /// this is the node that the value is written to
        /// </param>
        /// <param name="item">
        /// this is the item that is to be written
        /// </param>
        public void WriteAttribute(OutputNode node, Object item)
        {
            Class  expect = type.Type;
            String text   = factory.GetText(item);
            String key    = entry.Key;

            if (key == null)
            {
                key = context.GetName(expect);
            }
            String name = style.GetAttribute(key);

            if (text != null)
            {
                node.setAttribute(name, text);
            }
        }