Пример #1
0
        /// <summary>
        /// Provides example code for the BlogMLPost.PostTypeByName(string) method
        /// </summary>
        public static void PostTypeByNameExample()
        {
            BlogMLPostType postType = BlogMLPost.PostTypeByName("normal");

            if (postType == BlogMLPostType.Normal)
            {
            }
        }
Пример #2
0
        /// <summary>
        /// Provides example code for the BlogMLPost.PostTypeByName(string) method
        /// </summary>
        public static void PostTypeByNameExample()
        {
            #region PostTypeByName(string name)
            BlogMLPostType postType = BlogMLPost.PostTypeByName("normal");

            if (postType == BlogMLPostType.Normal)
            {
            }
            #endregion
        }
Пример #3
0
        /// <summary>
        /// Returns the <see cref="BlogMLPostType"/> enumeration value that corresponds to the specified post type name.
        /// </summary>
        /// <param name="name">The name of the post type.</param>
        /// <returns>A <see cref="BlogMLPostType"/> enumeration value that corresponds to the specified string, otherwise returns <b>BlogMLPostType.None</b>.</returns>
        /// <remarks>This method disregards case of specified post 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 PostTypeByName method.">
        ///         <code 
        ///             source="..\..\Documentation\Microsoft .NET 2.0\CodeExamplesLibrary\Core\BlogML\BlogMLPostExample.cs" 
        ///             region="PostTypeByName(string name)" 
        ///         />
        ///     </code>
        /// </example>
        public static BlogMLPostType PostTypeByName(string name)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            BlogMLPostType postType = BlogMLPostType.None;

            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNullOrEmptyString(name, "name");

            //------------------------------------------------------------
            //	Determine syndication content format based on supplied name
            //------------------------------------------------------------
            foreach (System.Reflection.FieldInfo fieldInfo in typeof(BlogMLPostType).GetFields())
            {
                if (fieldInfo.FieldType == typeof(BlogMLPostType))
                {
                    BlogMLPostType type      = (BlogMLPostType)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)
                        {
                            postType    = type;
                            break;
                        }
                    }
                }
            }

            return postType;
        }
Пример #4
0
        /// <summary>
        /// Returns the post type identifier for the supplied <see cref="BlogMLPostType"/>.
        /// </summary>
        /// <param name="type">The <see cref="BlogMLPostType"/> to get the post type identifier for.</param>
        /// <returns>The post type 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 PostTypeAsString method.">
        ///         <code 
        ///             source="..\..\Documentation\Microsoft .NET 2.0\CodeExamplesLibrary\Core\BlogML\BlogMLPostExample.cs" 
        ///             region="PostTypeAsString(BlogMLPostType type)" 
        ///         />
        ///     </code>
        /// </example>
        public static string PostTypeAsString(BlogMLPostType type)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            string name = String.Empty;

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

                    if (postType == 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;
        }