本文整理汇总了C#中SourceCode.IndentLeft方法的典型用法代码示例。如果您正苦于以下问题:C# SourceCode.IndentLeft方法的具体用法?C# SourceCode.IndentLeft怎么用?C# SourceCode.IndentLeft使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SourceCode
的用法示例。
在下文中一共展示了SourceCode.IndentLeft方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: 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);
}
示例3: 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);
}
示例4: GenerateArgumentedConstructor
public SourceCode GenerateArgumentedConstructor()
{
// msg argumented constructor
var paramArgs = new List<string>();
var initializeArgs = new List<string>();
foreach (var field in Fields.OfType<SimpleField>())
{
paramArgs.Add(string.Format("{0} _{1}", TypeUtil.ToArgumentTypeName(field.Type), field.Name));
initializeArgs.Add(string.Format("{0}(_{0})", field.Name));
}
var code = new SourceCode();
if (initializeArgs.Count == 0)
return code;
code.Append("{0}({1})", ClassName, string.Join(", ", paramArgs));
code.IndentRight();
code.Append(": {0} {{}}", string.Join(", ", initializeArgs));
code.IndentLeft();
code.NewLine();
return code;
}