//============================================================
        //	STATIC METHODS
        //============================================================
        #region ConstructTypeAsString(BlogMLContentType type)
        /// <summary>
        /// Returns the text construct identifier for the supplied <see cref="BlogMLContentType"/>.
        /// </summary>
        /// <param name="type">The <see cref="BlogMLContentType"/> to get the text construct identifier for.</param>
        /// <returns>The text construct identifier for the supplied <paramref name="type"/>, otherwise returns an empty string.</returns>
        /// <example>
        ///     <code lang="cs" title="The following code example demonstrates the usage of the ConstructTypeAsString method.">
        ///         <code
        ///             source="..\..\Documentation\Microsoft .NET 3.5\CodeExamplesLibrary\Core\BlogML\BlogMLTextConstructExample.cs"
        ///             region="ConstructTypeAsString(BlogMLContentType type)"
        ///         />
        ///     </code>
        /// </example>
        public static string ConstructTypeAsString(BlogMLContentType type)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            string name = String.Empty;

            //------------------------------------------------------------
            //	Return alternate value based on supplied protocol
            //------------------------------------------------------------
            foreach (System.Reflection.FieldInfo fieldInfo in typeof(BlogMLContentType).GetFields())
            {
                if (fieldInfo.FieldType == typeof(BlogMLContentType))
                {
                    BlogMLContentType constructType = (BlogMLContentType)Enum.Parse(fieldInfo.FieldType, fieldInfo.Name);

                    if (constructType == type)
                    {
                        object[] customAttributes = fieldInfo.GetCustomAttributes(typeof(EnumerationMetadataAttribute), false);

                        if (customAttributes != null && customAttributes.Length > 0)
                        {
                            EnumerationMetadataAttribute enumerationMetadata = customAttributes[0] as EnumerationMetadataAttribute;

                            name = enumerationMetadata.AlternateValue;
                            break;
                        }
                    }
                }
            }

            return(name);
        }
Пример #2
0
        /// <summary>
        /// Loads this <see cref="BlogMLTextConstruct"/> using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <returns><b>true</b> if the <see cref="BlogMLTextConstruct"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns>
        /// <remarks>
        ///     This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="BlogMLTextConstruct"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool Load(XPathNavigator source)
        {
            bool wasLoaded = false;

            Guard.ArgumentNotNull(source, "source");
            if (source.HasAttributes)
            {
                string typeAttribute = source.GetAttribute("type", String.Empty);
                if (!String.IsNullOrEmpty(typeAttribute))
                {
                    BlogMLContentType type = BlogMLTextConstruct.ConstructTypeByName(typeAttribute);
                    if (type != BlogMLContentType.None)
                    {
                        this.ContentType = type;
                        wasLoaded        = true;
                    }
                }
            }

            if (!String.IsNullOrEmpty(source.Value))
            {
                this.Content = source.Value;
                wasLoaded    = true;
            }

            return(wasLoaded);
        }
