本文整理汇总了C#中IFormatter.Write方法的典型用法代码示例。如果您正苦于以下问题:C# IFormatter.Write方法的具体用法?C# IFormatter.Write怎么用?C# IFormatter.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFormatter
的用法示例。
在下文中一共展示了IFormatter.Write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Colorize
/// <summary>
/// Colorizes source code using the specified language, formatter, and
/// style sheet.
/// </summary>
/// <param name="sourceCode">The source code to colorize.</param>
/// <param name="language">The language to use to colorize the source
/// code.</param>
/// <param name="formatter">The formatter to use to colorize the source
/// code.</param>
/// <param name="styleSheet">The style sheet to use to colorize the
/// source code.</param>
public void Colorize(string sourceCode, ILanguage language, IFormatter formatter, IStyleSheet styleSheet)
{
Guard.ArgNotNull(language, "language");
Guard.ArgNotNull(formatter, "formatter");
Guard.ArgNotNull(styleSheet, "styleSheet");
languageParser.Parse(sourceCode, language, (parsedSourceCode, captures) => formatter.Write(parsedSourceCode, captures, styleSheet));
}
示例2: Write
public virtual void Write(Layer layer, string path, IFormatter formatter)
{
var lines = new List<string>();
Write(layer, lines);
var slice = new Slice(layer.SemName, lines);
var sb = new StringBuilder();
formatter.Write(slice, sb);
using (var fs = File.OpenWrite(path))
using (var swr = new StreamWriter(fs))
{
swr.WriteLine(sb.ToString());
swr.Flush();
}
}
示例3: WriteOrderClause
private void WriteOrderClause(IOrderClause value, IFormatter formatter)
{
formatter.WriteKeyword("orderby");
formatter.Write(" ");
var ed = value.ExpressionAndDirections[0];
this.WriteExpression(ed.Expression, formatter);
if (ed.Direction == OrderDirection.Descending)
{
formatter.Write(" ");
formatter.WriteKeyword("descending");
}
}
示例4: WriteWhileStatement
private void WriteWhileStatement(IWhileStatement statement, IFormatter formatter)
{
this.WriteStatementSeparator(formatter);
formatter.WriteKeyword("while");
formatter.Write(" ");
formatter.Write("(");
if (statement.Condition != null)
{
this.WriteExpression(statement.Condition, formatter);
}
else
formatter.WriteLiteral("true");
formatter.Write(")");
formatter.Write(" {");
formatter.WriteLine();
formatter.WriteIndent();
if (statement.Body != null)
{
this.WriteStatement(statement.Body, formatter);
}
formatter.WriteLine();
formatter.WriteOutdent();
formatter.Write("}");
}
示例5: WriteVariableDeclaration
private void WriteVariableDeclaration(IVariableDeclaration variableDeclaration, IFormatter formatter)
{
formatter.WriteKeyword("var ");
this.WriteDeclaration(variableDeclaration.Name, formatter); // TODO Escape = true
if (!this.forLoop)
{
formatter.Write(";");
formatter.WriteLine();
}
}
示例6: WriteUsingStatement
private void WriteUsingStatement(IUsingStatement statement, IFormatter formatter)
{
IVariableReference variable = null;
IAssignExpression assignExpression = statement.Expression as IAssignExpression;
if (assignExpression != null)
{
IVariableDeclarationExpression variableDeclarationExpression = assignExpression.Target as IVariableDeclarationExpression;
if (variableDeclarationExpression != null)
{
variable = variableDeclarationExpression.Variable;
}
IVariableReferenceExpression variableReferenceExpression = assignExpression.Target as IVariableReferenceExpression;
if (variableReferenceExpression != null)
{
variable = variableReferenceExpression.Variable;
}
}
this.WriteStatementSeparator(formatter);
// make a comment that Reflector detected this as a using statement
//formatter.Write("{using");
if (variable != null)
{
//formatter.Write(" ");
this.WriteVariableReference(variable, formatter);
}
formatter.Write("}");
formatter.WriteLine();
// and replace this with
// - create obj
// - try ... finally obj.Dispose end
formatter.WriteKeyword("begin");
formatter.WriteLine();
formatter.WriteIndent();
if (variable != null)
{
this.WriteVariableReference(variable, formatter);
formatter.Write(" ");
formatter.WriteKeyword(":=");
formatter.Write(" ");
this.WriteExpression(assignExpression.Expression, formatter);
this.WriteStatementSeparator(formatter);
}
formatter.WriteKeyword("try");
formatter.WriteLine();
formatter.WriteIndent();
if (statement.Body != null)
{
this.WriteBlockStatement(statement.Body, formatter);
}
formatter.WriteLine();
formatter.WriteOutdent();
formatter.WriteKeyword("finally");
formatter.WriteLine();
formatter.WriteIndent();
if (variable != null)
{
this.firstStmt = true;
this.WriteVariableReference(variable, formatter);
formatter.Write(".");
formatter.Write("Dispose");
formatter.WriteLine();
}
else
{
this.firstStmt = true;
this.WriteExpression(statement.Expression);
formatter.Write(".");
formatter.Write("Dispose");
formatter.WriteLine();
}
formatter.WriteOutdent();
formatter.WriteKeyword("end");
formatter.WriteLine();
formatter.WriteOutdent();
formatter.WriteKeyword("end");
}
示例7: WriteTypeOfExpression
private void WriteTypeOfExpression(ITypeOfExpression expression, IFormatter formatter)
{
formatter.WriteKeyword("typeof");
formatter.Write("(");
this.WriteType(expression.Type, formatter);
formatter.Write(")");
}
示例8: WriteType
private void WriteType(IType type, IFormatter formatter)
{
ITypeReference typeReference = type as ITypeReference;
if (typeReference != null)
{
string description = Helper.GetNameWithResolutionScope(typeReference);
this.WriteTypeReference(typeReference, formatter, description, typeReference);
return;
}
IArrayType arrayType = type as IArrayType;
if (arrayType != null)
{
this.WriteType(arrayType.ElementType, formatter);
formatter.Write("[");
IArrayDimensionCollection dimensions = arrayType.Dimensions;
for (int i = 0; i < dimensions.Count; i++)
{
if (i != 0)
{
formatter.Write(",");
}
if ((dimensions[i].LowerBound != 0) && (dimensions[i].UpperBound != -1))
{
if ((dimensions[i].LowerBound != -1) || (dimensions[i].UpperBound != -1))
{
formatter.Write((dimensions[i].LowerBound != -1) ? dimensions[i].LowerBound.ToString(CultureInfo.InvariantCulture) : ".");
formatter.Write("..");
formatter.Write((dimensions[i].UpperBound != -1) ? dimensions[i].UpperBound.ToString(CultureInfo.InvariantCulture) : ".");
}
}
}
formatter.Write("]");
return;
}
IPointerType pointerType = type as IPointerType;
if (pointerType != null)
{
this.WriteType(pointerType.ElementType, formatter);
formatter.Write("*");
return;
}
IReferenceType referenceType = type as IReferenceType;
if (referenceType != null)
{
// formatter.WriteKeyword ("var"); // already done before the param name - HV
// formatter.Write (" ");
this.WriteType(referenceType.ElementType, formatter);
return;
}
IOptionalModifier optionalModifier = type as IOptionalModifier;
if (optionalModifier != null)
{
this.WriteType(optionalModifier.ElementType, formatter);
formatter.Write(" ");
formatter.WriteKeyword("modopt");
formatter.Write("(");
this.WriteType(optionalModifier.Modifier, formatter);
formatter.Write(")");
return;
}
IRequiredModifier requiredModifier = type as IRequiredModifier;
if (requiredModifier != null)
{
this.WriteType(requiredModifier.ElementType, formatter);
formatter.Write(" ");
formatter.WriteKeyword("modreq");
formatter.Write("(");
this.WriteType(requiredModifier.Modifier, formatter);
formatter.Write(")");
return;
}
IFunctionPointer functionPointer = type as IFunctionPointer;
if (functionPointer != null)
{
this.WriteType(functionPointer.ReturnType.Type, formatter);
formatter.Write(" *(");
for (int i = 0; i < functionPointer.Parameters.Count; i++)
{
if (i != 0)
{
formatter.Write(", ");
}
this.WriteType(functionPointer.Parameters[i].ParameterType, formatter);
}
formatter.Write(")");
return;
}
IGenericParameter genericParameter = type as IGenericParameter;
//.........这里部分代码省略.........
示例9: WriteQueryExpression
private void WriteQueryExpression(IQueryExpression value, IFormatter formatter)
{
formatter.Write("(");
this.WriteFromClause(value.From, formatter);
if ((value.Body.Clauses.Count > 0) || (value.Body.Continuation != null))
{
formatter.WriteLine();
formatter.WriteIndent();
}
else
{
formatter.Write(" ");
}
this.WriteQueryBody(value.Body, formatter);
formatter.Write(")");
if ((value.Body.Clauses.Count > 0) || (value.Body.Continuation != null))
{
formatter.WriteOutdent();
}
}
示例10: WriteQueryContinuation
private void WriteQueryContinuation(IQueryContinuation value, IFormatter formatter)
{
formatter.WriteKeyword("into");
formatter.Write(" ");
this.WriteDeclaration(value.Variable.Name, formatter);
formatter.WriteLine();
this.WriteQueryBody(value.Body, formatter);
}
示例11: WriteQueryBody
private void WriteQueryBody(IQueryBody value, IFormatter formatter)
{
// from | where | let | join | orderby
for (int i = 0; i < value.Clauses.Count; i++)
{
this.WriteQueryClause(value.Clauses[i], formatter);
formatter.WriteLine();
}
// select | group
this.WriteQueryOperation(value.Operation, formatter);
// into
if (value.Continuation != null)
{
formatter.Write(" ");
this.WriteQueryContinuation(value.Continuation, formatter);
}
}
示例12: WritePropertyReferenceExpression
private void WritePropertyReferenceExpression(IPropertyReferenceExpression expression, IFormatter formatter)
{
// TODO bool escape = true;
if (expression.Target != null)
{ // TODO escape = false;
this.WriteTargetExpression(expression.Target, formatter);
formatter.Write(".");
}
var g = expression.Property.Resolve().GetMethod;
WriteMethodReference(g, formatter);
formatter.Write("()");
}
示例13: WritePropertyIndexerExpression
private void WritePropertyIndexerExpression(IPropertyIndexerExpression expression, IFormatter formatter)
{
this.WriteTargetExpression(expression.Target, formatter);
formatter.Write("(");
bool first = true;
foreach (IExpression index in expression.Indices)
{
if (first)
{
first = false;
}
else
{
formatter.Write(", ");
}
this.WriteExpression(index, formatter);
}
formatter.Write(")");
}
示例14: WriteParameterDeclarationList
private void WriteParameterDeclarationList(IParameterDeclarationCollection parameters, IFormatter formatter, ILanguageWriterConfiguration configuration)
{
for (int i = 0; i < parameters.Count; i++)
{
IParameterDeclaration parameter = parameters[i];
IType parameterType = parameter.ParameterType;
if ((parameterType != null) || ((i + 1) != parameters.Count))
{
if (i != 0)
{
formatter.Write(", ");
}
this.WriteParameterDeclaration(parameter, formatter, configuration);
}
}
}
示例15: WriteParameterDeclaration
private void WriteParameterDeclaration(IParameterDeclaration value, IFormatter formatter, ILanguageWriterConfiguration configuration)
{
if ((configuration != null) && (configuration["ShowCustomAttributes"] == "true") && (value.Attributes.Count != 0))
{
this.WriteCustomAttributeList(value, formatter);
formatter.Write(" ");
}
IType parameterType = value.ParameterType;
IReferenceType referenceType = parameterType as IReferenceType;
if (referenceType != null)
{
}
if ((value.Name != null) && value.Name.Length > 0)
{
formatter.Write(value.Name);
}
else
{
formatter.Write("A");
}
}