internal void RepairCpp(bool repair, EntityConfig friend = null)
 {
     if (friend != null)
     {
         if (RepairTag(friend, Property.Parent.Option.ReferenceTag))
         {
             Property.CsType = CppTypeHelper2.CppTypeToCsType(Property);
         }
     }
     if (!repair)
     {
         //FindOld();
         CheckEnum();
         CheckStruct();
     }
 }
        private void CheckStruct()
        {
            if (Property.IsSystemField || Property.EnumConfig != null)
            {
                return;
            }
            if (Property.CppType == null)
            {
                Property.CppType = CppTypeHelper2.CsTypeToCppType(Property);
            }
            if (Property.CppLastType == null)
            {
                Property.CppLastType = Property.CppType;
            }

            var type = CppTypeHelper2.ToCppLastType(Property.CppType);

            if (type is EntityConfig entity)
            {
                Property.CppLastType = entity.Name;
                Property.CsType      = entity.Name + "Data";
                if (!entity.IsReference)
                {
                    return;
                }
                var friend = GetEntity(p => !p.IsReference && p != entity && p.Option.ReferenceTag == entity.Option.ReferenceTag);
                if (friend != null)
                {
                    Property.CppLastType = friend.Name;
                    Property.CsType      = friend.Name + "Data";
                }
                return;
            }

            if (type is TypedefItem typedef)
            {
                ReBindingEnum(typedef);
            }
            else
            {
                Property.CppLastType = type.ToString();
            }
        }
 /// <summary>
 ///     修复数组长度
 /// </summary>
 public void RepairByArrayLen()
 {
     if (CppTypeHelper2.ToCppLastType(Property.CppLastType) is TypedefItem type)
     {
         if (type.KeyWork == "char" && !string.IsNullOrWhiteSpace(type.ArrayLen))
         {
             try
             {
                 Property.Datalen = Int32.Parse(type.ArrayLen);
             }
             catch (Exception)
             {
                 Property.Datalen = 5000;
             }
         }
     }
     else if (!Property.Parent.IsReference && Property.CsType == "string" && Property.Datalen <= 0)
     {
         Property.Datalen = 500;
     }
 }
        /// <summary>
        ///     自动修复(从模型修复数据存储)
        /// </summary>
        public void RepairCpp(bool repair = false)
        {
            if (Entity.IsFreeze)
            {
                return;
            }
            if (Entity.IsReference)
            {
                if (repair)
                {
                    foreach (var col in Entity.Properties)
                    {
                        col.CppLastType = CppTypeHelper2.CppLastType(col.CppType);
                    }
                }
                return;
            }
            RepairEsName(repair);

            EntityConfig friend = GetEntity(p => p != Entity && p.Option.ReferenceTag == Entity.Option.ReferenceTag);

            PropertyBusinessModel model = new PropertyBusinessModel();

            foreach (var col in Entity.Properties)
            {
                if (col.IsDiscard || Entity.IsFreeze)
                {
                    continue;
                }
                col.Parent     = Entity;
                model.Property = col;
                model.RepairCpp(repair, friend);
                col.IsModify = true;
            }
            Entity.IsModify = true;
        }
        internal bool RepairTag(EntityConfig friend, string head)
        {
            if (Property.IsSystemField)
            {
                Property.Option.ReferenceTag = "[SYSTEM]";
                return(false);
            }
            if (friend == null)
            {
                Property.Option.ReferenceTag = null;
                return(false);
            }
            string tag  = Property.Option.ReferenceTag ?? "";
            var    link = friend.Properties.FirstOrDefault(p => tag == p.Option.ReferenceTag) ??
                          friend.Properties.FirstOrDefault(p => p.Name == Property.Name);

            if (link == null)
            {
                Property.Option.ReferenceTag = null;
                //Property.CppName = null;
                if (Property.EnumConfig != null && Property.EnumConfig.Items.Count <= 1)
                {
                    Property.EnumConfig.Option.IsDelete = true;
                    Property.EnumConfig = null;
                    Property.CustomType = null;
                }
                else if (Property.EnumConfig == null && Property.CustomType != null)
                {
                    Property.CustomType = null;
                }
                return(false);
            }
            tag = head + "," + link.CppType + "," + link.Name;
            if (friend.Option.ReferenceTag != null && friend.Option.ReferenceTag.Contains(tag + ",[Skip]"))
            {
                return(false);
            }
            Property.Option.ReferenceTag = tag;
            var cpptype = CppTypeHelper2.ToCppLastType(link.CppType);

            if (cpptype is EntityConfig stru)
            {
                link.CppLastType = Property.CppType = GetEntity(p => p.Option.ReferenceTag == stru.Option.ReferenceTag && p != stru)?.Name;
                return(true);
            }
            if (!(cpptype is TypedefItem type))
            {
                Property.CppType     = link.CppType;
                Property.CppLastType = link.CppType;
                return(true);
            }
            Property.CppType     = type.KeyWork;
            Property.CppLastType = type.KeyWork;
            if (type.ArrayLen != null)
            {
                if (type.KeyWork == "char" && !string.IsNullOrWhiteSpace(type.ArrayLen))
                {
                    if (Int32.TryParse(type.ArrayLen, out int len))
                    {
                        link.Datalen     = len;
                        Property.Datalen = len;
                    }
                    else
                    {
                        link.Datalen     = 100;
                        Property.Datalen = 100;
                        link.ArrayLen    = type.ArrayLen;
                    }
                }
                else
                {
                    link.ArrayLen     = type.ArrayLen;
                    Property.ArrayLen = type.ArrayLen;
                }
            }

            if (type.Items.Count <= 0)
            {
                Property.EnumConfig = null;
                Property.CustomType = null;
                return(true);
            }
            ReBindingEnum(type);
            return(false);
        }