public static void AutoCSGenerate() { var rCSGenerate = new CSGenerate(); for (int nIndex = 0; nIndex < AutoCSGenerateTypes.Types.Count; ++nIndex) { var rType = AutoCSGenerateTypes.Types[nIndex]; EditorUtility.DisplayProgressBar("AutoCSGenerate...", string.Format("Process {0}...", rType.FullName), (float)nIndex / (float)AutoCSGenerateTypes.Types.Count); var rProcessInstance = ReflectExpand.TConstruct <AutoCSGenerate>(rType); if (null == rProcessInstance) { Debug.LogErrorFormat("AutoCSGenerateMain => {0} not use. need default construct", rType.FullName); continue; } try { rProcessInstance.CSGenerateProcess(rCSGenerate); } catch (System.Exception rException) { Debug.LogException(rException); } } rCSGenerate.UpdateCSFile((rText, fRate) => { EditorUtility.DisplayProgressBar("AutoCSGenerate", rText, fRate); }); EditorUtility.ClearProgressBar(); }
public virtual void CSGenerateProcess(CSGenerate rGenerate) { }
public override void CSGenerateProcess(CSGenerate rGenerate) { rGenerate.GeneratePath = GeneratePath; rGenerate.CsprojFile = CsprojFile; StartGenerateCommon(); foreach (var rType in SerializerBinaryTypes.Types) { var rText = new StringBuilder(); rText .A("using System.IO;").N() .A("using Core;").N() .A("using Core.Serializer;").N() .L(2) .A("/// <summary>").N() .A("/// 文件自动生成无需又该!如果出现编译错误,删除文件后会自动生成").N() .A("/// </summary>").N(); if (!string.IsNullOrEmpty(rType.Namespace)) { rText .F("namespace {0}", rType.Namespace).N() .A("{").N(); } rText .F("public partial class {0}", rType.Name).N() .A("{").N(); var rSerializeMemberInfo = SearchSerializeMember(rType); // Serialize Function rText .T(1).A("public override void Serialize(BinaryWriter rWriter)").N() .T(1).A("{").N() .T(2).A("base.Serialize(rWriter);").N(); foreach (var rMemberInfo in rSerializeMemberInfo) { var rParamText = GenerateClassMemberDummyText(rMemberInfo); if (rMemberInfo.IsDefined(typeof(SBDynamicAttribute), true) && !IsBaseType(GetMemberType(rMemberInfo), false)) { rText.T(2).F("rWriter.SerializeDynamic({0});", rParamText).N(); } else { rText.T(2).F("rWriter.Serialize({0});", rParamText).N(); } } rText .T(1).A("}").N(); // Deserialize Function rText .T(1).A("public override void Deserialize(BinaryReader rReader)").N() .T(1).A("{").N() .T(2).A("base.Deserialize(rReader);").N(); foreach (var rMemberInfo in rSerializeMemberInfo) { if (rMemberInfo.IsDefined(typeof(SBDynamicAttribute), false) && !IsBaseType(GetMemberType(rMemberInfo), false)) { rText.T(2).F("this.{0} = {1}rReader.DeserializeDynamic({2});", rMemberInfo.Name, GenerateClassMemberTypeText(rMemberInfo), GenerateClassMemberDummyText(rMemberInfo)).N(); } else { rText.T(2).F("this.{0} = {1}rReader.Deserialize({2});", rMemberInfo.Name, GenerateClassMemberTypeText(rMemberInfo), GenerateClassMemberDummyText(rMemberInfo)).N(); } } rText .T(1).A("}").N(); rText.A("}").N(); if (!string.IsNullOrEmpty(rType.Namespace)) { rText.A("}").N(); } var rGroupName = string.Empty; var rAttributes = new List <SBGroupAttribute>(); rAttributes.AddRange(rType.GetCustomAttributes <SBGroupAttribute>(true)); if (rAttributes.Count > 0) { rGroupName = rAttributes[0].GroupName; } rGenerate.Add(rText.ToString(), UtilTool.PathCombine(GeneratePath, rGroupName, rType.FullName + ".Binary.cs")); foreach (var rMemberInfo in rSerializeMemberInfo) { var bDynamic = rMemberInfo.IsDefined(typeof(SBDynamicAttribute), false); if (rMemberInfo.MemberType == MemberTypes.Field) { AnalyzeGenerateCommon((rMemberInfo as FieldInfo).FieldType, bDynamic); } else if (rMemberInfo.MemberType == MemberTypes.Property) { AnalyzeGenerateCommon((rMemberInfo as PropertyInfo).PropertyType, bDynamic); } } } EndGenerateCommon(); rGenerate.AddHead(mCommonSerializer.ToString(), CommonSerializerPath); }