本文整理汇总了C#中ISiteMapNode.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# ISiteMapNode.CopyTo方法的具体用法?C# ISiteMapNode.CopyTo怎么用?C# ISiteMapNode.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISiteMapNode
的用法示例。
在下文中一共展示了ISiteMapNode.CopyTo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildDynamicNodesFor
/// <summary>
/// Adds the dynamic nodes for node.
/// </summary>
/// <param name="node">The node.</param>
/// <param name="parentNode">The parent node.</param>
public IEnumerable<ISiteMapNode> BuildDynamicNodesFor(ISiteMap siteMap, ISiteMapNode node, ISiteMapNode parentNode)
{
// List of dynamic nodes that have been created
var createdDynamicNodes = new List<ISiteMapNode>();
if (!node.HasDynamicNodeProvider)
{
return createdDynamicNodes;
}
// Build dynamic nodes
foreach (var dynamicNode in node.GetDynamicNodeCollection())
{
string key = dynamicNode.Key;
if (string.IsNullOrEmpty(key))
{
key = nodeKeyGenerator.GenerateKey(
parentNode == null ? "" : parentNode.Key,
Guid.NewGuid().ToString(),
node.Url,
node.Title,
node.Area,
node.Controller,
node.Action,
node.HttpMethod,
node.Clickable);
}
// Create a new node
var newNode = siteMapNodeFactory.CreateDynamic(siteMap, key, node.ResourceKey);
// Copy the values from the original node to the new one
node.CopyTo(newNode);
// Copy any values that were set in the dynamic node and overwrite the new node.
dynamicNode.SafeCopyTo(newNode);
// If the dynamic node has a parent key set, use that as the parent. Otherwise use the parentNode.
if (!string.IsNullOrEmpty(dynamicNode.ParentKey))
{
var parent = siteMap.FindSiteMapNodeFromKey(dynamicNode.ParentKey);
if (parent != null)
{
siteMap.AddNode(newNode, parent);
createdDynamicNodes.Add(newNode);
}
}
else
{
siteMap.AddNode(newNode, parentNode);
createdDynamicNodes.Add(newNode);
}
}
// Done!
return createdDynamicNodes;
}
示例2: BuildDynamicNodes
/// <summary>
/// Gets the dynamic nodes for node.
/// </summary>
/// <param name="siteMap">The site map.</param>
/// <param name="node">The node.</param>
/// <param name="parentKey">The key of the parent node.</param>
public virtual IEnumerable<ISiteMapNodeToParentRelation> BuildDynamicNodes(ISiteMapNode node, string defaultParentKey)
{
var result = new List<ISiteMapNodeToParentRelation>();
if (!node.HasDynamicNodeProvider)
{
return result;
}
// Build dynamic nodes
foreach (var dynamicNode in node.GetDynamicNodeCollection())
{
// If the dynamic node has a parent key set, use that as the parent. Otherwise use the parentNode.
var parentKey = !String.IsNullOrEmpty(dynamicNode.ParentKey) ? dynamicNode.ParentKey : defaultParentKey;
var key = dynamicNode.Key;
if (string.IsNullOrEmpty(key))
{
key = this.siteMapNodeCreator.GenerateSiteMapNodeKey(
parentKey,
Guid.NewGuid().ToString(),
node.Url,
node.Title,
node.Area,
node.Controller,
node.Action,
node.HttpMethod,
node.Clickable);
}
// Create a new node
var nodeParentMap = this.siteMapNodeCreator.CreateDynamicSiteMapNode(key, parentKey, node.DynamicNodeProvider, node.ResourceKey);
var newNode = nodeParentMap.Node;
// Copy the values from the original node to the new one
node.CopyTo(newNode);
// Copy any values that were set in the dynamic node and overwrite the new node.
dynamicNode.SafeCopyTo(newNode);
result.Add(nodeParentMap);
}
return result;
}
示例3: BuildDynamicNodes
/// <summary>
/// Gets the dynamic nodes for node.
/// </summary>
/// <param name="node">The SiteMap node.</param>
/// <param name="defaultParentKey">The key of the parent node.</param>
public virtual IEnumerable<ISiteMapNodeToParentRelation> BuildDynamicNodes(ISiteMapNode node, string defaultParentKey)
{
var result = new List<ISiteMapNodeToParentRelation>();
if (!node.HasDynamicNodeProvider)
{
return result;
}
// Get the dynamic nodes using the request's culture context.
// NOTE: In version 5, we need to use the invariant context and pass a reference to it
// into the dynamic node provider. This would be a breaking change, so for now we are
// swapping the context back to the state of the current request. This way, the end user
// still can opt to change to invariant culture, but in the reverse situation there would
// be no way to identify the culture of the current request without a reference to the
// cultureContext object.
IEnumerable<DynamicNode> dynamicNodes;
using (var originalCultureContext = this.cultureContextFactory.Create(this.cultureContext.OriginalCulture, this.cultureContext.OriginalUICulture))
{
dynamicNodes = node.GetDynamicNodeCollection();
}
// Build dynamic nodes
foreach (var dynamicNode in dynamicNodes)
{
// If the dynamic node has a parent key set, use that as the parent. Otherwise use the parentNode.
var parentKey = !string.IsNullOrEmpty(dynamicNode.ParentKey) ? dynamicNode.ParentKey : defaultParentKey;
var key = dynamicNode.Key;
if (string.IsNullOrEmpty(key))
{
key = this.siteMapNodeCreator.GenerateSiteMapNodeKey(
parentKey,
Guid.NewGuid().ToString(),
node.Url,
node.Title,
node.Area,
node.Controller,
node.Action,
node.HttpMethod,
node.Clickable);
}
// Create a new node
var nodeParentMap = this.siteMapNodeCreator.CreateDynamicSiteMapNode(key, parentKey, node.DynamicNodeProvider, node.ResourceKey);
var newNode = nodeParentMap.Node;
// Copy the values from the original node to the new one
node.CopyTo(newNode);
// Copy any values that were set in the dynamic node and overwrite the new node.
dynamicNode.SafeCopyTo(newNode);
result.Add(nodeParentMap);
}
return result;
}