本文整理汇总了C#中SourceCode.StaticInitializerStart方法的典型用法代码示例。如果您正苦于以下问题:C# SourceCode.StaticInitializerStart方法的具体用法?C# SourceCode.StaticInitializerStart怎么用?C# SourceCode.StaticInitializerStart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SourceCode
的用法示例。
在下文中一共展示了SourceCode.StaticInitializerStart方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateCpp
private void GenerateCpp()
{
_cppCode = new SourceCode();
_cppCode.Append("#include \"{0}\"", Configuration.Stdafx);
foreach (var dependancy in new[] {"singleton.h", "cbes/attribute.h"})
_cppCode.Append("#include \"{0}\"", dependancy);
_cppCode.NewLine();
_cppCode.Append("#pragma warning (disable: 4189 4100 4505)");
_cppCode.NewLine();
foreach (var attributeClass in _attributes)
_cppCode.Append("#include \"{0}\"", attributeClass.HeaderFileName);
_cppCode.NewLine();
#region factory
_cppCode.Append("#pragma region /* factory-register */");
_cppCode.StaticInitializerStart();
foreach (var attributeClass in _attributes)
_cppCode.Append("sys<attribute_factory>().factory_map.insert(std::make_pair(\"{0}\", [=] () {{ return attribute_ref(new {1}); }}));", attributeClass.Name,
attributeClass.StructName);
_cppCode.StaticInitializerEnd();
_cppCode.Append("#pragma endregion");
_cppCode.NewLine();
#endregion
foreach (var attributeClass in _attributes)
{
_cppCode.Append("#pragma region /* {0} */", attributeClass.Name);
#region from_bson
{
var nonVolatiles = attributeClass.NonVolatileFields.ToArray();
if (nonVolatiles.Any())
{
_cppCode.Append("void {0}::from_bson(bson_iterator*)", attributeClass.StructName);
_cppCode.Append("{");
_cppCode.Append("}");
}
else
{
_cppCode.Append("void {0}::from_bson(bson_iterator* iterator)", attributeClass.StructName);
_cppCode.BracketStart();
_cppCode.BracketStart("while (bson_iterator_next(iterator))");
_cppCode.Append("const char* field_name = bson_iterator_key(iterator);");
_cppCode.Append("const char* field_value = bson_iterator_string(iterator);");
foreach (var attributeField in nonVolatiles)
{
_cppCode.Append("if (stricmp(\"{0}\", field_name) == 0) {0} = boost::lexical_cast<{1}>(field_value);",
attributeField.Name, TypeUtil.ToDeclareTypeName(attributeField.Type));
}
_cppCode.BracketEnd();
_cppCode.BracketEnd();
}
}
#endregion
#region to_bson
{
_cppCode.Append("void {0}::to_bson(bson* obj)", attributeClass.StructName);
_cppCode.BracketStart();
_cppCode.Append("bson_append_start_object(obj, \"{0}\");", attributeClass.Name);
foreach (var attributeField in attributeClass.NonVolatileFields)
{
_cppCode.Append("bson_append_string(obj, \"{0}\", boost::lexical_cast<std::string>({0}).c_str());",
attributeField.Name);
}
_cppCode.Append("bson_append_finish_object(obj);");
_cppCode.BracketEnd();
}
#endregion
#region from_xml
{
var nonVolatileFields = attributeClass.NonVolatileFields.ToArray();
var primitives = nonVolatileFields.Where(e => TypeUtil.IsPrimitiveType(e.Type)).ToArray();
var nonPrimitives = nonVolatileFields.Where(e => !TypeUtil.IsPrimitiveType(e.Type)).ToArray();
if (!primitives.Any() && !nonPrimitives.Any())
{
_cppCode.Append("void {0}::from_xml(TiXmlElement*)", attributeClass.StructName);
_cppCode.Append("{");
_cppCode.Append("}");
}
else
{
_cppCode.Append("void {0}::from_xml(TiXmlElement* node)", attributeClass.StructName);
_cppCode.BracketStart();
// primitive type은 attribute로 값을 넣어준다.
_cppCode.Append("const char* attr_value = nullptr;");
foreach (var attributeField in primitives)
{
if (attributeField.Type == TypeEnum.INT || attributeField.Type == TypeEnum.DOUBLE)
//.........这里部分代码省略.........
示例2: 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>");
}