CN116483376A - Automatic generation method, system and storage medium for C# code - Google Patents

Automatic generation method, system and storage medium for C# code Download PDF

Info

Publication number
CN116483376A
CN116483376A CN202310494683.XA CN202310494683A CN116483376A CN 116483376 A CN116483376 A CN 116483376A CN 202310494683 A CN202310494683 A CN 202310494683A CN 116483376 A CN116483376 A CN 116483376A
Authority
CN
China
Prior art keywords
code
automatic generation
generation method
unity
steps
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202310494683.XA
Other languages
Chinese (zh)
Other versions
CN116483376B (en
Inventor
刘瑞祥
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guangzhou Zhengshi Network Technology Co ltd
Original Assignee
Guangzhou Zhengshi Network Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Guangzhou Zhengshi Network Technology Co ltd filed Critical Guangzhou Zhengshi Network Technology Co ltd
Priority to CN202310494683.XA priority Critical patent/CN116483376B/en
Publication of CN116483376A publication Critical patent/CN116483376A/en
Application granted granted Critical
Publication of CN116483376B publication Critical patent/CN116483376B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/52Binary to binary
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

The invention relates to an automatic generation method of a C# code, which comprises the following steps: s1, analyzing a target intermediate language; s2, generating an abstract syntax tree; s3, extracting metadata information; s4, generating a C# byte code corresponding to the metadata description mode; s5, merging the target intermediate language back to the target binary system; s6, updating meta-table information. The automatic generation method of the C# code adopts the source code to the C# byte code, namely the text to the binary system, the subsequent maintenance and modification are based on the old code before generation, the code volume is small, and the maintenance time is reduced.

Description

Automatic generation method, system and storage medium for C# code
Technical Field
The invention relates to the technical field of computers, in particular to an automatic generation method, an automatic generation system and a storage medium for a C# code.
Background
Currently, code automatic generation frameworks provided by the prior art include a Unity framework, a Spring framework and a guide framework.
Existing frames of this type are limited in that: techniques based on reflection class are implemented by analyzing metadata, scanning class (object) structures, and then dynamically creating instances when the program is executed.
There are two limitations: 1. the effective stage is positioned at the time of starting the software, so that the starting time of the target program can be linearly increased along with the increase of the code quantity; 2. the cross-platform cannot be used, and the C# language can generate an executable program aiming at a main stream operating system; however, some platforms may disable features such as reflection based on security or other considerations, such as apple Ios systems, and cross-platform application development may not be possible using existing frameworks.
There are also a few minor problems such as: 1. such a framework itself would be part of the program, compiled into the target software, adding additional application volume; 2. the frames can be internally provided with the container at the same time, so that the effect of simply adding functions without using the frames as the container cannot be realized.
Disclosure of Invention
The invention provides an automatic generation method of a C# code, which reduces the code scale required to be written manually on the premise of not changing the function, does not increase the cost of software in the running process, does not influence the cross-platform property of the software and does not generate invasiveness to the original code.
In order to achieve the aim of the invention, the technical scheme adopted is as follows:
the automatic generation method of the C# code comprises the following steps:
s1, analyzing a target intermediate language;
s2, generating an abstract syntax tree;
s3, extracting metadata information;
s4, generating a C# byte code corresponding to the metadata description mode;
s5, merging the target intermediate language back to the target binary system;
s6, updating meta-table information.
Preferably, in the step S4, generating the c# bytecode corresponding to the metadata description mode specifically includes:
and generating a C# byte code based on the metadata information, inserting the C# byte code into the original C# byte code, calculating the address offset after insertion, and updating the offset information in the original C# byte code.
Preferably, in the step S6, updating the meta table information specifically includes:
updating the meta-table information, deleting the meta-information of the custom attribute, updating the symbol table, adding the information of the newly generated code, and storing the target binary again.
Preferably, before executing the steps S1 to S6, the method further comprises the following steps:
1) Introducing a C# code automatic generation method into a Unity project;
2) Associating the call of the automatic generation method of the C# code to the C# compiling flow in the Unity;
3) Writing a business code;
4) The Unity auto-compile time triggers the hook function defined in step 2).
Preferably, in the step 1), the automatic generation method of the c# code is introduced into the Unity engineering in two different forms of dll or Unity package.
Preferably, in the step 2), the method for automatically generating c# code call is associated to a c# compiling flow in Unity, and specifically includes:
21 Add Editor code and register the complexation pipeline hook function of the Unity Editor API;
22 A compiled target dll name is specified in the hook function, and the call of the automatic generation method of the C# code is executed.
Preferably, in the step 3), writing the service code specifically includes:
31 Defining a field, named customerId;
32 Calling a property on the customerId and entering the type of event.
Meanwhile, the invention also provides a system for automatically generating the C# code, which comprises a memory and a processor, wherein a program is stored in the memory, and the method steps of the method are executed when the program is executed by the processor.
In addition, the invention also provides a storage medium comprising a memory, wherein the memory stores a program, and the program executes the method steps of the method when being executed by a processor.
Compared with the prior art, the invention has the beneficial effects that:
(1) The automatic generation method of the C# code adopts the source code to the C# byte code, namely the text to the binary system, the subsequent maintenance and modification are based on the old code before generation, the code volume is small, and the maintenance time is reduced.
(2) The automatic generation method of the C# code provided by the invention does not increase the cost of the software in the running process, does not influence the cross-platform property of the software and does not generate invasiveness to the original code.
Drawings
In order to more clearly illustrate the embodiments of the invention or the technical solutions of the prior art, the drawings which are used in the description of the embodiments or the prior art will be briefly described, it being obvious that the drawings in the description below are only some embodiments of the invention, and that other drawings can be obtained from these drawings without inventive faculty for a person skilled in the art.
Fig. 1 is a flow chart of an automatic c# code generation method.
Fig. 2 is a schematic diagram of the structure of the c# code automatic generation system.
Description of the embodiments
In order to make the objects, features and advantages of the present invention more comprehensible, the technical solutions in the embodiments of the present invention are described in detail below with reference to the accompanying drawings, and it is apparent that the embodiments described below are only some embodiments of the present invention, but not all embodiments of the present invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
Examples
Fig. 1 is a schematic flow chart of the method for automatically generating c# codes. In this embodiment, the method for automatically generating c# code is applied to a standard c# item, and the method for automatically generating c# code is directly executed in a compiling script, as shown in fig. 1, and includes the following steps:
the automatic generation method of the C# code comprises the following steps:
s1, analyzing a target intermediate language;
s2, generating an abstract syntax tree;
s3, extracting metadata information;
s4, generating a C# byte code corresponding to the metadata description mode;
s5, merging the target intermediate language back to the target binary system;
s6, updating meta-table information.
In a specific implementation process, the step S2 is equivalent to the inverse process of the compiling step executed by the back end of each language compiler, and the intermediate code or machine code is regenerated by generating an AST (abstract syntax tree) through source code during software compiling. To obtain the original code organization structure, the abstract syntax tree needs to be obtained in reverse direction.
In a specific implementation process, in the step S3, the user-defined attribute is also generated as a part of the metadata by the compiler of c# to the target IL (intermediate language). The attribute information is extracted as raw data for generating an OpCode (c# bytecode) next.
In a specific implementation process, in the step S4, generating the c# bytecode corresponding to the metadata description mode specifically includes:
and generating a C# byte code based on the metadata information, inserting the C# byte code into the original C# byte code, calculating the address offset after insertion, and updating the offset information in the original C# byte code.
In a specific implementation process, in step S6, updating meta-table information specifically includes:
updating the meta-table information, deleting the meta-information of the custom attribute, updating the symbol table, adding the information of the newly generated code, and storing the target binary again.
Examples
The automatic generation method of the C# code of the embodiment is applied to the Unity item, the Unity item is provided with a custom compiling flow, a compiling link for embedding the C# code exists in the middle, and the method is more complex than the standard C# item. Specifically, the method comprises the following steps:
1) And introducing the automatic generation method of the C# code into the Unity engineering.
In the step 1), the automatic generation method of the C# code is introduced into the Unity engineering in two different forms of dll and Unity package.
2) And associating the C# code automatic generation method call into a C# compiling flow in the Unity.
In step 2), the method for automatically generating the C# code is related to the C# compiling flow in the Unity, and specifically comprises the following steps:
21 Add Editor code and register the complexation pipeline hook function of the Unity Editor API;
22 A compiled target dll name is specified in the hook function, and the call of the automatic generation method of the C# code is executed.
3) And writing service codes.
In the step 3), writing the service code specifically includes:
31 Defining a field, named customerId;
32 Calling a property on the customerId and entering the type of event.
The automatic generation method of the C# code does not need to specially define an event, and does not need to specially define a setter to pack a field and manually call an event dispatching method.
4) The Unity auto-compile time triggers the hook function defined in step 2).
5) Method steps of the c# code automatic generation method of embodiment 1 are performed.
Examples
The present embodiment provides an automatic c# code generating system, as shown in fig. 2, including a memory and a processor, where the memory stores a program, and when the program is executed by the processor, the method steps of the method described in embodiment 1 are executed.
Examples
The present embodiment provides a storage medium including a memory having a program stored therein, which when executed by a processor, performs the method steps of the method of embodiment 1.
In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods may be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative, e.g., the division of the units is merely a logical function division, and there may be additional divisions when actually implemented, e.g., multiple units or components may be combined or integrated into another system, or some features may be omitted or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be an indirect coupling or communication connection via some interfaces, devices or units, which may be in electrical, mechanical or other form.
The units described as separate units may or may not be physically separate, and units shown as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional unit in the embodiments of the present invention may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit. The integrated units may be implemented in hardware or in software functional units.
The integrated units, if implemented in the form of software functional units and sold or used as stand-alone products, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied essentially or in part or all of the technical solution or in part in the form of a software product stored in a storage medium, including instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a usb disk, a removable hard disk, a Read-only memory (ROM), a random access memory (RAM, randomAccessMemory), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
The above embodiments are only for illustrating the technical solution of the present invention, and not for limiting the same; although the invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims (9)

  1. The automatic generation method of the C# code is characterized by comprising the following steps of: the method comprises the following steps:
    s1, analyzing a target intermediate language;
    s2, generating an abstract syntax tree;
    s3, extracting metadata information;
    s4, generating a C# byte code corresponding to the metadata description mode;
    s5, merging the target intermediate language back to the target binary system;
    s6, updating meta-table information.
  2. 2. The c# code automatic generation method of claim 1, wherein: in the step S4, the generating the c# bytecode corresponding to the metadata description mode specifically includes:
    and generating a C# byte code based on the metadata information, inserting the C# byte code into the original C# byte code, calculating the address offset after insertion, and updating the offset information in the original C# byte code.
  3. 3. The c# code automatic generation method of claim 2, wherein: in the step S6, updating the meta-table information specifically includes:
    updating the meta-table information, deleting the meta-information of the custom attribute, updating the symbol table, adding the information of the newly generated code, and storing the target binary again.
  4. 4. A c# code automatic generation method according to any of claims 1-3, wherein: before executing the steps S1-S6, the method further comprises the following steps:
    1) Introducing a C# code automatic generation method into a Unity project;
    2) Associating the call of the automatic generation method of the C# code to the C# compiling flow in the Unity;
    3) Writing a business code;
    4) The Unity auto-compile time triggers the hook function defined in step 2).
  5. 5. The c# code automatic generation method of claim 4, wherein: in the step 1), the automatic generation method of the C# code is introduced into the Unity engineering in two different forms of dll and Unity package.
  6. 6. The c# code automatic generation method of claim 5, wherein: in the step 2), the method for automatically generating the C# code is related to the C# compiling flow in the Unity, and specifically comprises the following steps:
    21 Add Editor code and register the complexation pipeline hook function of the Unity Editor API;
    22 A compiled target dll name is specified in the hook function, and the call of the automatic generation method of the C# code is executed.
  7. 7. The c# code automatic generation method of claim 6, wherein: in the step 3), writing the service code specifically includes:
    31 Defining a field, named customerId;
    32 Calling a property on the customerId and entering the type of event.
  8. 8. The automatic generation system of C# code, including memory and processor, the said memory stores the procedure, its characteristic lies in: the program, when executed by the processor, performs the method steps of the method of any of claims 1-7.
  9. 9. A storage medium comprising a memory, the memory having a program stored therein, characterized in that: the program, when executed by a processor, performs the method steps of the method of any of claims 1-7.
