当前位置: 首页>>代码示例>>C#>>正文


C# Topic.Contains方法代码示例

本文整理汇总了C#中Topic.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# Topic.Contains方法的具体用法?C# Topic.Contains怎么用?C# Topic.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Topic的用法示例。


在下文中一共展示了Topic.Contains方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetTopic

        /*==========================================================================================================================
        | METHOD: SET TOPIC
        \-------------------------------------------------------------------------------------------------------------------------*/
        /// <summary>
        ///   Looks up a topic; if it doesn't exist, creates it.
        /// </summary>
        /// <param name="parentTopic">The topic's <see cref="Topic.Parent"/>.</param>
        /// <param name="key">The topic's <see cref="Topic.Key"/>.</param>
        /// <param name="contentType">The topic's <see cref="Topic.ContentType"/> key.</param>
        /// <returns>The configured topic object.</returns>
        Topic SetTopic(Topic parentTopic, string key, string contentType)
        {
            /*------------------------------------------------------------------------------------------------------------------------
              | Validate input
              \-----------------------------------------------------------------------------------------------------------------------*/
              Contract.Requires<ArgumentNullException>(parentTopic != null, "The parent topic must be specified.");
              Topic.ValidateKey(key);

              Topic topic = null;
              if (!parentTopic.Contains(key)) {

            /*----------------------------------------------------------------------------------------------------------------------
            | Create a strongly-typed ContentType object if the contentType key is set to "ContentType"
            \---------------------------------------------------------------------------------------------------------------------*/
            if (contentType.Equals("ContentType")) {
              topic = new ContentType();
            }

            /*----------------------------------------------------------------------------------------------------------------------
            | Create a strongly-typed Attribute object if the contentType key is set to "Attribute"
            \---------------------------------------------------------------------------------------------------------------------*/
            else if (contentType.Equals("Attribute")) {
              topic = new Attribute();
            }

            /*----------------------------------------------------------------------------------------------------------------------
            | Create a strongly-typed ContentType object if the contentType key is set to "ContentType"
            \---------------------------------------------------------------------------------------------------------------------*/
            else {
              topic = Topic.Create(key, contentType);
            }

            /*----------------------------------------------------------------------------------------------------------------------
            | Set the primary topic properties (Key, ContentType, and Parent)
            \---------------------------------------------------------------------------------------------------------------------*/
            topic.Key = key;
            topic.Attributes.Set("Key", key);
            topic.ContentType = null;
            topic.Attributes.Set("ContentType", contentType);
            topic.Parent = parentTopic;
            topic.Attributes.Set("ParentID", parentTopic.Id.ToString());
              }
              else {

            /*----------------------------------------------------------------------------------------------------------------------
            | Update the primary topic properties (Key, ContentType, and Parent)
            \---------------------------------------------------------------------------------------------------------------------*/
            topic = parentTopic[key];
            topic.Key = key;
            topic.Attributes.Set("Key", key);
            topic.ContentType = null;
            topic.Attributes.Set("ContentType", contentType);
            topic.Attributes.Set("ParentID", parentTopic.Id.ToString());

              }
              return parentTopic[key];
        }
开发者ID:Ignia,项目名称:Topics-Library,代码行数:67,代码来源:TopicsSetup.cs

示例2: SetAttributeReference

        /*==========================================================================================================================
        | METHOD: SET ATTRIBUTE REFERENCE
        \-------------------------------------------------------------------------------------------------------------------------*/
        /// <summary>
        ///   Looks up an Topic (assumed to be an attribute) from the provided Topic collection, finds the attribute with the
        ///   associated name, and creates a Topic Pointer that points to that attribute.
        /// </summary>
        /// <param name="contentType">The <see cref="ContentType"/>for the attribute topic.</param>
        /// <param name="attributes">The collection of attributes for the attribute topic.</param>
        /// <param name="key">The <see cref="Topic.Key"/> for the attribute to be referenced.</param>
        /// <returns>The topic object for the referencing topic.</returns>
        Topic SetAttributeReference(Topic contentType, Topic attributes, string key)
        {
            /*------------------------------------------------------------------------------------------------------------------------
              | Validate input
              \-----------------------------------------------------------------------------------------------------------------------*/
              Contract.Requires<ArgumentNullException>(attributes != null, "The attributes topic must be specified.");
              Contract.Requires<ArgumentNullException>(contentType != null, "The contentTYpe topic must be specified.");
              Contract.Requires<ArgumentNullException>(String.IsNullOrWhiteSpace(key), "The key must be specified.");
              Topic.ValidateKey(key);

              if (!attributes.Contains(key)) {
            throw new Exception("The attribute with the key '" + key + "' does not exist in the '" + attributes.Key + "' Topic.");
            }

              /*------------------------------------------------------------------------------------------------------------------------
              | Establish the derived and target attributes
              \-----------------------------------------------------------------------------------------------------------------------*/
              Topic attribute = attributes[key];
              Topic attributeReference = SetTopic(contentType, attribute.Key, attribute.Attributes.Get("ContentType"));

              /*------------------------------------------------------------------------------------------------------------------------
              | Set the attribute reference/derivation
              \-----------------------------------------------------------------------------------------------------------------------*/
              attributeReference.DerivedTopic = attribute;

              /*------------------------------------------------------------------------------------------------------------------------
              | Return referencing attribute
              \-----------------------------------------------------------------------------------------------------------------------*/
              return attributeReference;
        }
开发者ID:Ignia,项目名称:Topics-Library,代码行数:41,代码来源:TopicsSetup.cs


注:本文中的Topic.Contains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。