本文整理汇总了C#中System.Xaml.XamlObjectReader.ReadSubtree方法的典型用法代码示例。如果您正苦于以下问题:C# XamlObjectReader.ReadSubtree方法的具体用法?C# XamlObjectReader.ReadSubtree怎么用?C# XamlObjectReader.ReadSubtree使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xaml.XamlObjectReader
的用法示例。
在下文中一共展示了XamlObjectReader.ReadSubtree方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadSubtree3
public void ReadSubtree3 ()
{
var xr = new XamlObjectReader (5);
xr.Read ();
xr.Read ();
var sr = xr.ReadSubtree ();
Assert.AreEqual (XamlNodeType.None, sr.NodeType, "#1-2");
Assert.AreEqual (XamlNodeType.StartObject, xr.NodeType, "#1-3");
Assert.IsTrue (sr.Read (), "#2");
Assert.AreEqual (XamlNodeType.StartObject, sr.NodeType, "#2-2");
Assert.AreEqual (XamlNodeType.StartObject, xr.NodeType, "#2-3");
Assert.IsTrue (sr.Read (), "#3");
Assert.AreEqual (XamlNodeType.StartMember, sr.NodeType, "#3-2");
Assert.AreEqual (XamlNodeType.StartMember, xr.NodeType, "#3-3");
Assert.IsTrue (sr.Read (), "#4");
Assert.AreEqual (XamlNodeType.Value, sr.NodeType, "#4-2");
Assert.AreEqual (XamlNodeType.Value, xr.NodeType, "#4-3");
Assert.IsTrue (sr.Read (), "#5");
Assert.AreEqual (XamlNodeType.EndMember, sr.NodeType, "#5-2");
Assert.AreEqual (XamlNodeType.EndMember, xr.NodeType, "#5-3");
Assert.IsTrue (sr.Read (), "#6");
Assert.AreEqual (XamlNodeType.EndObject, sr.NodeType, "#6-2");
Assert.AreEqual (XamlNodeType.EndObject, xr.NodeType, "#6-3");
Assert.IsFalse (sr.Read (), "#7");
Assert.AreEqual (XamlNodeType.None, xr.NodeType, "#7-2");
}
示例2: ReadSubtree1
public void ReadSubtree1 ()
{
var xr = new XamlObjectReader (5);
var sr = xr.ReadSubtree ();
Assert.AreEqual (XamlNodeType.None, sr.NodeType, "#1-2");
Assert.AreEqual (XamlNodeType.None, xr.NodeType, "#1-3");
Assert.IsTrue (sr.Read (), "#2");
Assert.AreEqual (XamlNodeType.None, sr.NodeType, "#2-2");
Assert.AreEqual (XamlNodeType.None, xr.NodeType, "#2-3");
Assert.IsFalse (sr.Read (), "#3");
Assert.AreEqual (XamlNodeType.NamespaceDeclaration, xr.NodeType, "#3-2");
}
示例3: ConvertAttachedPropertiesToViewState
// This method collects view state attached properties and generates a Xaml node stream
// with all view state information appearing within the ViewStateManager node.
// It is called when workflow definition is being serialized to string.
// inputReader - Nodestream with view state information as attached properties on the activity nodes.
// The reader is positioned at the begining of the workflow definition.
// idManager - This component issues running sequence numbers for IdRef.
// Result - Node stream positioned at the begining of the workflow definition with a
// ViewStateManager node containing all view state information.
// Implementation logic:
// 1. Scan the input nodestream Objects for attached properties that need to be converted (VirtualizedContainerService.HintSize and WorkflowViewStateService.ViewState).
// 2. If the Object had a IdRef value then use it otherwise generate a new value.
// 3. Store idRef value and corresponding viewstate related attached property nodes (from step 1)
// in the viewStateInfo dictionary.
// 4. Use the viewStateInfo dictionary to generate ViewStateManager node which is then inserted
// into the end of output nodestream.
public static XamlReader ConvertAttachedPropertiesToViewState(XamlObjectReader inputReader, ViewStateIdManager idManager)
{
// Stack to track StartObject/GetObject and EndObject nodes.
Stack<Frame> stack = new Stack<Frame>();
XamlMember viewStateManager = new XamlMember(ViewStateManager, GetViewStateManager, SetViewStateManager, inputReader.SchemaContext);
XamlMember idRefMember = new XamlMember(IdRef, GetIdRef, SetIdRef, inputReader.SchemaContext);
// Xaml member corresponding to x:Class property of the workflow definition. Used to find x:Class value in the node stream.
XamlMember activityBuilderName = new XamlMember(typeof(ActivityBuilder).GetProperty("Name"), inputReader.SchemaContext);
string activityBuilderTypeName = typeof(ActivityBuilder).Name;
// Dictionary to keep track of IdRefs and corresponding viewstate related
// attached property nodes.
Dictionary<string, XamlNodeList> viewStateInfo = new Dictionary<string, XamlNodeList>();
// Output node list
XamlNodeList workflowDefinition = new XamlNodeList(inputReader.SchemaContext);
using (XamlWriter workflowDefinitionWriter = workflowDefinition.Writer)
{
bool design2010NamespaceFound = false;
bool inIdRefMember = false;
bool inxClassMember = false;
bool skipWritingWorkflowDefinition = false;
bool skipReadingWorkflowDefinition = false;
string xClassName = null;
while (skipReadingWorkflowDefinition || inputReader.Read())
{
skipWritingWorkflowDefinition = false;
skipReadingWorkflowDefinition = false;
switch (inputReader.NodeType)
{
case XamlNodeType.NamespaceDeclaration:
if (inputReader.Namespace.Namespace.Equals(NameSpaces.Design2010, StringComparison.Ordinal))
{
design2010NamespaceFound = true;
}
break;
case XamlNodeType.StartObject:
// Save the Xaml type and clr object on the stack frame. These are used later to generate
// IdRef values and attaching the same to the clr object.
stack.Push(new Frame() { Type = inputReader.Type, InstanceObject = inputReader.Instance });
// If the design2010 namespace was not found add the namespace node
// before the start object is written out.
if (!design2010NamespaceFound)
{
workflowDefinitionWriter.WriteNamespace(new NamespaceDeclaration(NameSpaces.Design2010, NameSpaces.Design2010Prefix));
design2010NamespaceFound = true;
}
break;
case XamlNodeType.GetObject:
// Push an empty frame to balance the Pop operation when the EndObject node
// is encountered.
stack.Push(new Frame() { Type = null });
break;
case XamlNodeType.StartMember:
// Track when we enter IdRef member so that we can save its value.
if (inputReader.Member.Equals(idRefMember))
{
inIdRefMember = true;
}
// Track when we enter x:Class member so that we can save its value.
else if (inputReader.Member.Equals(activityBuilderName))
{
inxClassMember = true;
}
// Start of VirtualizedContainerService.HintSize or WorkflowViewStateService.ViewState property.
else if (IsAttachablePropertyForConvert(inputReader))
{
// The top of stack here corresponds to the activity on which
// the above properties are attached.
if (stack.Peek().AttachedPropertyNodes == null)
{
stack.Peek().AttachedPropertyNodes = new XamlNodeList(inputReader.SchemaContext);
}
// Write the attached property's xaml nodes into the stack.
XamlReader subTreeReader = inputReader.ReadSubtree();
XamlWriter attachedPropertyWriter = stack.Peek().AttachedPropertyNodes.Writer;
//.........这里部分代码省略.........
示例4: RemoveIdRefs
// This method removes IdRef nodes from the nodestream. This method would be called
// when a 4.5 workflow definition is retargeted to 4.0.
public static XamlReader RemoveIdRefs(XamlObjectReader inputReader)
{
XamlMember idRefMember = new XamlMember(IdRef, GetIdRef, SetIdRef, inputReader.SchemaContext);
XamlNodeList outputNodeList = new XamlNodeList(inputReader.SchemaContext);
using (XamlWriter outputWriter = outputNodeList.Writer)
{
while (inputReader.Read())
{
if (inputReader.NodeType == XamlNodeType.StartMember && inputReader.Member.Equals(idRefMember))
{
// Exhaust the idRefMember sub-tree.
XamlReader idRefReader = inputReader.ReadSubtree();
while (idRefReader.Read());
}
outputWriter.WriteNode(inputReader);
}
}
return outputNodeList.GetReader();
}