本文整理汇总了C#中SourceCode.Append方法的典型用法代码示例。如果您正苦于以下问题:C# SourceCode.Append方法的具体用法?C# SourceCode.Append怎么用?C# SourceCode.Append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SourceCode
的用法示例。
在下文中一共展示了SourceCode.Append方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateField
public override SourceCode GenerateField(CodeContext context)
{
var code = new SourceCode();
code.Append("typedef std::vector<{0}> {1};", CanonicalTarget, TypeName);
code.Append("{0} {1};", TypeName, VarName);
return code;
}
示例2: GenerateReader
public override SourceCode GenerateReader(CodeContext context)
{
var code = new SourceCode();
code.Append("this->skip(static_cast<msg_size_t>(sizeof(msg_type_t)));");
code.Append("(*this) >> {0};", GetVarAccessor(context));
return code;
}
示例3: GenerateHandler
public override SourceCode GenerateHandler(CodeContext context)
{
var code = new SourceCode();
var listAccessor = GetVarAccessor(context);
var iteratorName = context.StartIterator();
code.Append(CodeUtil.ForEachCode(TypeName, listAccessor, iteratorName, true));
code.IndentRight();
code.Append("{0}::handle(session, *{1});", CanonicalTarget, iteratorName);
code.BracketEnd();
context.EndIterator();
return code;
}
示例4: GenerateWriter
public override SourceCode GenerateWriter(CodeContext context)
{
var code = new SourceCode();
var listAccessor = GetVarAccessor(context);
var iteratorName = context.StartIterator();
code.Append("(*this) << static_cast<uint32_t>({0}size());", listAccessor);
code.Append(CodeUtil.ForEachCode(CanonicalType, listAccessor, iteratorName, true));
code.IndentRight();
code.Append("(*this) << (*{0});", iteratorName);
code.BracketEnd();
context.EndIterator();
return code;
}
示例5: GenerateModelCode
public override SourceCode GenerateModelCode()
{
var code = new SourceCode();
code.Append(Class.GenerateModelCode());
if (Class.NodeCount > 1)
{
code.Append(Class.HasId ? "typedef std::map<data::id_t, {0}*> {1};" : "typedef std::vector<{0}*> {1};", Class.TypeName, Class.CollectionTypeName);
code.Append("{0} {1};", Class.CollectionTypeName, Class.CollectionName);
}
else
code.Append("{0} {1};", Class.TypeName, Class.CanonicalName);
return code;
}
示例6: GenerateField
public override SourceCode GenerateField(CodeContext context)
{
var code = new SourceCode();
code.Append("struct {0} {{", Name);
code.IndentRight();
Fields.ForEach(field => code.Append(field.GenerateField(context)));
code.NewLine();
code.Append(Fields.GenerateDefaultConstructor(Name));
code.BracketEnd(";");
code.Append("typedef std::vector<{0}> {1};", Name, TypeName);
code.Append("{0} {1};", TypeName, VarName);
return code;
}
示例7: GenerateHandler
public override SourceCode GenerateHandler(CodeContext context)
{
var code = new SourceCode();
if (Fields.Count(field => field is RefField) == 0)
return code;
var listAccessor = GetVarAccessor(context);
var iteratorName = context.StartIterator();
code.Append(CodeUtil.ForEachCode(TypeName, listAccessor, iteratorName, true));
code.IndentRight();
Fields.ForEach(field => code.Append(field.GenerateHandler(context)));
code.BracketEnd();
context.EndIterator();
return code;
}
示例8: GenerateReader
public override SourceCode GenerateReader(CodeContext context)
{
var code = new SourceCode();
var countVar = Name + "_count";
code.Append("uint32_t {0};", countVar);
code.Append("(*this) >> {0};", countVar);
code.Append("for (uint32_t index = 0; index < {0}; ++index) {{", countVar);
code.IndentRight();
var listAccessor = GetVarAccessor(context);
var eachVariable = context.StartAccessor("each");
code.Append("{0} {1};", CanonicalName, eachVariable);
Fields.ForEach(field => code.Append(field.GenerateReader(context)));
code.Append("{0}push_back({1});", listAccessor, eachVariable);
code.BracketEnd();
context.EndAccessor();
return code;
}
示例9: GenerateReader
public override SourceCode GenerateReader(CodeContext context)
{
var code = new SourceCode();
var countVar = Name + "_count";
code.Append("uint32_t {0};", countVar);
code.Append("(*this) >> {0};", countVar);
var listAccessor = GetVarAccessor(context);
code.Append("for (uint32_t index = 0; index < {0}; ++index) {{", countVar);
code.IndentRight();
var eachVariable = context.StartAccessor("each");
code.Append("{0} {1};", CanonicalTarget, eachVariable);
code.Append("this->skip(static_cast<msg_size_t>(sizeof(msg_type_t)));");
code.Append("(*this) >> {0};", eachVariable);
code.Append("{0}push_back({1});", listAccessor, eachVariable);
context.EndAccessor();
code.BracketEnd();
return code;
}
示例10: GenerateDefaultConstructor
public static SourceCode GenerateDefaultConstructor(this IEnumerable<Field> fields, string className)
{
// msg default constructor
var primitiveArgs = fields.OfType<SimpleField>().Select(
e => string.Format("{0}({1})", e.Name, TypeUtil.ToDefaultValueInInitializer(e.Type))).ToArray();
var code = new SourceCode();
if (primitiveArgs.Any())
{
code.Append("#ifdef _DEBUG");
code.Append("{0}()", className);
code.IndentRight();
code.Append(": {0} {{}}", string.Join(", ", primitiveArgs));
code.IndentLeft();
code.Append("#else");
}
code.Append("{0}() {{}}", className);
if (primitiveArgs.Any())
code.Append("#endif");
return code;
}
示例11: GenerateTypeIdFile
private void GenerateTypeIdFile()
{
var typeIdCode = new SourceCode();
typeIdCode.Append("#pragma once");
typeIdCode.NewLine();
typeIdCode.Append("namespace data { namespace type_id { ;");
foreach (var clazz in DataCenter.Instance.Values)
{
typeIdCode.Append("const int {0} = {1};", clazz.SimpleName, clazz.TypeId);
}
typeIdCode.Append("}}");
typeIdCode.NewLine();
typeIdCode.WriteToFile(Path.Combine(_outputDirectory, "data_type_id.h"));
}
示例12: GenerateParserFile
private void GenerateParserFile()
{
const string clientCppFileName = "data_center_client.cpp";
const string serverCppFileName = "data_center_server.cpp";
// generate parser file
var parser = new SourceCode();
parser.Append("#include <data_expression.h>");
parser.Append("#include <data_center.h>");
foreach (var clazz in DataCenter.Instance.Values)
parser.Append("#include \"{0}\"", clazz.HeaderFileName);
parser.NewLine();
parser.Append("#pragma warning( disable : 4996 )");
parser.NewLine();
parser.Append("using namespace data;");
parser.NewLine();
foreach (var clazz in DataCenter.Instance.Values)
parser.Append("template <> typename data_center<{0}>::storage_t* data_center<{0}>::storage = nullptr;", clazz.TypeName);
foreach (var clazz in DataCenter.Instance.Values)
parser.Append("template <> data_linker_t data_center<{0}>::linker;", clazz.TypeName);
parser.NewLine();
foreach (var clazz in DataCenter.Instance.Values)
parser.Append(clazz.GenerateParseDeclsCode().Generate());
parser.NewLine();
foreach (var clazz in DataCenter.Instance.Values)
{
parser.Append(clazz.GenerateParseCode().Generate());
parser.NewLine();
}
parser.NewLine();
foreach (var clazz in DataCenter.Instance.Values)
{
parser.Append("void data::__data_load(data_type_t<{0}>)", clazz.TypeName);
parser.BracketStart();
parser.Append("TiXmlDocument document;");
parser.Append("document.LoadFile(user_defined_path_resolver(\"{0}\"));", clazz.XmlFileName.Replace("\\", "\\\\"));
parser.Append("TiXmlElement* root_node = document.FirstChildElement(\"{0}\");", clazz.XmlRootName);
parser.Append("parse_{0}(root_node->FirstChildElement(\"{1}-list\"));", clazz.ParserName, clazz.XmlNodeName);
parser.BracketEnd();
parser.NewLine();
}
SourceCode.StaticInitializerSerial = 99;
parser.StaticInitializerStart();
{
foreach (var clazz in DataCenter.Instance.Values)
parser.Append("data::__data_load(data_type_t<{0}>());", clazz.TypeName);
parser.NewLine();
foreach (var clazz in DataCenter.Instance.Values)
parser.Append("{0}_data::linker.link();", clazz.SimpleName);
}
parser.StaticInitializerEnd();
parser.NewLine();
parser.Append("#pragma warning( default : 4996 )");
parser.NewLine();
parser.WriteToFile(Path.Combine(_outputDirectory, clientCppFileName), "#include <clientpch.h>");
parser.WriteToFile(Path.Combine(_outputDirectory, serverCppFileName), "#include <serverpch.h>");
}
示例13: GenerateHandlerDeclaration
public SourceCode GenerateHandlerDeclaration()
{
var code = new SourceCode();
code.NewLine();
code.Append("typedef {0} type;", ClassName);
code.Append("typedef std::function<void (msg_session_ref, const type&)> handler_t;");
code.Append("typedef void (*listener_t)(const type&);");
code.Append("typedef std::vector<listener_t> listener_list;");
code.NewLine();
code.Append("static handler_t _handler;");
code.Append("static listener_list _listeners;");
code.Append("static void handle(msg_session_ref session, const type& msg);");
code.Append("static void handle(msg_session_ref session, msg_reader reader);");
code.Append("static void broadcast(const type& msg);");
return code;
}
示例14: GenerateParseDeclsCode
public SourceCode GenerateParseDeclsCode()
{
var code = new SourceCode();
code.Append(GenerateParseDeclCode());
foreach (var field in DataClassFields)
code.Append(field.Class.GenerateParseDeclCode());
return code;
}
示例15: GenerateModelCode
public SourceCode GenerateModelCode()
{
var code = new SourceCode();
code.BracketStart("struct {0}", TypeName);
code.IndentRight();
foreach (var field in Fields.Values)
code.Append(field.GenerateModelCode());
if (HasContent)
code.Append("std::string {0};", IsNameContent ? "name" : "content");
if (NodeCount > 1)
{
code.NewLine();
code.Append("~{0}()", TypeName);
code.BracketStart();
foreach (var field in DataClassFields)
{
if (field.Class.HasId) code.Append("CLEAR_POINTER_MAP({0}, {1});", field.Class.CollectionTypeName, field.Class.CollectionName);
else code.Append("CLEAR_POINTER_LIST({0}, {1});", field.Class.TypeName, field.Class.CollectionName);
}
code.BracketEnd();
}
code.BracketEnd(";");
return code;
}