Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Code generation

Discussion in 'Scripting' started by zehreken, Apr 25, 2022.

  1. zehreken

    zehreken

    Joined:
    Jun 29, 2009
    Posts:
    112
    Hey all, I'm trying to generate code from plain C# classes. This is a class generated from json schema file.

    Code (CSharp):
    1. public partial class Base
    2.     {
    3.         /// <summary>
    4.         /// Client Timestamp
    5.         /// </summary>
    6.         public DateTimeOffset? ClientTimestamp { get; set; }
    7.  
    8.         /// <summary>
    9.         /// Event ID
    10.         /// </summary>
    11.         public long? EventId { get; set; }
    12.  
    13.         /// <summary>
    14.         /// Event Name
    15.         /// </summary>
    16.         public string EventName { get; set; }
    17.  
    18.         public Geolocation? Geolocation { get; set; }
    19.  
    20.         /// <summary>
    21.         /// ID
    22.         /// </summary>
    23.         public Guid Id { get; set; }
    24.  
    25.         /// <summary>
    26.         /// Ingestion Timestamp
    27.         /// </summary>
    28.         public DateTimeOffset? IngestionTimestamp { get; set; }
    29.  
    30.         public User? User { get; set; }
    31.     }
    What I need to do next is generating a static method that has the properties of this class as parameters. I think I can do it manually by manipulating strings but I want to know if there is a better way to do this. Thanks in advance.
     
  2. nijnstein

    nijnstein

    Joined:
    Feb 6, 2021
    Posts:
    78
    i doubt that there is anything easier to use then string manipulation if you really want to generate static methods from json layout, i hope to stand corrected