CN202310494683.XA 2023-05-05 2023-05-05 Automatic generation method, system and storage medium for C# code Active CN116483376B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310494683.XA CN116483376B (en) 2023-05-05 2023-05-05 Automatic generation method, system and storage medium for C# code

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310494683.XA CN116483376B (en) 2023-05-05 2023-05-05 Automatic generation method, system and storage medium for C# code

Publications (2)

Publication Number Publication Date
CN116483376A true CN116483376A (en) 2023-07-25
CN116483376B CN116483376B (en) 2023-10-03

Family

ID=87219344

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310494683.XA Active CN116483376B (en) 2023-05-05 2023-05-05 Automatic generation method, system and storage medium for C# code

Country Status (1)

Country Link
CN (1) CN116483376B (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20210034356A1 (en) * 2018-03-29 2021-02-04 Netease (Hangzhou) Network Co.,Ltd. Code Hot-Update Method and Device, Storage Medium, Processor, and Terminal
CN113778848A (en) * 2021-01-29 2021-12-10 北京沃东天骏信息技术有限公司 Test code generation method, device, computer system and medium
CN113849781A (en) * 2021-08-20 2021-12-28 苏州浪潮智能科技有限公司 Go language source code obfuscation method, system, terminal and storage medium
CN115080011A (en) * 2022-06-23 2022-09-20 北京志凌海纳科技有限公司 Code generation method and system based on abstract syntax tree

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20210034356A1 (en) * 2018-03-29 2021-02-04 Netease (Hangzhou) Network Co.,Ltd. Code Hot-Update Method and Device, Storage Medium, Processor, and Terminal
CN113778848A (en) * 2021-01-29 2021-12-10 北京沃东天骏信息技术有限公司 Test code generation method, device, computer system and medium
CN113849781A (en) * 2021-08-20 2021-12-28 苏州浪潮智能科技有限公司 Go language source code obfuscation method, system, terminal and storage medium
CN115080011A (en) * 2022-06-23 2022-09-20 北京志凌海纳科技有限公司 Code generation method and system based on abstract syntax tree

Also Published As

Publication number Publication date
CN116483376B (en) 2023-10-03

Similar Documents

Publication Publication Date Title
US8464234B2 (en) Pre-parsed headers for compilation
US10353702B2 (en) Source code element signatures
US7962919B2 (en) Apparatus and method for modifying an initial event queue for extending an XML processor's feature set
US9182953B2 (en) Hybrid dynamic code compiling device, method, and service system thereof
US20150128114A1 (en) Parser
US20190146777A1 (en) Method and apparatus for generating patch
CN110795091B (en) Modularized route decoupling method, storage medium, electronic equipment and system
CN106850650B (en) Method for accessing data by game client and client game system
CN103440285A (en) Large-scale mobile phone game system and database updating method of large-scale mobile phone game system
CN111240772A (en) Data processing method and device based on block chain and storage medium
CN110888972A (en) Sensitive content identification method and device based on Spark Streaming
CN116483376B (en) Automatic generation method, system and storage medium for C# code
CN113204593A (en) ETL job development system and computer equipment based on big data calculation engine
CN110347416B (en) Script updating method and device
CN114816363A (en) MyBatis-based data service API implementation method and device
CN114356379A (en) Backup-based service upgrading method, device, equipment and storage medium
CN111399842B (en) Code compiling method and device
CN114398282A (en) Test script generation method, device, equipment and storage medium
CN114706586A (en) Code compiling method, code running method, code compiling device, code running device, computer equipment and storage medium
US10452592B1 (en) Message bus-based streaming rules engine
CN108628909B (en) Information pushing method and device
CN111400396A (en) Method and device for generating data synchronization script and computer readable storage medium
EP4064037A1 (en) Method for compilation, apparatus for compilation, electronic device, storage medium, and program product
CN113641422A (en) File generation method and device, electronic equipment and computer readable medium
CN116185406A (en) TaroJS ecological global injection plug-in method

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant