public static string MakeClassInfoCreator(NativeRPC.ClassInfo cinfo) { //struct ClassInfoCreator_TestCppRPC //{ // ClassInfoCreator_TestCppRPC() // { // TestCppRPC obj; // RPCClassInfo& cinfo = *obj.GetRPCClassInfo(); // cinfo.mChildObjects[0] = offsetof(TestCppRPC,ChildObj0);//(int)((TestCppRPC*)(NULL))->ChildObj0; // cinfo.mMethods.push_back(&HExe_1213132112::Instance); // cinfo.mChildObjects.push_back(&HIndex_1213132112::Instance); // } //} obj_TestCppRPC; string strObjGetFn = ""; string strObj = ""; foreach (NativeRPC.ChildObjectInfo cobj in cinfo.ChildObjects) { //strObj += TabStr + TabStr + "cinfo.mChildObjects[" + cobj.Index + "] = offsetof(" + CSharp2CppType(cinfo.FullName) + "," + cobj.Name + ");" + EndLine; strObj += TabStr + TabStr + "cinfo.mFnChildObjects[" + cobj.Index + "] = Get_" + cobj.Name + ";" + EndLine; strObjGetFn += TabStr + "static CppRPC::RPCObject* Get_" + cobj.Name + "(CppRPC::RPCObject* host) { return ((" + CSharp2CppType(cinfo.FullName) + "*)host)->" + cobj.Name + ";}" + EndLine; } string strIndex = ""; foreach (NativeRPC.IndexerInfo idx in cinfo.Indexer) { strObj += TabStr + TabStr + "cinfo.mIndexers[ " + idx.Index + "] = CppRPC_ExecuterNamespace::HIndex_" + idx.GetIndexerHashCode() + "::Instance();" + EndLine; } string strMethod = ""; foreach (NativeRPC.MethodInfo mi in cinfo.Methods) { strObj += TabStr + TabStr + "cinfo.mMethods[ " + mi.Indexer + "] = CppRPC_ExecuterNamespace::HExe_" + mi.GetMethodHashCode() + "::Instance();" + EndLine; } string strOut = ""; strOut += "struct " + cinfo.ClassName + (UInt32)cinfo.FullName.GetHashCode() + EndLine; strOut += "{" + EndLine; strOut += strObjGetFn; strOut += TabStr + cinfo.ClassName + (UInt32)cinfo.FullName.GetHashCode() + "()" + EndLine; strOut += TabStr + "{" + EndLine; strOut += TabStr + TabStr + "CppRPC::RPCClassInfo& cinfo = *((" + CSharp2CppType(cinfo.FullName) + "*)NULL)->" + CSharp2CppType(cinfo.FullName) + "::GetRPCClassInfo();" + EndLine; strOut += strObj; strOut += strIndex; strOut += strMethod; strOut += TabStr + "}" + EndLine; strOut += "} dummyobj_" + (UInt32)cinfo.FullName.GetHashCode() + ";" + EndLine; return(strOut); }
public static string MakeClientClassCode(NativeRPC.ClassInfo cinfo) { string strOut = "#if CSharpCompliler" + EndLine; strOut += "namespace " + cinfo.Namespace + "{" + EndLine; strOut += "public class H_" + cinfo.ClassName + EndLine; strOut += "{" + EndLine; strOut += TabStr + "public static " + cinfo.Namespace + ".H_" + cinfo.ClassName + " smInstance = new " + cinfo.Namespace + ".H_" + cinfo.ClassName + "();" + EndLine; foreach (NativeRPC.MethodInfo mi in cinfo.Methods) { strOut += MakeCallCode(mi); } foreach (NativeRPC.ChildObjectInfo cobj in cinfo.ChildObjects) { strOut += MakeChildObjectCode(cobj); } foreach (NativeRPC.IndexerInfo idx in cinfo.Indexer) { strOut += MakeIndexObjectCode(idx); } strOut += "}" + EndLine; strOut += "}" + EndLine; strOut += "#else" + EndLine; strOut += "//以下是C++代码,产生执行器和绑定执行器" + EndLine; strOut += EndLine; strOut += "namespace CppRPC_ExecuterNamespace{" + EndLine; foreach (NativeRPC.MethodInfo mi in cinfo.Methods) { string code = MakeMethodExecuterCode(mi); code = code.Replace("System::", "CppSystem::"); strOut += code; } foreach (NativeRPC.IndexerInfo idx in cinfo.Indexer) { string code = MakeIndexerExecuterCode(idx); code = code.Replace("System::", "CppSystem::"); strOut += code; } strOut += "}" + EndLine; //strOut += MakeClassInfoCreator(cinfo); strOut += "#endif" + EndLine; return(strOut); }