本文整理汇总了C#中System.Xaml.XamlReader类的典型用法代码示例。如果您正苦于以下问题:C# XamlReader类的具体用法?C# XamlReader怎么用?C# XamlReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XamlReader类属于System.Xaml命名空间,在下文中一共展示了XamlReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: XamlBackgroundReader
public XamlBackgroundReader (XamlReader wrappedReader)
{
if (wrappedReader == null)
throw new ArgumentNullException ("wrappedReader");
r = wrappedReader;
q = new XamlNodeQueue (r.SchemaContext) { LineInfoProvider = r as IXamlLineInfo };
}
示例2: DynamicActivityXamlReader
public DynamicActivityXamlReader(bool isBuilder, XamlReader innerReader, XamlSchemaContext schemaContext)
: base()
{
this.isBuilder = isBuilder;
this.innerReader = innerReader;
this.schemaContext = schemaContext ?? innerReader.SchemaContext;
this.xamlTypeXamlType = this.schemaContext.GetXamlType(typeof(XamlType));
this.typeXamlType = this.schemaContext.GetXamlType(typeof(Type));
this.baseActivityXamlType = this.schemaContext.GetXamlType(typeof(Activity));
this.activityPropertyXamlType = this.schemaContext.GetXamlType(typeof(DynamicActivityProperty));
this.activityPropertyType = this.activityPropertyXamlType.GetMember("Type");
this.activityPropertyName = this.activityPropertyXamlType.GetMember("Name");
this.activityPropertyValue = this.activityPropertyXamlType.GetMember("Value");
this.activityPropertyAttributes = this.activityPropertyXamlType.GetMember("Attributes");
this.namespaceTable = new NamespaceTable();
this.frontLoadedDirectives = true;
// we pump items through this node-list when rewriting
this.nodeQueue = new XamlNodeQueue(this.schemaContext);
this.nodeReader = this.nodeQueue.Reader;
IXamlLineInfo lineInfo = innerReader as IXamlLineInfo;
if (lineInfo != null && lineInfo.HasLineInfo)
{
this.innerReaderLineInfo = lineInfo;
this.nodeReaderLineInfo = (IXamlLineInfo)nodeQueue.Reader;
this.hasLineInfo = true;
}
}
示例3: LoadAttributeData
// We get here when we are inside x:ClassAttributes or x:Property.Attributes. We expect the first element to be the Attribute SO.
internal static AttributeData LoadAttributeData(XamlReader reader, NamespaceTable namespaceTable, string rootNamespace)
{
AttributeData attributeData = null;
reader.Read();
if (reader.NodeType == XamlNodeType.StartObject)
{
attributeData = new AttributeData { Type = reader.Type };
bool readNext = false;
while (readNext || reader.Read())
{
namespaceTable.ManageNamespace(reader);
readNext = false;
if (reader.NodeType == XamlNodeType.StartMember)
{
if (reader.Member == XamlLanguage.Arguments)
{
foreach (AttributeParameterData parameterData in ReadParameters(reader.ReadSubtree(), namespaceTable, rootNamespace))
{
attributeData.Parameters.Add(parameterData);
}
readNext = true;
}
else if (!reader.Member.IsDirective)
{
KeyValuePair<string, AttributeParameterData> propertyInfo = ReadAttributeProperty(reader.ReadSubtree(), namespaceTable, rootNamespace);
attributeData.Properties.Add(propertyInfo.Key, propertyInfo.Value);
readNext = true;
}
}
}
}
return attributeData;
}
示例4: ManageNamespace
public void ManageNamespace(XamlReader reader)
{
switch (reader.NodeType)
{
case XamlNodeType.NamespaceDeclaration:
tempNamespaceList.Add(reader.Namespace.Prefix,
new NamespaceDeclaration(
XamlBuildTaskServices.UpdateClrNamespaceUriWithLocalAssembly(reader.Namespace.Namespace, this.localAssemblyName),
reader.Namespace.Prefix));
break;
case XamlNodeType.StartObject:
case XamlNodeType.StartMember:
case XamlNodeType.GetObject:
if (tempNamespaceList != null)
{
namespaceStack.Push(tempNamespaceList);
tempNamespaceList = new Dictionary<string, NamespaceDeclaration>();
}
break;
case XamlNodeType.EndMember:
case XamlNodeType.EndObject:
namespaceStack.Pop();
break;
default:
break;
}
}
示例5: WriteNode
public void WriteNode (XamlReader reader)
{
if (reader == null)
throw new ArgumentNullException ("reader");
switch (reader.NodeType) {
case XamlNodeType.StartObject:
WriteStartObject (reader.Type);
break;
case XamlNodeType.GetObject:
WriteGetObject ();
break;
case XamlNodeType.EndObject:
WriteEndObject ();
break;
case XamlNodeType.StartMember:
WriteStartMember (reader.Member);
break;
case XamlNodeType.EndMember:
WriteEndMember ();
break;
case XamlNodeType.Value:
WriteValue (reader.Value);
break;
case XamlNodeType.NamespaceDeclaration:
WriteNamespace (reader.Namespace);
break;
default:
throw NotImplemented (); // documented behavior
}
}
示例6: Main
static void Main(string[] args)
{
Xaml.XamlReader reader = new Xaml.XamlReader();
Page page = (Page)reader.Load("Test.xaml");
Console.WriteLine(page.Title);
var stream = File.Open("Test.html", FileMode.Create, FileAccess.ReadWrite, FileShare.Read);
StreamWriter writer = new StreamWriter(stream);
page.Render(writer);
//writer.Flush();
//writer.Close();
Console.ReadLine();
//XmlWriterSettings setting = new XmlWriterSettings();
//setting.Encoding = new UTF8Encoding(false);
//XmlWriter xmlWriter = XmlWriter.Create(writer, setting);
//xmlWriter.WriteStartDocument();
//xmlWriter.WriteStartElement("html");
//xmlWriter.WriteStartElement("span");
//xmlWriter.WriteString("test");
//xmlWriter.WriteEndElement();
//xmlWriter.WriteEndElement();
//xmlWriter.WriteEndDocument();
//xmlWriter.Flush();
//xmlWriter.Close();
//Console.ReadLine();
}
示例7: DynamicActivityXamlReader
public DynamicActivityXamlReader(bool isBuilder, XamlReader innerReader, XamlSchemaContext schemaContext)
{
this.isBuilder = isBuilder;
this.innerReader = innerReader;
this.schemaContext = schemaContext ?? innerReader.SchemaContext;
this.xamlTypeXamlType = this.schemaContext.GetXamlType(typeof(XamlType));
this.typeXamlType = this.schemaContext.GetXamlType(typeof(System.Type));
this.baseActivityXamlType = this.schemaContext.GetXamlType(typeof(Activity));
this.activityPropertyXamlType = this.schemaContext.GetXamlType(typeof(DynamicActivityProperty));
this.activityPropertyType = this.activityPropertyXamlType.GetMember("Type");
this.activityPropertyName = this.activityPropertyXamlType.GetMember("Name");
this.activityPropertyValue = this.activityPropertyXamlType.GetMember("Value");
this.activityPropertyAttributes = this.activityPropertyXamlType.GetMember("Attributes");
this.namespaceTable = new NamespaceTable();
this.frontLoadedDirectives = true;
this.nodeQueue = new XamlNodeQueue(this.schemaContext);
this.nodeReader = this.nodeQueue.Reader;
IXamlLineInfo info = innerReader as IXamlLineInfo;
if ((info != null) && info.HasLineInfo)
{
this.innerReaderLineInfo = info;
this.nodeReaderLineInfo = (IXamlLineInfo) this.nodeQueue.Reader;
this.hasLineInfo = true;
}
}
示例8: ManageNamespace
public void ManageNamespace(XamlReader reader)
{
switch (reader.NodeType)
{
case XamlNodeType.StartObject:
case XamlNodeType.GetObject:
case XamlNodeType.StartMember:
this.EnterScope();
return;
case XamlNodeType.EndObject:
case XamlNodeType.EndMember:
this.ExitScope();
break;
case XamlNodeType.Value:
break;
case XamlNodeType.NamespaceDeclaration:
this.AddNamespace(reader.Namespace);
return;
default:
return;
}
}
示例9: Load
public override object Load(XamlReader xamlReader, IServiceProvider serviceProvider)
{
IXamlObjectWriterFactory settings = serviceProvider.GetService(typeof(IXamlObjectWriterFactory)) as IXamlObjectWriterFactory;
System.Windows.Markup.IProvideValueTarget provideValueService = serviceProvider.GetService(typeof(System.Windows.Markup.IProvideValueTarget)) as System.Windows.Markup.IProvideValueTarget;
Type propertyType = null;
// IProvideValueTarget.TargetProperty can return DP, Attached Property or MemberInfo for clr property
// In this case it should always be a regular clr property here.
PropertyInfo propertyInfo = provideValueService.TargetProperty as PropertyInfo;
if (propertyInfo != null)
{
propertyType = propertyInfo.PropertyType;
}
else
{
return null;
}
object instance = Activator.CreateInstance(
typeof(FuncFactory<>).MakeGenericType(propertyType.GetGenericArguments()),
settings,
xamlReader);
return Delegate.CreateDelegate(propertyType, instance, instance.GetType().GetMethod("Evaluate"));
}
示例10: ValidateXaml
public bool ValidateXaml(XamlReader xamlReader, bool failOnFirstError, string assemblyName, out IList<LogData> validationErrors)
{
if (xamlReader == null)
{
throw FxTrace.Exception.ArgumentNull("xamlReader");
}
validationErrors = null;
// We loop through the provided XAML using a XamlValidatingReader to ensure that:
// 1. XAML is valid.
// 2. All types referenced in XAML are validate-able. At this point, any types defined in the local
// assembly should be referenced, so this should be possible.
XamlValidatingReader reader = new XamlValidatingReader(xamlReader, this.localAssembly, rootNamespace, assemblyName);
reader.OnValidationError += new EventHandler<ValidationEventArgs>(reader_OnValidationError);
while (reader.Read())
{
if (this.eventArgs != null && failOnFirstError)
{
validationErrors = this.eventArgs;
return false;
}
}
validationErrors = this.eventArgs;
if (validationErrors != null && validationErrors.Count > 0)
{
return false;
}
return true;
}
示例11: Transform
// This method is a workaround for TFS bug #788190, since XamlReader.ReadSubtree() should (but doesn't) preserve IXamlLineInfo on the subreader
public static void Transform(XamlReader reader, XamlWriter writer, IXamlLineInfo readerLineInfo, bool closeWriter)
{
IXamlLineInfoConsumer consumer = writer as IXamlLineInfoConsumer;
SharedFx.Assert(consumer != null && consumer.ShouldProvideLineInfo, "Should only call this function to write into a XamlNodeQueue.Writer, which is always IXamlLineInfoConsumer");
bool shouldPassLineNumberInfo = false;
if (readerLineInfo != null)
{
shouldPassLineNumberInfo = true;
}
while (reader.Read())
{
if (shouldPassLineNumberInfo)
{
consumer.SetLineInfo(readerLineInfo.LineNumber, readerLineInfo.LinePosition);
}
writer.WriteNode(reader);
}
if (closeWriter)
{
writer.Close();
}
}
示例12: Initialize
private void Initialize(XamlReader wrappedReader, int bufferSize)
{
XamlNodeNextDelegate delegate4;
this._providerFullEvent = new EventWaitHandle(false, EventResetMode.AutoReset);
this._dataReceivedEvent = new EventWaitHandle(false, EventResetMode.AutoReset);
this._incoming = new XamlNode[bufferSize];
this._outgoing = new XamlNode[bufferSize];
this._wrappedReader = wrappedReader;
this._wrappedReaderHasLineInfo = ((IXamlLineInfo) this._wrappedReader).HasLineInfo;
XamlNodeAddDelegate add = new XamlNodeAddDelegate(this.Add);
XamlLineInfoAddDelegate addlineInfoDelegate = null;
if (this._wrappedReaderHasLineInfo)
{
addlineInfoDelegate = new XamlLineInfoAddDelegate(this.AddLineInfo);
}
this._writer = new WriterDelegate(add, addlineInfoDelegate, this._wrappedReader.SchemaContext);
if (this._wrappedReaderHasLineInfo)
{
delegate4 = new XamlNodeNextDelegate(this.Next_ProcessLineInfo);
}
else
{
delegate4 = new XamlNodeNextDelegate(this.Next);
}
this._internalReader = new ReaderDelegate(this._wrappedReader.SchemaContext, delegate4, this._wrappedReaderHasLineInfo);
this._currentNode = new XamlNode(XamlNode.InternalNodeType.StartOfStream);
}
示例13: XamlWrappingReader
internal XamlWrappingReader(XamlReader underlyingReader)
{
if (underlyingReader == null)
{
throw FxTrace.Exception.AsError(new ArgumentNullException("underlyingReader"));
}
_underlyingReader = underlyingReader;
}
示例14: Load
public static XamlDomNode Load(XamlReader xxr)
{
var ixli = xxr as IXamlLineInfo;
var dw = new XamlDomWriter(xxr.SchemaContext);
XamlServices.Transform(xxr, dw);
return dw.RootNode;
}
示例15: CreateReader
public static XamlReader CreateReader(XamlReader innerReader)
{
if (innerReader == null)
{
throw FxTrace.Exception.ArgumentNull("innerReader");
}
return new DynamicActivityXamlReader(innerReader);
}