Пример #3
0
        /// <summary>
        /// Returns the <see cref="BlogMLContentType"/> enumeration value that corresponds to the specified text construct type name.
        /// </summary>
        /// <param name="name">The name of the text construct type.</param>
        /// <returns>A <see cref="BlogMLContentType"/> enumeration value that corresponds to the specified string, otherwise returns <b>BlogMLContentType.None</b>.</returns>
        /// <remarks>This method disregards case of specified text construct type name.</remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="name"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="name"/> is an empty string.</exception>
        /// <example>
        ///     <code lang="cs" title="The following code example demonstrates the usage of the ConstructTypeByName method.">
        ///         <code
        ///             source="..\..\Documentation\Microsoft .NET 3.5\CodeExamplesLibrary\Core\BlogML\BlogMLTextConstructExample.cs"
        ///             region="ConstructTypeByName(string name)"
        ///         />
        ///     </code>
        /// </example>
        public static BlogMLContentType ConstructTypeByName(string name)
        {
            BlogMLContentType constructType = BlogMLContentType.None;

            Guard.ArgumentNotNullOrEmptyString(name, "name");
            foreach (System.Reflection.FieldInfo fieldInfo in typeof(BlogMLContentType).GetFields())
            {
                if (fieldInfo.FieldType == typeof(BlogMLContentType))
                {
                    BlogMLContentType type             = (BlogMLContentType)Enum.Parse(fieldInfo.FieldType, fieldInfo.Name);
                    object[]          customAttributes = fieldInfo.GetCustomAttributes(typeof(EnumerationMetadataAttribute), false);

                    if (customAttributes != null && customAttributes.Length > 0)
                    {
                        EnumerationMetadataAttribute enumerationMetadata = customAttributes[0] as EnumerationMetadataAttribute;

                        if (String.Compare(name, enumerationMetadata.AlternateValue, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            constructType = type;
                            break;
                        }
                    }
                }
            }

            return(constructType);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="BlogMLTextConstruct"/> class using the supplied content and entity encoding scheme.
 /// </summary>
 /// <param name="content">The entity encoded content.</param>
 /// <param name="encoding">An <see cref="BlogMLContentType"/> enumeration value that represents the entity encoding utilized by the <paramref name="content"/>.</param>
 /// <remarks>
 ///     This constructor assumes the supplied <paramref name="content"/> is encoded per the specified <paramref name="encoding"/> scheme.
 ///     The textual content will be escaped using a <i>CDATA</i> block.
 /// </remarks>
 public BlogMLTextConstruct(string content, BlogMLContentType encoding)
 {
     //------------------------------------------------------------
     //	Initialize class state
     //------------------------------------------------------------
     this.Content     = content;
     this.ContentType = encoding;
 }
Пример #5
0
        /// <summary>
        /// Provides example code for the BlogMLTextConstruct.ConstructTypeByName(string) method
        /// </summary>
        public static void ConstructTypeByNameExample()
        {
            BlogMLContentType contentType = BlogMLTextConstruct.ConstructTypeByName("html");

            if (contentType == BlogMLContentType.Html)
            {
            }
        }
Пример #6
0
        /// <summary>
        /// Provides example code for the BlogMLTextConstruct.ConstructTypeByName(string) method
        /// </summary>
        public static void ConstructTypeByNameExample()
        {
            #region ConstructTypeByName(string name)
            BlogMLContentType contentType = BlogMLTextConstruct.ConstructTypeByName("html");

            if (contentType == BlogMLContentType.Html)
            {
            }
            #endregion
        }
        //============================================================
        //	PUBLIC METHODS
        //============================================================
        #region Load(XPathNavigator source)
        /// <summary>
        /// Loads this <see cref="BlogMLTextConstruct"/> using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <returns><b>true</b> if the <see cref="BlogMLTextConstruct"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns>
        /// <remarks>
        ///     This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="BlogMLTextConstruct"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool Load(XPathNavigator source)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool wasLoaded = false;

            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(source, "source");

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            if (source.HasAttributes)
            {
                string typeAttribute = source.GetAttribute("type", String.Empty);
                if (!String.IsNullOrEmpty(typeAttribute))
                {
                    BlogMLContentType type = BlogMLTextConstruct.ConstructTypeByName(typeAttribute);
                    if (type != BlogMLContentType.None)
                    {
                        this.ContentType = type;
                        wasLoaded        = true;
                    }
                }
            }

            if (!String.IsNullOrEmpty(source.Value))
            {
                this.Content = source.Value;
                wasLoaded    = true;
            }

            return(wasLoaded);
        }
Пример #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BlogMLTextConstruct"/> class using the supplied content and entity encoding scheme.
 /// </summary>
 /// <param name="content">The entity encoded content.</param>
 /// <param name="encoding">An <see cref="BlogMLContentType"/> enumeration value that represents the entity encoding utilized by the <paramref name="content"/>.</param>
 /// <remarks>
 ///     This constructor assumes the supplied <paramref name="content"/> is encoded per the specified <paramref name="encoding"/> scheme. 
 ///     The textual content will be escaped using a <i>CDATA</i> block.
 /// </remarks>
 public BlogMLTextConstruct(string content, BlogMLContentType encoding)
 {
     //------------------------------------------------------------
     //	Initialize class state
     //------------------------------------------------------------
     this.Content        = content;
     this.ContentType    = encoding;
 }
Пример #9
0
        /// <summary>
        /// Returns the text construct identifier for the supplied <see cref="BlogMLContentType"/>.
        /// </summary>
        /// <param name="type">The <see cref="BlogMLContentType"/> to get the text construct identifier for.</param>
        /// <returns>The text construct identifier for the supplied <paramref name="type"/>, otherwise returns an empty string.</returns>
        /// <example>
        ///     <code lang="cs" title="The following code example demonstrates the usage of the ConstructTypeAsString method.">
        ///         <code 
        ///             source="..\..\Documentation\Microsoft .NET 3.5\CodeExamplesLibrary\Core\BlogML\BlogMLTextConstructExample.cs" 
        ///             region="ConstructTypeAsString(BlogMLContentType type)" 
        ///         />
        ///     </code>
        /// </example>
        public static string ConstructTypeAsString(BlogMLContentType type)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            string name = String.Empty;

            //------------------------------------------------------------
            //	Return alternate value based on supplied protocol
            //------------------------------------------------------------
            foreach (System.Reflection.FieldInfo fieldInfo in typeof(BlogMLContentType).GetFields())
            {
                if (fieldInfo.FieldType == typeof(BlogMLContentType))
                {
                    BlogMLContentType constructType = (BlogMLContentType)Enum.Parse(fieldInfo.FieldType, fieldInfo.Name);

                    if (constructType == type)
                    {
                        object[] customAttributes   = fieldInfo.GetCustomAttributes(typeof(EnumerationMetadataAttribute), false);

                        if (customAttributes != null && customAttributes.Length > 0)
                        {
                            EnumerationMetadataAttribute enumerationMetadata = customAttributes[0] as EnumerationMetadataAttribute;

                            name    = enumerationMetadata.AlternateValue;
                            break;
                        }
                    }
                }
            }

            return name;
        }
Пример #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BlogMLTextConstruct"/> class using the supplied content and entity encoding scheme.
 /// </summary>
 /// <param name="content">The entity encoded content.</param>
 /// <param name="encoding">An <see cref="BlogMLContentType"/> enumeration value that represents the entity encoding utilized by the <paramref name="content"/>.</param>
 /// <remarks>
 ///     This constructor assumes the supplied <paramref name="content"/> is encoded per the specified <paramref name="encoding"/> scheme.
 ///     The textual content will be escaped using a <i>CDATA</i> block.
 /// </remarks>
 public BlogMLTextConstruct(string content, BlogMLContentType encoding)
 {
     this.Content     = content;
     this.ContentType = encoding;
 }