当前位置: 首页>>代码示例>>C#>>正文


C# SourceCode.BracketEnd方法代码示例

本文整理汇总了C#中SourceCode.BracketEnd方法的典型用法代码示例。如果您正苦于以下问题:C# SourceCode.BracketEnd方法的具体用法?C# SourceCode.BracketEnd怎么用?C# SourceCode.BracketEnd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SourceCode的用法示例。


在下文中一共展示了SourceCode.BracketEnd方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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;
 }
开发者ID:ktj007,项目名称:mmo,代码行数:12,代码来源:RefListField.cs

示例2: 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;
 }
开发者ID:ktj007,项目名称:mmo,代码行数:13,代码来源:ListField.cs

示例3: 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;
 }
开发者ID:ktj007,项目名称:mmo,代码行数:13,代码来源:RefListField.cs

示例4: 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;
        }
开发者ID:ktj007,项目名称:mmo,代码行数:15,代码来源:ListField.cs

示例5: 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;
        }
开发者ID:ktj007,项目名称:mmo,代码行数:19,代码来源:RefListField.cs

示例6: 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);
        }
开发者ID:ktj007,项目名称:mmo,代码行数:77,代码来源:AttributeCodeGenerator.cs

示例7: 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;
        }
开发者ID:ktj007,项目名称:mmo,代码行数:19,代码来源:ListField.cs

示例8: 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>");
        }
开发者ID:ktj007,项目名称:mmo,代码行数:69,代码来源:DataCodeGenerator.cs

示例9: GenerateHandlerBody

        public SourceCode GenerateHandlerBody(CodeContext context)
        {
            var code = new SourceCode();
            code.Append("inline void {0}::handle(msg_session_ref session, const type& msg)", CanonicalName);
            code.BracketStart();
            code.Append("_ASSERT(_handler != NULL);");
            code.Append("_handler(session, msg);");
            Fields.ForEach(field => code.Append(field.GenerateHandler(context)));
            code.BracketEnd();
            code.NewLine();

            code.Append("inline void {0}::handle(msg_session_ref session, msg_reader reader)", CanonicalName);
            code.BracketStart();
            var accessor = context.StartAccessor("msg");
            {
                code.Append("{0} {1};", ClassName, accessor);
                code.Append("reader >> {0};", accessor);
                code.Append("handle(session, {0});", accessor);
            }
            context.EndAccessor();
            code.BracketEnd();
            code.NewLine();

            code.Append("inline void {0}::broadcast(const type& msg)", CanonicalName);
            code.BracketStart();
            context.StartAccessor("msg");
            {
                code.Append(CodeUtil.ForEachCode("listener_list", "_listeners.", "iter", false));
                code.IndentRight();
                // not-recursive ref
                code.Append("(*iter)(msg);");
                code.BracketEnd();
            }
            context.EndAccessor();
            code.BracketEnd();
            return code;
        }
开发者ID:ktj007,项目名称:mmo,代码行数:37,代码来源:Message.cs

示例10: GenerateParseCode

        public SourceCode GenerateParseCode()
        {
            var code = new SourceCode();
            code.Append(GenerateParsePrototypeCode());
            code.BracketStart();
            {
                code.Append("if (root_node == nullptr) return;");
                code.BracketStart("for (TiXmlElement* each_node = root_node->FirstChildElement(); each_node != nullptr; each_node = each_node->NextSiblingElement())");
                {
                    code.Append("{0}* ptr = new {0};", QualifiedTypeName);

                    foreach (var field in Fields.Values)
                        code.Append(field.GenerateParseCode());

                    if (HasContent)
                        code.Append("ptr->{0} = std::string(each_node->GetText() != nullptr? each_node->GetText(): \"\");", IsNameContent ? "name" : "content");

                    code.NewLine();
                    if (IsTopMost)
                        code.Append("{0}_data::add(ptr);", SimpleName);
                    else
                    {
                        code.Append(HasId ? "parent->{0}.insert(std::make_pair(ptr->id, ptr));" : "parent->{0}.push_back(ptr);", CollectionName);
                    }

                    if (NeedLinker)
                        code.NewLine();

                    foreach (var field in ReferenceFields)
                        code.Append(field.GenerateParseRefCode());
                }
                code.BracketEnd();
            }
            code.BracketEnd();

            foreach (var field in DataClassFields)
                code.Append(field.GenerateParseBodyCode());
            return code;
        }
开发者ID:ktj007,项目名称:mmo,代码行数:39,代码来源:DataClass.cs

