本文整理汇总了C#中SourceCode.WriteToFile方法的典型用法代码示例。如果您正苦于以下问题:C# SourceCode.WriteToFile方法的具体用法?C# SourceCode.WriteToFile怎么用?C# SourceCode.WriteToFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SourceCode
的用法示例。
在下文中一共展示了SourceCode.WriteToFile方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateCpp
//.........这里部分代码省略.........
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)
{
_cppCode.Append("node->Attribute(\"{0}\", &{0});", attributeField.Name);
}
else
{
_cppCode.Append("attr_value = node->Attribute(\"{0}\");", attributeField.Name);
_cppCode.Append("if (attr_value != nullptr) {0} = boost::lexical_cast<{1}>(attr_value);", attributeField.Name,
TypeUtil.ToDeclareTypeName(attributeField.Type));
}
}
// non-primitive type은 child element로 값을 넣어준다.
if (nonPrimitives.Any())
{
_cppCode.BracketStart("for (TiXmlElement* each_node = node->FirstChildElement(); each_node != nullptr; each_node = each_node->NextSiblingElement())");
_cppCode.Append("const char* node_name = each_node->Value();");
foreach (var attributeField in nonPrimitives)
{
_cppCode.BracketStart("if (stricmp(\"{0}\", node_name) == 0)", attributeField.Name);
_cppCode.Append(
attributeField.Type == TypeEnum.STRING
? "{0} = std::string(each_node->GetText() != nullptr? each_node->GetText(): \"\");"
: "xml_custom_convert(each_node, &{0});", attributeField.Name);
_cppCode.BracketEnd();
}
_cppCode.BracketEnd();
}
_cppCode.BracketEnd();
}
}
#endregion
#region to_xml
{
_cppCode.Append("void {0}::to_xml(std::ostream& out)", attributeClass.StructName);
_cppCode.BracketStart();
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("out << \"<{0}/>\";", attributeClass.Name);
else
{
_cppCode.Append("out << \"<{0}\";", attributeClass.Name);
if (primitives.Any())
{
_cppCode.IndentRight();
// primitive type은 attribute로 값을 넣어준다.
foreach (var attributeField in primitives)
_cppCode.Append(@"out << "" {0}=\"""" << {0} << ""\"""";", attributeField.Name);
_cppCode.IndentLeft();
}
if (!nonPrimitives.Any())
_cppCode.Append("out << \"/>\";");
else
{
_cppCode.Append("out << \">\";");
_cppCode.IndentRight();
// non-primitive type은 child element로 값을 넣어준다.
foreach (var attributeField in nonPrimitives)
_cppCode.Append(@"out << ""<{0}>"" << {0} << ""</{0}>"";", attributeField.Name);
_cppCode.IndentLeft();
_cppCode.Append("out << \"</{0}>\";", attributeClass.Name);
}
}
_cppCode.Append("out << std::endl;");
_cppCode.BracketEnd();
}
#endregion
_cppCode.Append("#pragma endregion");
_cppCode.NewLine();
}
var cppFileName = Path.Combine(_outputDirectory, "bind_attributes.cpp");
_cppCode.WriteToFile(cppFileName);
}
示例2: GenerateHeaders
private void GenerateHeaders(AttributeClass attributeClass)
{
var code = new SourceCode();
code.Append("#pragma once");
code.NewLine();
code.Append("#include \"cbes/attribute.h\"");
code.NewLine();
code.BracketStart("struct {0} : public attribute_t<{0}>", attributeClass.StructName);
foreach (var attributeField in attributeClass.Fields)
{
code.Append("{2}{0} {1};", TypeUtil.ToDeclareTypeName(attributeField.Type), attributeField.Name, attributeField.Volatile ? "volatile " : "");
}
code.NewLine();
code.Append("// default constructor");
var constructorArgs = attributeClass.Fields.Select(
e => string.Format("{0}({1})", e.Name, e.Default ?? TypeUtil.ToDefaultValueInInitializer(e.Type))).ToList();
if (constructorArgs.Count > 0)
{
code.Append("{0}()", attributeClass.StructName);
code.IndentRight();
code.Append(": {0} {{}}", string.Join(", ", constructorArgs));
code.IndentLeft();
}
else code.Append("{0}() {{}}", attributeClass.StructName);
if (attributeClass.NonDefaultFields.Any())
{
code.NewLine();
code.Append("// argumented constructor");
var paramArgs = new List<string>();
var initializeArgs = new List<string>();
// default가 없는 field를 대상으로만 argumented constructor를 만들어준다.
foreach (var attributeField in attributeClass.Fields)
{
if (attributeField.Default == null)
{
paramArgs.Add(string.Format("{0} _{1}", TypeUtil.ToArgumentTypeName(attributeField.Type), attributeField.Name));
initializeArgs.Add(string.Format("{0}(_{0})", attributeField.Name));
}
else
{
initializeArgs.Add(string.Format("{0}({1})", attributeField.Name, attributeField.Default));
}
}
if (initializeArgs.Count > 0)
{
code.Append("{0}({1})", attributeClass.StructName, string.Join(", ", paramArgs));
code.IndentRight();
code.Append(": {0} {{}}", string.Join(", ", initializeArgs));
code.IndentLeft();
}
}
code.NewLine();
code.Append(SourceCode.Parse(@"
virtual void from_bson(bson_iterator*);
virtual void to_bson(bson*);
virtual void from_xml(TiXmlElement*);
virtual void to_xml(std::ostream&);".Trim()));
if (attributeClass.CustomCode != null)
{
code.NewLine();
code.Append(SourceCode.Parse(attributeClass.CustomCode));
}
code.BracketEnd(";");
code.Append("typedef boost::shared_ptr<{0}> {1};", attributeClass.StructName, attributeClass.ReferenceName);
code.NewLine();
var headerPath = Path.Combine(_outputDirectory, attributeClass.HeaderFileName);
code.WriteToFile(headerPath);
}
示例3: 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"));
}
示例4: 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>");
}
示例5: GenerateModelFile
private void GenerateModelFile()
{
Parallel.ForEach(DataCenter.Instance.Values, clazz =>
{
// generate header file
var header = new SourceCode();
header.Append("#pragma once");
header.Append("#include <data_def.h>");
header.Append("#include \"data_type_id.h\"");
header.Append("#include <data_center.h>");
header.Append(clazz.GenerateDependencyIncludeCode());
header.NewLine();
header.Append("namespace data { ;");
header.Append(clazz.GenerateModelCode());
header.NewLine();
header.Append("typedef data_center<{0}> {1}_data;", clazz.TypeName, clazz.SimpleName);
header.NewLine();
header.Append("#if DATA_RELOADABLE");
header.Append(clazz.GenerateReloaderImplCode());
header.Append("#endif");
header.NewLine();
header.Append("void __data_load(data_type_t<{0}>);", clazz.TypeName);
header.NewLine();
header.Append("}");
header.NewLine();
header.WriteToFile(Path.Combine(_outputDirectory, clazz.HeaderFileName));
});
}
示例6: Generate
public void Generate(string outputDirectory, string directionName)
{
var msgFileName = Path.Combine(outputDirectory, Name + "_msg.h");
var code = new SourceCode();
code.Append("#pragma once");
code.NewLine();
code.Append("#include <msg_def.h>");
code.Append("#include <msg_reader.h>");
code.Append("#include <msg_writer.h>");
code.Append("#include <msg_session_ref.h>");
code.NewLine();
code.Append("#pragma warning (disable: 4100)");
code.NewLine();
code.Append(GenerateMsgType());
code.Append("namespace msg {");
code.NewLine();
var context = new CodeContext();
foreach (var msg in SortedMessages)
{
code.BracketStart("struct {0}", msg.ClassName);
code.Append("static const msg_type_t __type = msg_type::{0};", msg.Name);
code.NewLine();
context.StartAccessor("msg");
msg.Fields.ForEach(field => code.Append(field.GenerateField(context)));
code.NewLine();
code.Append(msg.GenerateArgumentedConstructor());
code.Append(msg.Fields.GenerateDefaultConstructor(msg.ClassName));
code.Append(msg.GenerateHandlerDeclaration());
context.EndAccessor();
code.BracketEnd(";");
code.NewLine();
}
code.Append("}");
code.NewLine();
code.NewLine();
code.Append(GenerateReaderWriter(context));
code.NewLine();
code.NewLine();
code.Append("namespace msg {");
foreach (var msg in SortedMessages)
{
context.StartAccessor("msg");
code.Append(msg.GenerateHandlerBody(context));
context.EndAccessor();
code.NewLine();
}
code.Append("}");
code.NewLine();
if (!String.IsNullOrWhiteSpace(directionName))
{
code.Append(GenerateEntityBindCode(directionName));
code.NewLine();
}
code.NewLine();
code.Append("#pragma warning (default: 4100)");
code.WriteToFile(msgFileName);
}