コード例 #1
0
ファイル: CodeGen.cs プロジェクト: chismar/MyNetworkEngine
 public static string GetTagForProp(string propName, int offset)
 {
     return(((int)(Crc64CodeGen.Compute(propName) & int.MaxValue) + 1).ToString());
 }
コード例 #2
0
ファイル: CodeGen.cs プロジェクト: chismar/MyNetworkEngine
        private IEnumerable <MemberDeclarationSyntax> GenerateMessage(SemanticModel model, MethodDeclarationSyntax method, string className)
        {
            List <MsgArg> args = new List <MsgArg>();

            foreach (var param in method.ParameterList.Parameters)
            {
                args.Add(new MsgArg()
                {
                    Name = param.Identifier.ValueText, Type = param.Type.ToString(), Ghost = InheritsFrom("NetworkEngine.SyncObject", model.GetTypeInfo(param.Type).Type)
                });
            }
            var scriptObject = new ScriptObject();

            scriptObject.Import(new { Entity = className, Method = method.Identifier.ValueText, Class = className, Arguments = args, Id = (int)Crc64CodeGen.Compute((className + method.Identifier.ValueText)) });
            scriptObject.Import(nameof(PutToStreamFromType), (Func <bool, string, string, string>)((b, str, str2) => PutToStreamFromType(b, str, str2)));
            scriptObject.Import(nameof(GetFromStreamFromType), (Func <bool, string, string, string>)((b, str, str2) => GetFromStreamFromType(b, str, str2)));
            scriptObject.Import(nameof(GetTagForProp), (Func <string, int, string>)((str, i) => GetTagForProp(str, i)));
            var code = _messageTemplate.Render(scriptObject); var syntaxTree = CSharpSyntaxTree.ParseText(code);
            var cds = syntaxTree.GetRoot().DescendantNodesAndSelf().OfType <ClassDeclarationSyntax>();

            //foreach (var cd in cds.ToArray())
            //    cds = cds.Concat(new[] { GenerateSyncObjClass(model, cd) });
            return(cds);
        }