示例11: GenerateMsgType

        private SourceCode GenerateMsgType()
        {
            var code = new SourceCode();
            code.BracketStart("namespace msg_type");

            var msgSerial = 0;
            foreach (var msg in Messages)
            {
                code.Append("const msg_type_t {0} = {1};", msg.Name, _id*1000 + msgSerial);
                ++msgSerial;
            }
            code.BracketEnd();
            code.NewLine();
            code.NewLine();
            return code;
        }
开发者ID:ktj007,项目名称:mmo,代码行数:16,代码来源:MessageGroup.cs

示例12: GenerateParseCode

 public override SourceCode GenerateParseCode()
 {
     var code = new SourceCode();
     switch (ValueType)
     {
         case TypeEnum.BOOL:
             code.BracketStart();
             code.Append("const char* _temp = each_node->Attribute(\"{0}\");", CanonicalName);
             code.Append("ptr->{0} = _temp == nullptr? false: boost::lexical_cast<bool>(_temp);", CanonicalName);
             code.BracketEnd();
             break;
         case TypeEnum.DATA_ENUM:
             code.BracketStart();
             code.Append("const char* _temp = each_node->Attribute(\"{0}\");", CanonicalName);
             foreach (var value in Values.Distinct())
                 code.Append("if (stricmp(_temp, \"{2}\") == 0) ptr->{0} = {1}::{2};", CanonicalName, OwnedClass.QualifiedTypeName, value.Substring(1).ToEnumName());
             // remove leading _ char
             code.BracketEnd();
             break;
         case TypeEnum.DATA_ID:
         case TypeEnum.INT:
         case TypeEnum.DOUBLE:
             code.Append("each_node->Attribute(\"{0}\", &ptr->{0});", CanonicalName);
             break;
         case TypeEnum.DATA_POS:
             code.Append("parse_data_xyz(each_node->Attribute(\"{0}\"), &ptr->{0});", CanonicalName);
             break;
         case TypeEnum.STRING:
             code.Append("ptr->{0} = std::string(each_node->Attribute(\"{0}\"));", CanonicalName);
             break;
         case TypeEnum.DATA_REFERENCE:
             code.Append("ptr->{0} = nullptr;", CanonicalName);
             break;
         case TypeEnum.DATA_EXPRESSION:
             code.Append("ptr->{0} = expression_parser_t(each_node->Attribute(\"{0}\")).result();", CanonicalName);
             break;
     }
     return code;
 }
开发者ID:ktj007,项目名称:mmo,代码行数:39,代码来源:SimpleDataField.cs

示例13: GenerateModelCode

 public override SourceCode GenerateModelCode()
 {
     var code = new SourceCode();
     if (ValueType == TypeEnum.DATA_ENUM)
     {
         code.BracketStart("enum {0}", EnumTypeName);
         foreach (var value in Values.Distinct())
             code.Append("{0},", value.Substring(1).ToEnumName()); // remove leading _ char
         code.BracketEnd(";");
     }
     code.Append("{0} {1};", TypeString, CanonicalName);
     return code;
 }
开发者ID:ktj007,项目名称:mmo,代码行数:13,代码来源:SimpleDataField.cs

示例14: 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)
//.........这里部分代码省略.........
开发者ID:ktj007,项目名称:mmo,代码行数:101,代码来源:AttributeCodeGenerator.cs

示例15: GenerateReaderWriter

        private SourceCode GenerateReaderWriter(CodeContext context)
        {
            var code = new SourceCode();
            code.Append("#pragma region /* reader & writer */");
            code.NewLine();

            foreach (var msg in SortedMessages)
            {
                var accessor = context.StartAccessor("msg");

                code.Append("template <>");
                code.Append("inline msg_writer& msg_writer::operator << (const {0}& {1})", msg.CanonicalName, accessor);
                code.BracketStart();
                code.Append("(*this) << {0};", msg.MessageTypeName);

                msg.Fields.ForEach(field => code.Append(field.GenerateWriter(context)));
                code.Append("return (*this);");
                code.BracketEnd();
                code.NewLine();

                code.Append("template <>");
                code.Append("inline msg_reader& msg_reader::operator >> ({0}& {1})", msg.CanonicalName, accessor);
                code.BracketStart();
                msg.Fields.ForEach(field => code.Append(field.GenerateReader(context)));
                code.Append("return (*this);");
                code.BracketEnd();
                code.NewLine();

                context.EndAccessor();
            }
            code.Append("#pragma endregion");
            return code;
        }
开发者ID:ktj007,项目名称:mmo,代码行数:33,代码来源:MessageGroup.cs


注:本文中的SourceCode.BracketEnd方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。