public IShellCodeModelElement2 AddBase(string Base, int Position) { CodeElement ce = _codeClass.AddBase(Base, Position); return(ShellObjectFactory.CreateFromCodeElement(ce)); }
public static void Excute(CodeClass2 classElement, Dictionary<string, CodeClass2> dic, TyrantVSPackage package) { if (classElement == null) return; //var classCode = classElement.StartPoint.CreateEditPoint().GetText(classElement.GetEndPoint()); var validBases = new List<CodeElement>(); foreach (CodeElement baseClass in classElement.Bases) { if (!baseClass.FullName.StartsWith("Tyrant.GameCore.Message<") && baseClass.FullName != typeof(object).FullName) validBases.Add(baseClass); } var validInterfaces = new List<CodeElement>(); foreach (CodeElement implementedInterface in classElement.ImplementedInterfaces) { if (implementedInterface.FullName != "Tyrant.GameCore.ISerializable") { validInterfaces.Add(implementedInterface); break; } } var baseCollection = classElement.Collection; string name = classElement.Name; classElement.GetStartPoint(vsCMPart.vsCMPartHeader).CreateEditPoint().ReplaceText(classElement.GetStartPoint(vsCMPart.vsCMPartBody), $"public partial class {name}{Environment.NewLine}{{{Environment.NewLine}", (int)vsEPReplaceTextOptions.vsEPReplaceTextAutoformat); classElement = baseCollection.Item(name) as CodeClass2; classElement.AddImplementedInterface("Tyrant.GameCore.ISerializable"); foreach (CodeElement baseClass in validBases) { try { classElement.AddBase(baseClass, -1); } catch { } } foreach (CodeElement implementedInterface in validInterfaces) { try { classElement.AddImplementedInterface(implementedInterface, -1); } catch { } } CommunicationCodeHelper.RemoveMembers(classElement); CodeFunction2 serializeMethod = null, deserializeMethod = null; try { classElement.AddFunction("Tyrant.GameCore.ISerializable.Serialize", vsCMFunction.vsCMFunctionFunction, vsCMTypeRef.vsCMTypeRefVoid, -1, vsCMAccess.vsCMAccessDefault); } catch { } serializeMethod = classElement.Members.Item("Tyrant.GameCore.ISerializable.Serialize") as CodeFunction2; try { serializeMethod.AddParameter("dest", typeof(ProtoBuf.ProtoWriter).FullName); } catch { serializeMethod = classElement.Members.Item("Tyrant.GameCore.ISerializable.Serialize") as CodeFunction2; } try { classElement.AddFunction("Tyrant.GameCore.ISerializable.Deserialize", vsCMFunction.vsCMFunctionFunction, vsCMTypeRef.vsCMTypeRefVoid, -1, vsCMAccess.vsCMAccessDefault); } catch { } deserializeMethod = classElement.Members.Item("Tyrant.GameCore.ISerializable.Deserialize") as CodeFunction2; try { deserializeMethod.AddParameter("source", typeof(ProtoBuf.ProtoReader).FullName); } catch { deserializeMethod = classElement.Members.Item("Tyrant.GameCore.ISerializable.Deserialize") as CodeFunction2; } CommunicationCodeHelper.GenerateSerializaCode(classElement, serializeMethod, deserializeMethod, dic, package/*, "dest", "source"*/); }