0

The same way I can make a "instance" of a generic method of a certain type (MethodInfo mod = methodInfo.MakeGenericMethod(acc.GetType())), can the same be done to classes? Can those runtime generated classes also be non-abstract? I want this so that I don't have to write this at the end of my files:

public class BonusEdibilityFromNutrients : BonusValuesToEdibility<EffectsAffectsNutrients, NutrientProcessor.Nutrients, NutrientsMinMax> {
}
public class BonusEdibilityFromTastes : BonusValuesToEdibility<EffectsAffectsTastes, TasteProcessor.Tastes, TastesMinMax> {
}
public class BonusEdibilityFromAroma : BonusValuesToEdibility<EffectsAffectsAroma, AromaProcessor.Aroma, AromaMinMax> {
}
public class BonusEdibilityFromComposition : BonusValuesToEdibility<EffectsAffectsComposition, CompositionProcessor.Composition, DummyMinMax2> {
}
public class BonusEdibilityFromCookProperties : BonusValuesToEdibility<EffectsAffectsCookProperties, CookPropertiesProcessor.CookProperties, DummyMinMax1> {
}
public class BonusEdibilityFromQuality : BonusValuesToEdibility<EffectsAffectsQuality, ItemInstance, QualityMinMax> {
}

public class TransferValuesConstantNutrients : TransferValuesConstant<EffectsAffectsNutrients, NutrientProcessor.Nutrients, NutrientsMinMax> {
}
public class TransferValuesConstantTastes : TransferValuesConstant<EffectsAffectsTastes, TasteProcessor.Tastes, TastesMinMax> {
}
public class TransferValuesConstantAroma : TransferValuesConstant<EffectsAffectsAroma, AromaProcessor.Aroma, AromaMinMax> {
}
public class TransferValuesConstantComposition : TransferValuesConstant<EffectsAffectsComposition, CompositionProcessor.Composition, DummyMinMax2> {
}
public class TransferValuesConstantCookProperties : TransferValuesConstant<EffectsAffectsCookProperties, CookPropertiesProcessor.CookProperties, DummyMinMax1> {
}
public class TransferValuesConstantQuality : TransferValuesConstant<EffectsAffectsQuality, ItemInstance, QualityMinMax> {
}

public class TransferValuesPercentNutrients : TransferValuesPercent<EffectsAffectsNutrients, NutrientProcessor.Nutrients, NutrientsMinMax> {
}
public class TransferValuesPercentTastes : TransferValuesPercent<EffectsAffectsTastes, TasteProcessor.Tastes, TastesMinMax> {
}
public class TransferValuesPercentAroma : TransferValuesPercent<EffectsAffectsAroma, AromaProcessor.Aroma, AromaMinMax> {
}
public class TransferValuesPercentComposition : TransferValuesPercent<EffectsAffectsComposition, CompositionProcessor.Composition, DummyMinMax2> {
}
public class TransferValuesPercentCookProperties : TransferValuesPercent<EffectsAffectsCookProperties, CookPropertiesProcessor.CookProperties, DummyMinMax1> {
}
public class TransferValuesPercentQuality : TransferValuesPercent<EffectsAffectsQuality, ItemInstance, QualityMinMax> {
}

public class TransferValuesSwapConstantNutrients : SwaprValuesConstant<EffectsAffectsNutrients, NutrientProcessor.Nutrients, NutrientsMinMax> {
}
public class TransferValuesSwapConstantTastes : SwaprValuesConstant<EffectsAffectsTastes, TasteProcessor.Tastes, TastesMinMax> {
}
public class TransferValuesSwapConstantAroma : SwaprValuesConstant<EffectsAffectsAroma, AromaProcessor.Aroma, AromaMinMax> {
}
public class TransferValuesSwapConstantComposition : SwaprValuesConstant<EffectsAffectsComposition, CompositionProcessor.Composition, DummyMinMax2> {
}
public class TransferValuesSwapConstantCookProperties : SwaprValuesConstant<EffectsAffectsCookProperties, CookPropertiesProcessor.CookProperties, DummyMinMax1> {
}
public class TransferValuesSwapConstantQuality : SwaprValuesConstant<EffectsAffectsQuality, ItemInstance, QualityMinMax> {
}

