本文整理汇总了C#中ICodeWriter.BeginBlock方法的典型用法代码示例。如果您正苦于以下问题:C# ICodeWriter.BeginBlock方法的具体用法?C# ICodeWriter.BeginBlock怎么用?C# ICodeWriter.BeginBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICodeWriter
的用法示例。
在下文中一共展示了ICodeWriter.BeginBlock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteSerializeFieldStatementRecursive
private static void WriteSerializeFieldStatementRecursive(ICodeWriter o, bool writeToBitstream, Type variableType, string variableName)
{
if (variableType.IsArray)
{
Type elemType = variableType.GetElementType();
if (writeToBitstream)
{
WriteStreamWriteStatement(o, variableName + ".Length");
o.BeginBlock("for (int i = 0; i < {0}.Length; i++) {{", variableName);
WriteSerializeFieldStatementRecursive(o, writeToBitstream, elemType, variableName + "[i]");
o.EndBlock("}");
}
else
{
string lengthVariableName = "_" + variableName + "Length";
o.WriteLine("int {0};", lengthVariableName);
WriteStreamReadStatement(o, "out", lengthVariableName);
o.WriteLine("{0} = new {1}[{2}];", variableName, elemType.ToString(), lengthVariableName);
o.BeginBlock("for (int i = 0; i < {0}; i++) {{", lengthVariableName);
WriteSerializeFieldStatementRecursive(o, writeToBitstream, elemType, variableName + "[i]");
o.EndBlock("}");
}
}
else
{
WriteSerializeNonCollectionStatement(o, writeToBitstream, variableType, variableName);
}
}
示例2: Write
public void Write(ICodeWriter o)
{
o.WriteLine("[Transient]");
o.BeginBlock("internal sealed class {0} : IEventFactory {{", factoryName);
WriteRecreateEvent(o);
o.EndBlock("}");
}
示例3: WriteAccessor
public static void WriteAccessor(ICodeWriter o, string typeName, string variableNameInLowerCamelCase)
{
o.BeginBlock("public {0} {1} {{", typeName, GetVariableNameInUpperCamelCase(variableNameInLowerCamelCase));
o.WriteLine("get {{ return {0}; }}", variableNameInLowerCamelCase);
o.WriteLine("set {{ {0} = value; }}", variableNameInLowerCamelCase);
o.EndBlock("}");
}
示例4: WriteSingleton
public static void WriteSingleton(ICodeWriter o, string className)
{
o.WriteLine("private static {0} instance = new {0}();", className);
o.BeginBlock("public static {0} Instance {{", className);
o.WriteLine("get { return instance; }");
o.EndBlock("}");
o.WriteLine("private {0}() {{ }}", className);
}
示例5: Write
public void Write(ICodeWriter o)
{
o.WriteLine("[Transient]");
o.BeginBlock("internal sealed class {0} : IEventHandlers {{", handlersName);
WriteCallHandler(o);
WriteEvents(o);
o.EndBlock("}");
}
示例6: WriteCallHandler
private void WriteCallHandler(ICodeWriter o)
{
o.BeginBlock("public void CallHandler(IEvent e) {");
o.BeginBlock("switch (e.Id) {");
foreach (EventInfo ei in eventInfos)
{
o.BeginBlock("case {0}:", ei.EventId);
string handlerName = GetHandlerName(ei.Type.Name);
o.BeginBlock("if ({0} != null)", handlerName);
o.WriteLine("{0}(({1})e);", handlerName, ei.Type.Name);
o.EndBlock("break;");
o.EndBlock("");
}
o.BeginBlock("default:");
o.WriteLine("throw new UnknownEventIdException(e.Id, \"{0}\");", handlersName + ".CallHandler()");
o.EndBlock("");
o.EndBlock("}");
o.EndBlock("}");
}
示例7: Write
public void Write(ICodeWriter o)
{
string className = t.Name;
string protocolName = attr.ProtocolName;
o.BeginBlock("internal partial class {0} : IProtocolInfo {{", className);
ClassGeneratorHelper.WriteSingleton(o, className);
WriteName(o, protocolName);
WriteVersionProperty(o, "MajorVersion", attr.MajorVersion);
WriteVersionProperty(o, "MinorVersion", minorVersion);
o.EndBlock("}");
}
示例8: WriteRecreateEvent
private void WriteRecreateEvent(ICodeWriter o)
{
o.BeginBlock("public IEvent RecreateSimpleEvent(BitStream source) {");
o.WriteLine("Debug.Assert(source != null);");
o.WriteLine("IEvent _event;");
o.WriteLine("int id;");
o.WriteLine("if(!source.Read(out id)) throw new DeserializationException();");
o.WriteLine("source.ResetReadPointer();");
o.BeginBlock("switch (id) {");
foreach (EventInfo ei in eventInfos)
{
o.BeginBlock("case {0}:", ei.EventId);
o.WriteLine("_event = new {0}(source);", ei.Type.Name);
o.WriteLine("break;");
o.EndBlock("");
}
o.BeginBlock("default:");
o.WriteLine("throw new UnknownEventIdException(id, \"{0}\");", factoryName + ".RecreateEvent()");
o.EndBlock("");
o.EndBlock("}");
o.WriteLine("return _event;");
o.EndBlock("}");
}
示例9: Write
public void Write(ICodeWriter o)
{
o.BeginBlock("internal partial class {0} : IEvent {{", type.Name);
WriteCtorWithId(o);
WriteCtorWithStream(o);
WriteAccessors(o);
WriteGetStream(o);
WriteId(o);
WriteSourceOid(o);
WriteTargetOid(o);
WriteSender(o);
WriteProtocolInfo(o);
o.EndBlock("}");
}
示例10: WriteSetData
private void WriteSetData(ICodeWriter o)
{
StringBuilder arg = new StringBuilder();
FieldInfo[] fields = GetSerializableFields();
for (int i = 0; i < fields.Length; i++)
{
if (0 < i) arg.Append(", ");
arg.Append(fields[i].FieldType.ToString());
arg.Append(" ");
arg.Append(fields[i].Name);
}
o.BeginBlock("public void SetData({0}) {{", arg.ToString());
foreach (FieldInfo field in fields)
{
o.WriteLine("this.{0} = {0};", field.Name);
}
o.EndBlock("}");
}
示例11: WriteGetStream
// TODO: ProtocolGenerator can't handle null reference.
private void WriteGetStream(ICodeWriter o)
{
o.BeginBlock("public BitStream Stream {");
o.BeginBlock("get {");
o.WriteLine("BitStream eventStream = new BitStream();");
WriteStreamWriteStatement(o, "id");
WriteStreamWriteStatement(o, "sourceOId");
WriteStreamWriteStatement(o, "targetOId");
foreach (FieldInfo field in GetSerializableFields())
{
WriteSerializeFieldStatementRecursive(o, true, field.FieldType, field.Name);
}
o.WriteLine("return eventStream;");
o.EndBlock("}");
o.EndBlock("}");
}
示例12: WriteCtorWithStream
private void WriteCtorWithStream(ICodeWriter o)
{
o.BeginBlock("public {0}(BitStream source) {{", type.Name);
WriteStreamReadStatement(o, "out", "id");
WriteStreamReadStatement(o, "out", "sourceOId");
WriteStreamReadStatement(o, "out", "targetOId");
foreach (FieldInfo field in GetSerializableFields())
{
WriteSerializeFieldStatementRecursive(o, false, field.FieldType, field.Name);
}
o.EndBlock("}");
}
示例13: WriteCtorWithId
private void WriteCtorWithId(ICodeWriter o)
{
o.BeginBlock("public {0}() {{", type.Name);
o.WriteLine("id = {0};", eventId);
o.EndBlock("}");
}
示例14: WritePropertyImpl
/// <summary>
///
/// </summary>
/// <param name="o"></param>
/// <param name="typeName"></param>
/// <param name="variableNameInLowerCamelCase"></param>
/// <param name="defaultValue">Can be null</param>
/// <param name="doesWriteGetter"></param>
/// <param name="getterAccessibility">Can be null</param>
/// <param name="doesWriteSetter"></param>
/// <param name="setterAccessibility">Can be null</param>
private static void WritePropertyImpl(ICodeWriter o, string typeName, string variableNameInLowerCamelCase, string defaultValue, bool doesWriteGetter, string getterAccessibility, bool doesWriteSetter, string setterAccessibility)
{
string getterAccessibilityWithSpace = "";
string setterAccessibilityWithSpace = "";
string defaultValueWithAssignMark = "";
if (getterAccessibility != null)
{
getterAccessibilityWithSpace = getterAccessibility + " ";
}
if (setterAccessibility != null)
{
setterAccessibilityWithSpace = setterAccessibility + " ";
}
if (defaultValue != null)
{
defaultValueWithAssignMark = " = " + defaultValue;
}
string variableNameInUpperCamelCase = GetVariableNameInUpperCamelCase(variableNameInLowerCamelCase);
o.BeginBlock("public {0} {1} {{", typeName, variableNameInUpperCamelCase);
if (doesWriteGetter)
{
o.WriteLine("{0}get {{ return {1}; }}", getterAccessibilityWithSpace, variableNameInLowerCamelCase);
}
if (doesWriteSetter)
{
o.WriteLine("{0}set {{ {1} = value; }}", setterAccessibilityWithSpace, variableNameInLowerCamelCase);
}
o.EndBlock("}");
o.WriteLine("{0} {1}{2};", typeName, variableNameInLowerCamelCase, defaultValueWithAssignMark);
}
示例15: WriteGetAccessor
public static void WriteGetAccessor(ICodeWriter o, string typeName, string propertyName, string value)
{
o.BeginBlock("public {0} {1} {{", typeName, propertyName);
o.WriteLine("get {{ return {0}; }}", value);
o.EndBlock("}");
}