本文整理汇总了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];
}
示例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;
}