public class TransferValuesSwapPercentNutrients : SwapValuesPercent<EffectsAffectsNutrients, NutrientProcessor.Nutrients, NutrientsMinMax> {
}
public class TransferValuesSwapPercentTastes : SwapValuesPercent<EffectsAffectsTastes, TasteProcessor.Tastes, TastesMinMax> {
}
public class TransferValuesSwapPercentAroma : SwapValuesPercent<EffectsAffectsAroma, AromaProcessor.Aroma, AromaMinMax> {
}
public class TransferValuesSwapPercentComposition : SwapValuesPercent<EffectsAffectsComposition, CompositionProcessor.Composition, DummyMinMax2> {
}
public class TransferValuesSwapPercentCookProperties : SwapValuesPercent<EffectsAffectsCookProperties, CookPropertiesProcessor.CookProperties, DummyMinMax1> {
}
public class TransferValuesSwapPercentQuality : SwapValuesPercent<EffectsAffectsQuality, ItemInstance, QualityMinMax> {
}

public class BonusValuesConstantNutrients : BonusValuesConstant<EffectsAffectsNutrients, NutrientProcessor.Nutrients, NutrientsMinMax> {
}
public class BonusValuesConstantTastes : BonusValuesConstant<EffectsAffectsTastes, TasteProcessor.Tastes, TastesMinMax> {
}
public class BonusValuesConstantAroma : BonusValuesConstant<EffectsAffectsAroma, AromaProcessor.Aroma, AromaMinMax> {
}
public class BonusValuesConstantComposition : BonusValuesConstant<EffectsAffectsComposition, CompositionProcessor.Composition, DummyMinMax2> {
}
public class BonusValuesConstantCookProperties : BonusValuesConstant<EffectsAffectsCookProperties, CookPropertiesProcessor.CookProperties, DummyMinMax1> {
}
public class BonusValuesConstantQuality : BonusValuesConstant<EffectsAffectsQuality, ItemInstance, QualityMinMax> {
}

public class BonusValuesPercentNutrients : BonusValuesPercent<EffectsAffectsNutrients, NutrientProcessor.Nutrients, NutrientsMinMax> {
}
public class BonusValuesPercentTastes : BonusValuesPercent<EffectsAffectsTastes, TasteProcessor.Tastes, TastesMinMax> {
}
public class BonusValuesPercentAroma : BonusValuesPercent<EffectsAffectsAroma, AromaProcessor.Aroma, AromaMinMax> {
}
public class BonusValuesPercentComposition : BonusValuesPercent<EffectsAffectsComposition, CompositionProcessor.Composition, DummyMinMax2> {
}
public class BonusValuesPercentCookProperties : BonusValuesPercent<EffectsAffectsCookProperties, CookPropertiesProcessor.CookProperties, DummyMinMax1> {
}
public class BonusValuesPercentQuality : BonusValuesPercent<EffectsAffectsQuality, ItemInstance, QualityMinMax> {
}


OBS: I am looking for a non-runtime-compile solution, because that will take longer than the time I can afford right now to setup
OBS2: I already know how to handle the runtime generation of ECS types limiation on Unity, so that's a non issue
OBS3: I am using the term "instance of" class due to not knowing the proper term for it, I don't need a object instance of a class such as described, I need the class such as described to exist on the assembly at runtime.

Guedez
  • 189
  • 3
  • 14
  • Are you looking for `Type.MakeGenericType`? – Jon Skeet Nov 09 '19 at 15:09
  • Yes, you create an instance of a type that is a class, so an instance of a class, that is thus an object. It's the good expression. Therefore you get a reference to this object, to this instance of the class. An object is an instance of a class. –  Nov 09 '19 at 15:10
  • typeof(MyType<>) is giving me "Using the generic type MyType requires 3 type arguments". Is it a .net version issue? Would It still work if I just put whatever 3 types there? – Guedez Nov 09 '19 at 15:31
  • "I want this so that I don't have to write this at the end of my files" Why would you repeat anything of that anywhere? If you repeat it, you only run the risk of having different types in different files (as the namespace integral part of a classes identity). You could just bake them into a dll and start referencing that dll. – Christopher Nov 09 '19 at 16:46
  • You completely missed the point @Christopher I need those types to exist but I don't want to write them myself, I want that automated somehow. I don't care if someone makes more of them somewhere else – Guedez Nov 10 '19 at 15:04
  • @Guedez: That is reflections ability to make types on the fly. And agian, utterly ruins type saftey. And I think you have to put the type is some global collection, to have any chance of doing is checks or the like on it. Also on this scale and with it clearly being a game, this is very likely to be a giant resource drain. With games you are happy with every bit of perforamnce you do not *have* to trade away. – Christopher Nov 10 '19 at 15:16
  • I am using this to create Unity ECS systems, they need to be typed for tape safety, so I need to declare concrete classes for my generic implementations. I have many different components that implements certain interfaces, so I use this to enable a single abstract system to be able to treat multiple components. – Guedez Nov 11 '19 at 01:13

0 Answers0