LogFAQs > #909932545

LurkerFAQs, Active DB, DB1, DB2, DB3, Database 4 ( 07.23.2018-12.31.2018 ), DB5, DB6, DB7, DB8, DB9, DB10, DB11, DB12, Clear
Topic List
Page List: 1
TopicCool function I wrote
Yellow
10/04/18 5:30:34 AM
#1:


So, I'm making my own Windows Forms/Qt equivalent in MonoGame (a library pretty much meant for games only), and I just got done making a object-to-child-class code generator. Basically how Windows Forms adds new windows as classes to your code. I can't really explain it well, but it does this.

// My 'Animal' test class
....public class Animal
....{
........public Animal()
........{
........
........}
........public Animal(String name)
........{
............this.species = name;
........}
........public Animal(String name, int height)
........{
............this.species = name;
............this.height = height;
........}
........
........public string species;
........public int height;
....}

Animal goat = new Animal("Goat", 20);
String cs_file = CSCreator.SerializeToCS(goat, "Goat");
System.IO.File.WriteAllText(@"WriteText.txt", cs_file);


This will take goat and write to a CS file a class that inherits Animal, preserving all the fields as they were.

// All auto-generated
using DownUnder.Content.Utilities;
using DownUnder.Content.UI;

namespace DownUnder.Content.Utilities
{
....public class Goat : Animal
....{
........public Goat() : base() { species = "Goat"; height = 20; }
........public Goat(System.String name) : base(name) { name = "Goat"; height = 20; }
........public Goat(System.String name, System.Int32 height) : base(name, height) { name = "Goat"; height = 20; }

....}
}


//...
// After adding in the generated code
Goat my_goat = new Goat();
Debug.WriteLine("" + my_goat.species);


Goat

I feel like MS has made something like this and gave us access to it, (idk why else you would have such a functional Reflection system) and I just wrote this for no reason, but oh well. Anyone feel free to use my code without credit. Be careful though, if I recall @Judgmenl said I'm a huge idiot that doesn't know anything about programming.

Source
https://pastebin.com/WDLygCRs

@Sahuagin
... Copied to Clipboard!
Topic List
Page List: 1