本文整理汇总了C#中SyntaxWriter.WriteKeyword方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxWriter.WriteKeyword方法的具体用法?C# SyntaxWriter.WriteKeyword怎么用?C# SyntaxWriter.WriteKeyword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxWriter
的用法示例。
在下文中一共展示了SyntaxWriter.WriteKeyword方法的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: WriteEnumerationSyntax
/// <inheritdoc />
public override void WriteEnumerationSyntax(XPathNavigator reflection, SyntaxWriter writer)
{
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(" ");
WriteVisibility(reflection, writer);
writer.WriteIdentifier(name);
}
示例4: WriteDelegateSyntax
/// <inheritdoc />
public override void WriteDelegateSyntax(XPathNavigator reflection, SyntaxWriter writer)
{
if(IsUnsupportedUnsafe(reflection, writer))
return;
string name = (string)reflection.Evaluate(apiNameExpression);
bool isSerializable = (bool)reflection.Evaluate(apiIsSerializableTypeExpression);
XPathNavigator type = reflection.SelectSingleNode(apiReturnTypeExpression);
if(isSerializable)
WriteAttribute("T:System.SerializableAttribute", writer);
WriteAttributes(reflection, writer);
WriteVisibility(reflection, writer);
writer.WriteString(" ");
writer.WriteKeyword("Delegate");
writer.WriteString(" ");
if(type == null)
{
writer.WriteKeyword("Sub");
}
else
{
writer.WriteKeyword("Function");
}
writer.WriteString(" ");
writer.WriteIdentifier(name);
WriteGenericTemplates(reflection, writer, true); // Need to write variance info for interfaces and delegates
WriteParameters(reflection, writer);
if(type != null)
{
writer.WriteString(" ");
writer.WriteKeyword("As");
writer.WriteString(" ");
WriteTypeReference(type, writer);
}
}
示例5: WriteTypeReference
// References
/// <inheritdoc />
protected override void WriteTypeReference(XPathNavigator reference, SyntaxWriter writer)
{
switch(reference.LocalName)
{
case "arrayOf":
int rank = Convert.ToInt32(reference.GetAttribute("rank", String.Empty),
CultureInfo.InvariantCulture);
XPathNavigator element = reference.SelectSingleNode(typeExpression);
WriteTypeReference(element, writer);
writer.WriteString("[");
for(int i = 1; i < rank; i++)
writer.WriteString(",");
writer.WriteString("]");
break;
case "pointerTo":
XPathNavigator pointee = reference.SelectSingleNode(typeExpression);
writer.WriteKeyword("nativeptr");
writer.WriteString("<");
WriteTypeReference(pointee, writer);
writer.WriteString(">");
break;
case "referenceTo":
XPathNavigator referee = reference.SelectSingleNode(typeExpression);
WriteTypeReference(referee, writer);
break;
case "type":
string id = reference.GetAttribute("api", String.Empty);
WriteNormalTypeReference(id, writer);
XPathNodeIterator typeModifiers = reference.Select(typeModifiersExpression);
while(typeModifiers.MoveNext())
WriteTypeReference(typeModifiers.Current, writer);
break;
case "template":
string name = reference.GetAttribute("name", String.Empty);
writer.WriteString("'");
writer.WriteString(name);
XPathNodeIterator modifiers = reference.Select(typeModifiersExpression);
while(modifiers.MoveNext())
WriteTypeReference(modifiers.Current, writer);
break;
case "specialization":
writer.WriteString("<");
XPathNodeIterator arguments = reference.Select(specializationArgumentsExpression);
while(arguments.MoveNext())
{
if(arguments.CurrentPosition > 1)
writer.WriteString(", ");
WriteTypeReference(arguments.Current, writer);
}
writer.WriteString(">");
break;
}
}
示例6: WriteDotNetObject
private void WriteDotNetObject(XPathNavigator reflection, SyntaxWriter writer, string kind)
{
string name = reflection.Evaluate(apiNameExpression).ToString();
bool isSerializable = (bool)reflection.Evaluate(apiIsSerializableTypeExpression);
XPathNodeIterator implements = reflection.Select(apiImplementedInterfacesExpression);
XPathNavigator baseClass = reflection.SelectSingleNode(apiBaseClassExpression);
bool hasBaseClass = (baseClass != null) && !((bool)baseClass.Evaluate(typeIsObjectExpression));
// CLR considers interfaces abstract.
bool isAbstract = (bool)reflection.Evaluate(apiIsAbstractTypeExpression) && kind != "interface";
bool isSealed = (bool)reflection.Evaluate(apiIsSealedTypeExpression);
if(isAbstract)
WriteAttribute("T:Microsoft.FSharp.Core.AbstractClassAttribute", true, writer);
if(isSealed)
WriteAttribute("T:Microsoft.FSharp.Core.SealedAttribute", true, writer);
if(isSerializable)
WriteAttribute("T:System.SerializableAttribute", true, writer);
WriteAttributes(reflection, writer);
writer.WriteKeyword("type");
writer.WriteString(" ");
writer.WriteIdentifier(name);
WriteGenericTemplates(reflection, writer);
writer.WriteString(" = ");
if(hasBaseClass || implements.Count != 0)
{
writer.WriteLine();
writer.WriteString(" ");
}
writer.WriteKeyword(kind);
if(hasBaseClass || implements.Count != 0)
{
writer.WriteLine();
}
if(hasBaseClass)
{
writer.WriteString(" ");
writer.WriteKeyword("inherit");
writer.WriteString(" ");
WriteTypeReference(baseClass, writer);
writer.WriteLine();
}
while(implements.MoveNext())
{
XPathNavigator implement = implements.Current;
writer.WriteString(" ");
writer.WriteKeyword("interface");
writer.WriteString(" ");
WriteTypeReference(implement, writer);
writer.WriteLine();
}
if(hasBaseClass || implements.Count != 0)
{
writer.WriteString(" ");
}
else
{
writer.WriteString(" ");
}
writer.WriteKeyword("end");
}
示例7: WriteNormalMethodSyntax
/// <inheritdoc />
public override void WriteNormalMethodSyntax(XPathNavigator reflection, SyntaxWriter writer)
{
// !EFW - Added unsafe check
if(IsUnsupportedUnsafe(reflection, writer))
return;
if(IsUnsupportedVarargs(reflection, writer))
return;
string name = (string)reflection.Evaluate(apiNameExpression);
XPathNavigator type = reflection.SelectSingleNode(apiReturnTypeExpression);
bool isExplicit = (bool)reflection.Evaluate(apiIsExplicitImplementationExpression);
WriteAttributes(reflection, writer);
WriteProcedureModifiers(reflection, writer);
if(type == null)
writer.WriteKeyword("Sub");
else
writer.WriteKeyword("Function");
writer.WriteString(" ");
writer.WriteIdentifier(name);
WriteGenericTemplates(reflection, writer);
WriteParameters(reflection, writer);
if(type != null)
{
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(attributeTypeExpression);
// string id = implementation.GetAttribute("api", String.Empty);
if(implementations.CurrentPosition > 1)
writer.WriteString(", ");
WriteTypeReference(contract, writer);
writer.WriteString(".");
WriteMemberReference(implementation, writer);
}
}
}
示例8: WriteOperatorSyntax
//.........这里部分代码省略.........
case "LogicalNot":
identifier = "not";
break;
case "True":
identifier = "true";
break;
case "False":
identifier = "false";
break;
// binary comparison operators
case "Equality":
identifier = "=";
break;
case "Inequality":
identifier = "<>";
break;
case "LessThan":
identifier = "<";
break;
case "GreaterThan":
identifier = ">";
break;
case "LessThanOrEqual":
identifier = "<=";
break;
case "GreaterThanOrEqual":
identifier = ">=";
break;
// binary math operators
case "Addition":
identifier = "+";
break;
case "Subtraction":
identifier = "-";
break;
case "Multiply":
identifier = "*";
break;
case "Division":
identifier = "/";
break;
case "Modulus":
identifier = "%";
break;
// binary logical operators
case "BitwiseAnd":
identifier = "&&&";
break;
case "BitwiseOr":
identifier = "|||";
break;
case "ExclusiveOr":
identifier = "^^^";
break;
// bit-array operators
case "OnesComplement":
identifier = null; // No F# equiv.
break;
case "LeftShift":
identifier = "<<<";
break;
case "RightShift":
identifier = ">>>";
break;
case "Assign":
identifier = "=";
break;
// unrecognized operator
default:
identifier = null;
break;
}
}
if(identifier == null)
{
writer.WriteMessage("UnsupportedOperator_" + Language);
}
else
{
if(isStatic)
{
writer.WriteKeyword("static");
writer.WriteString(" ");
}
writer.WriteKeyword("let");
writer.WriteString(" ");
writer.WriteKeyword("inline");
writer.WriteKeyword(" ");
writer.WriteString("(");
writer.WriteIdentifier(identifier);
writer.WriteString(")");
WriteParameters(reflection, writer);
writer.WriteString(" : ");
WriteReturnValue(reflection, writer);
}
}
示例9: 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);
XPathNavigator args = reflection.SelectSingleNode(apiEventArgsExpression);
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(isVirtual)
if(i == 0)
{
writer.WriteKeyword("abstract");
writer.WriteString(" ");
}
else
{
writer.WriteKeyword("override");
writer.WriteString(" ");
}
else
{
WriteMemberKeyword(reflection, writer);
}
writer.WriteIdentifier(name);
writer.WriteString(" : ");
writer.WriteReferenceLink("T:Microsoft.FSharp.Control.IEvent`2");
writer.WriteString("<");
WriteTypeReference(handler, writer);
writer.WriteString(",");
writer.WriteLine();
writer.WriteString(" ");
if(args == null)
{
writer.WriteReferenceLink("T:System.EventArgs");
}
else
{
WriteTypeReference(args, writer);
}
writer.WriteString(">");
if(i == 0)
writer.WriteLine();
}
}
示例10: 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);
}
示例11: WriteVisibility
private static void WriteVisibility(string visibility, SyntaxWriter writer)
{
switch(visibility)
{
case "public":
writer.WriteKeyword("Public");
break;
case "family":
writer.WriteKeyword("Protected");
break;
case "family or assembly":
writer.WriteKeyword("Protected Friend");
break;
case "family and assembly":
writer.WriteKeyword("Friend"); // not right, but same outside assembly
break;
case "assembly":
writer.WriteKeyword("Friend");
break;
case "private":
writer.WriteKeyword("Private");
break;
}
}
示例12: 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);
}
}
}
示例13: 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(" ");
}
}
}
}
}
示例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)
{
//.........这里部分代码省略.........