本文整理汇总了C#中SyntaxWriter.WriteString方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxWriter.WriteString方法的具体用法?C# SyntaxWriter.WriteString怎么用?C# SyntaxWriter.WriteString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxWriter
的用法示例。
在下文中一共展示了SyntaxWriter.WriteString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteClassSyntax
/// <inheritdoc />
public override void WriteClassSyntax(XPathNavigator reflection, SyntaxWriter writer)
{
if(IsUnsupportedGeneric(reflection, writer))
return;
string name = (string)reflection.Evaluate(apiNameExpression);
bool isAbstract = (bool)reflection.Evaluate(apiIsAbstractTypeExpression);
bool isSealed = (bool)reflection.Evaluate(apiIsSealedTypeExpression);
WriteAccessModifier(reflection, writer);
if(isSealed)
{
writer.WriteKeyword("final");
writer.WriteString(" ");
}
else if(isAbstract)
{
writer.WriteKeyword("abstract");
writer.WriteString(" ");
}
writer.WriteKeyword("class");
writer.WriteString(" ");
writer.WriteString(name);
WriteBaseClass(reflection, writer);
WriteInterfaceList(reflection, writer);
}
示例2: WriteNamespaceSyntax
// namespace: done
/// <inheritdoc />
public override void WriteNamespaceSyntax(XPathNavigator reflection, SyntaxWriter writer)
{
string name = reflection.Evaluate(apiNameExpression).ToString();
writer.WriteKeyword("namespace");
writer.WriteString(" ");
writer.WriteIdentifier(name);
}
示例3: WriteClassSyntax
/// <inheritdoc />
public override void WriteClassSyntax(XPathNavigator reflection, SyntaxWriter writer)
{
string name = reflection.Evaluate(apiNameExpression).ToString();
bool isAbstract = (bool)reflection.Evaluate(apiIsAbstractTypeExpression);
bool isSealed = (bool)reflection.Evaluate(apiIsSealedTypeExpression);
bool isSerializable = (bool)reflection.Evaluate(apiIsSerializableTypeExpression);
if(isSerializable)
WriteAttribute("T:System.SerializableAttribute", true, writer);
WriteAttributes(reflection, writer);
WriteVisibility(reflection, writer);
writer.WriteString(" ");
if(isAbstract)
{
if(isSealed)
{
writer.WriteKeyword("static");
}
else
{
writer.WriteKeyword("abstract");
}
writer.WriteString(" ");
}
else
{
if(isSealed)
{
writer.WriteKeyword("sealed");
writer.WriteString(" ");
}
}
writer.WriteKeyword("class");
writer.WriteString(" ");
writer.WriteIdentifier(name);
WriteGenericTemplates(reflection, writer, false);
WriteBaseClassAndImplementedInterfaces(reflection, writer);
WriteGenericTemplateConstraints(reflection, writer);
}
示例4: WriteDelegateSyntax
/// <inheritdoc />
public override void WriteDelegateSyntax(XPathNavigator reflection, SyntaxWriter writer)
{
// !EFW - Added unsafe check
if(IsUnsupportedUnsafe(reflection, writer))
return;
string name = (string)reflection.Evaluate(apiNameExpression);
bool isSerializable = (bool)reflection.Evaluate(apiIsSerializableTypeExpression);
if(isSerializable)
WriteAttribute("T:System.SerializableAttribute", true, writer);
WriteAttributes(reflection, writer);
writer.WriteKeyword("type");
writer.WriteString(" ");
writer.WriteIdentifier(name);
writer.WriteString(" = ");
writer.WriteLine();
writer.WriteString(" ");
writer.WriteKeyword("delegate");
writer.WriteString(" ");
writer.WriteKeyword("of");
writer.WriteString(" ");
WriteParameters(reflection, writer);
writer.WriteKeyword("->");
writer.WriteString(" ");
WriteReturnValue(reflection, writer);
}
示例5: WriteAttributes
// !EFW - Added indent parameter for property getter/setter attributes. Added parameterAttributes to
// suppress line feeds for method parameter attributes.
private void WriteAttributes(XPathNavigator reflection, SyntaxWriter writer, string indent = null,
bool parameterAttributes = false)
{
// Handle interop attributes first as they are output in metadata
if(!parameterAttributes)
WriteInteropAttributes(reflection, writer, indent);
// Add the standard attributes
XPathNodeIterator attributes = (XPathNodeIterator)reflection.Evaluate(apiAttributesExpression);
foreach(XPathNavigator attribute in attributes)
{
XPathNavigator type = attribute.SelectSingleNode(attributeTypeExpression);
// !EFW - Ignore FixedBufferAttribute and ParamArrayAttribute
if(type.GetAttribute("api", String.Empty) == "T:System.Runtime.CompilerServices.FixedBufferAttribute" ||
type.GetAttribute("api", String.Empty) == "T:System.ParamArrayAttribute")
continue;
writer.WriteString("[<");
WriteTypeReference(type, writer);
XPathNodeIterator arguments = (XPathNodeIterator)attribute.Select(attributeArgumentsExpression);
XPathNodeIterator assignments = (XPathNodeIterator)attribute.Select(attributeAssignmentsExpression);
if((arguments.Count > 0) || (assignments.Count > 0))
{
writer.WriteString("(");
while(arguments.MoveNext())
{
XPathNavigator argument = arguments.Current;
if(arguments.CurrentPosition > 1)
WriteWithLineBreakIfNeeded(writer, ", ", indent + "\t");
WriteValue(argument, writer);
}
if(arguments.Count > 0 && assignments.Count > 0)
writer.WriteString(", ");
while(assignments.MoveNext())
{
XPathNavigator assignment = assignments.Current;
if(assignments.CurrentPosition > 1)
WriteWithLineBreakIfNeeded(writer, ", ", indent + "\t");
writer.WriteString((string)assignment.Evaluate(assignmentNameExpression));
writer.WriteString(" = ");
WriteValue(assignment, writer);
}
writer.WriteString(")");
}
writer.WriteString(">]");
if(!parameterAttributes)
writer.WriteLine();
}
if(parameterAttributes && attributes.Count != 0)
writer.WriteString(" ");
}
示例6: WriteMemberKeyword
// Write member | abstract | override
private static void WriteMemberKeyword(XPathNavigator reflection, SyntaxWriter writer)
{
bool isOverride = (bool)reflection.Evaluate(apiIsOverrideExpression);
bool isAbstract = (bool)reflection.Evaluate(apiIsAbstractProcedureExpression);
if(isOverride)
writer.WriteKeyword("override");
else
if(isAbstract)
writer.WriteKeyword("abstract");
else
writer.WriteKeyword("member");
writer.WriteString(" ");
}
示例7: WriteFieldSyntax
/// <inheritdoc />
public override void WriteFieldSyntax(XPathNavigator reflection, SyntaxWriter writer)
{
// !EFW - Added unsafe check
if(IsUnsupportedUnsafe(reflection, writer))
return;
string name = (string)reflection.Evaluate(apiNameExpression);
bool isStatic = (bool)reflection.Evaluate(apiIsStaticExpression);
bool isInitOnly = (bool)reflection.Evaluate(apiIsInitOnlyFieldExpression);
bool isSerialized = (bool)reflection.Evaluate(apiIsSerializedFieldExpression);
if(!isSerialized)
WriteAttribute("T:System.NonSerializedAttribute", true, writer);
WriteAttributes(reflection, writer);
if(isStatic)
{
writer.WriteKeyword("static");
writer.WriteString(" ");
}
writer.WriteKeyword("val");
writer.WriteString(" ");
if(!isInitOnly)
{
writer.WriteKeyword("mutable");
writer.WriteString(" ");
}
WriteVisibility(reflection, writer);
writer.WriteIdentifier(name);
writer.WriteString(": ");
WriteReturnValue(reflection, writer);
}
示例8: WritePropertySyntax
/// <inheritdoc />
public override void WritePropertySyntax(XPathNavigator reflection, SyntaxWriter writer)
{
// !EFW - Added unsafe check
if(IsUnsupportedUnsafe(reflection, writer))
return;
string name = (string)reflection.Evaluate(apiNameExpression);
bool isGettable = (bool)reflection.Evaluate(apiIsReadPropertyExpression);
bool isSettable = (bool)reflection.Evaluate(apiIsWritePropertyExpression);
bool isStatic = (bool)reflection.Evaluate(apiIsStaticExpression);
bool isVirtual = (bool)reflection.Evaluate(apiIsVirtualExpression) && !(bool)reflection.Evaluate(apiIsAbstractProcedureExpression);
int iterations = isVirtual ? 2 : 1;
for(int i = 0; i < iterations; i++)
{
WriteAttributes(reflection, writer);
WriteVisibility(reflection, writer);
if(isStatic)
{
writer.WriteKeyword("static");
writer.WriteString(" ");
}
if(isVirtual)
if(i == 0)
{
writer.WriteKeyword("abstract");
writer.WriteString(" ");
}
else
{
writer.WriteKeyword("override");
writer.WriteString(" ");
}
else
{
WriteMemberKeyword(reflection, writer);
}
writer.WriteIdentifier(name);
writer.WriteString(" : ");
WriteReturnValue(reflection, writer);
writer.WriteString(" ");
writer.WriteKeyword("with");
writer.WriteString(" ");
if(isGettable)
{
// !EFW - Added support for getter/setter attributes
XPathNavigator getter = reflection.SelectSingleNode(apiGetterExpression);
if(getter != null && getter.HasChildren)
{
writer.WriteLine();
writer.WriteString("\t");
this.WriteAttributes(getter, writer, "\t");
writer.WriteString("\t");
}
string getVisibility = (string)reflection.Evaluate(apiGetVisibilityExpression);
if(!String.IsNullOrEmpty(getVisibility))
{
WriteVisibility(getVisibility, writer);
}
writer.WriteKeyword("get");
}
if(isSettable)
{
if(isGettable)
writer.WriteString(", ");
// !EFW - Added support for getter/setter attributes
XPathNavigator setter = reflection.SelectSingleNode(apiSetterExpression);
if(setter != null && setter.HasChildren)
{
writer.WriteLine();
writer.WriteString("\t");
this.WriteAttributes(setter, writer, "\t");
writer.WriteString("\t");
}
string setVisibility = (string)reflection.Evaluate(apiSetVisibilityExpression);
if(!String.IsNullOrEmpty(setVisibility))
{
WriteVisibility(setVisibility, writer);
}
writer.WriteKeyword("set");
}
if(i == 0)
//.........这里部分代码省略.........
示例9: WriteClassSyntax
/// <inheritdoc />
public override void WriteClassSyntax(XPathNavigator reflection, SyntaxWriter writer)
{
string name = (string)reflection.Evaluate(apiNameExpression);
bool isAbstract = (bool)reflection.Evaluate(apiIsAbstractTypeExpression);
bool isSealed = (bool)reflection.Evaluate(apiIsSealedTypeExpression);
bool isSerializable = (bool)reflection.Evaluate(apiIsSerializableTypeExpression);
if(isSerializable)
WriteAttribute("T:System.SerializableAttribute", writer);
WriteAttributes(reflection, writer);
WriteVisibility(reflection, writer);
writer.WriteString(" ");
if(isAbstract)
{
if(isSealed)
{
// static -- VB doesn't really handle this case
writer.WriteKeyword("NotInheritable");
writer.WriteString(" ");
}
else
{
writer.WriteKeyword("MustInherit");
writer.WriteString(" ");
}
}
else if(isSealed)
{
writer.WriteKeyword("NotInheritable");
writer.WriteString(" ");
}
writer.WriteKeyword("Class");
writer.WriteString(" ");
writer.WriteIdentifier(name);
WriteGenericTemplates(reflection, writer);
WriteBaseClass(reflection, writer);
WriteImplementedInterfaces(reflection, writer);
}
示例10: WriteAttribute
private void WriteAttribute(string reference, bool newLine, SyntaxWriter writer)
{
writer.WriteString("<");
writer.WriteReferenceLink(reference);
writer.WriteString(">");
if(newLine)
{
if(includeLineContinuation)
writer.WriteString(" _");
writer.WriteLine();
}
}
示例11: WriteFieldSyntax
/// <inheritdoc />
public override void WriteFieldSyntax(XPathNavigator reflection, SyntaxWriter writer)
{
if(IsUnsupportedUnsafe(reflection, writer))
return;
string name = (string)reflection.Evaluate(apiNameExpression);
bool isStatic = (bool)reflection.Evaluate(apiIsStaticExpression);
bool isLiteral = (bool)reflection.Evaluate(apiIsLiteralFieldExpression);
bool isInitOnly = (bool)reflection.Evaluate(apiIsInitOnlyFieldExpression);
bool isSerialized = (bool)reflection.Evaluate(apiIsSerializedFieldExpression);
XPathNavigator type = reflection.SelectSingleNode(apiReturnTypeExpression);
if(!isSerialized)
WriteAttribute("T:System.NonSerializedAttribute", writer);
WriteAttributes(reflection, writer);
WriteVisibility(reflection, writer);
writer.WriteString(" ");
if(isStatic)
{
if(isLiteral)
{
writer.WriteKeyword("Const");
}
else
{
writer.WriteKeyword("Shared");
}
writer.WriteString(" ");
}
if(isInitOnly)
{
writer.WriteKeyword("ReadOnly");
writer.WriteString(" ");
}
writer.WriteIdentifier(name);
writer.WriteString(" ");
writer.WriteKeyword("As");
writer.WriteString(" ");
WriteTypeReference(type, writer);
}
示例12: WriteProcedureModifiers
private static void WriteProcedureModifiers(XPathNavigator reflection, SyntaxWriter writer)
{
// interface members don't get modified
string typeSubgroup = (string)reflection.Evaluate(apiContainingTypeSubgroupExpression);
if(typeSubgroup == "interface")
return;
bool isStatic = (bool)reflection.Evaluate(apiIsStaticExpression);
bool isVirtual = (bool)reflection.Evaluate(apiIsVirtualExpression);
bool isAbstract = (bool)reflection.Evaluate(apiIsAbstractProcedureExpression);
bool isFinal = (bool)reflection.Evaluate(apiIsFinalExpression);
bool isOverride = (bool)reflection.Evaluate(apiIsOverrideExpression);
WriteVisibility(reflection, writer);
writer.WriteString(" ");
if(isStatic)
{
writer.WriteKeyword("Shared");
writer.WriteString(" ");
}
else
{
if(isVirtual)
{
if(isAbstract)
{
writer.WriteKeyword("MustOverride");
writer.WriteString(" ");
}
else if(isOverride)
{
writer.WriteKeyword("Overrides");
writer.WriteString(" ");
if(isFinal)
{
writer.WriteKeyword("NotOverridable");
writer.WriteString(" ");
}
}
else
{
if(!isFinal)
{
writer.WriteKeyword("Overridable");
writer.WriteString(" ");
}
}
}
}
}
示例13: WriteExplicitImplementations
private void WriteExplicitImplementations(XPathNavigator reflection, SyntaxWriter writer)
{
bool isExplicit = (bool)reflection.Evaluate(apiIsExplicitImplementationExpression);
if(isExplicit)
{
if(writer.Position > MaxPosition)
{
writer.WriteLine();
writer.WriteString("\t");
}
else
writer.WriteString(" ");
writer.WriteKeyword("Implements");
writer.WriteString(" ");
XPathNodeIterator implementations = reflection.Select(apiImplementedMembersExpression);
while(implementations.MoveNext())
{
XPathNavigator implementation = implementations.Current;
XPathNavigator contract = implementation.SelectSingleNode(memberDeclaringTypeExpression);
//string id = implementation.GetAttribute("api", String.Empty);
if(implementations.CurrentPosition > 1)
writer.WriteString(", ");
WriteTypeReference(contract, writer);
writer.WriteString(".");
WriteMemberReference(implementation, writer);
//writer.WriteReferenceLink(id);
}
}
}
示例14: WriteEventSyntax
/// <inheritdoc />
public override void WriteEventSyntax(XPathNavigator reflection, SyntaxWriter writer)
{
// !EFW - Added unsafe check
if(IsUnsupportedUnsafe(reflection, writer))
return;
string name = (string)reflection.Evaluate(apiNameExpression);
XPathNavigator handler = reflection.SelectSingleNode(apiHandlerOfEventExpression);
WriteAttributes(reflection, writer);
WriteProcedureModifiers(reflection, writer);
writer.WriteString("Event");
writer.WriteString(" ");
writer.WriteIdentifier(name);
writer.WriteString(" ");
writer.WriteKeyword("As");
writer.WriteString(" ");
WriteTypeReference(handler, writer);
WriteExplicitImplementations(reflection, writer);
}
示例15: WritePropertySyntax
/// <inheritdoc />
public override void WritePropertySyntax(XPathNavigator reflection, SyntaxWriter writer)
{
if(IsUnsupportedUnsafe(reflection, writer))
return;
string name = (string)reflection.Evaluate(apiNameExpression);
bool hasGetter = (bool)reflection.Evaluate(apiIsReadPropertyExpression);
bool hasSetter = (bool)reflection.Evaluate(apiIsWritePropertyExpression);
bool isDefault = (bool)reflection.Evaluate(apiIsDefaultMemberExpression);
bool isExplicit = (bool)reflection.Evaluate(apiIsExplicitImplementationExpression);
XPathNavigator type = reflection.SelectSingleNode(apiReturnTypeExpression);
WriteAttributes(reflection, writer);
WriteProcedureModifiers(reflection, writer);
if(hasGetter && !hasSetter)
{
writer.WriteKeyword("ReadOnly");
writer.WriteString(" ");
}
else if(hasSetter && !hasGetter)
{
writer.WriteKeyword("WriteOnly");
writer.WriteString(" ");
}
if(isDefault)
{
writer.WriteKeyword("Default");
writer.WriteString(" ");
}
writer.WriteKeyword("Property");
writer.WriteString(" ");
writer.WriteIdentifier(name);
WriteParameters(reflection, writer);
writer.WriteString(" ");
writer.WriteKeyword("As");
writer.WriteString(" ");
WriteTypeReference(type, writer);
if(isExplicit)
{
if(writer.Position > MaxPosition)
{
writer.WriteLine();
writer.WriteString("\t");
}
else
{
writer.WriteString(" ");
}
writer.WriteKeyword("Implements");
writer.WriteString(" ");
XPathNodeIterator implementations = reflection.Select(apiImplementedMembersExpression);
while(implementations.MoveNext())
{
XPathNavigator implementation = implementations.Current;
XPathNavigator contract = implementation.SelectSingleNode(memberDeclaringTypeExpression);
//string id = implementation.GetAttribute("api", String.Empty);
if(implementations.CurrentPosition > 1)
writer.WriteString(", ");
WriteTypeReference(contract, writer);
writer.WriteString(".");
WriteMemberReference(implementation, writer);
//writer.WriteReferenceLink(id);
}
}
if(hasGetter)
{
writer.WriteLine();
// !EFW - Added support for getter/setter attributes
XPathNavigator getter = reflection.SelectSingleNode(apiGetterExpression);
if(getter != null && getter.HasChildren)
{
writer.WriteString("\t");
this.WriteAttributes(getter, writer, "\t");
}
writer.WriteString("\t");
string getVisibility = (string)reflection.Evaluate(apiGetVisibilityExpression);
if(!String.IsNullOrEmpty(getVisibility))
{
WriteVisibility(getVisibility, writer);
writer.WriteString(" ");
}
writer.WriteKeyword("Get");
}
if(hasSetter)
{
//.........这里部分代码省略.........