instantiation

C# reflection and instantiation - is there a way to do Activator.CreateInstance(myType){ X = x }?

拈花ヽ惹草 提交于 2020-07-30 05:33:31
问题 I'm not sure of the terminology for this kind of code, but I want to know if it's possible to instantiate variables after the parentheses, but whilst using reflection. I have a map which gets loaded from an XML file. This is a collection of (int X, int Y, string S) where the X,Y is the position of some terrain, and S is a string representing the type of the terrain. I have a dictionary to pass between the strings and the relevant types; for example one key-value pair might be "Tree", typeof

How can I conditionally instantiate an object?

安稳与你 提交于 2020-07-09 04:33:17
问题 I'm trying to do some conditional work like so: Type object; if (cond) { doSomeStuff(); object = getObject(); doMoreStuff(); } else { doSomeOtherStuff(); object = getDifferentObject(); doEvenMoreStuff(); } use(object); The only way I can think of solving this is the duplicate the use code (which is actually inline code in my application) and declare object in each branch of the if block. If I wanted to avoid duplicate code I'd have to wrap it in some use function, as I have above. In a real

What makes enum in java non instantiable?

那年仲夏 提交于 2020-06-25 07:36:10
问题 I know that an enum enum Year { First, Second, Third, Fourth; } gets converted into final class Year extends Enum<Year> { public static final Year First = new Year(); public static final Year Second = new Year(); public static final Year Third = new Year(); public static final Year Fourth = new Year(); } When I tried to instantiate enum (not class) I got compile time error as: error: enum types may not be instantiated Year y = new Year(); As per my knowledge a private constructor makes a

MVVM model instantiation

▼魔方 西西 提交于 2020-06-24 21:59:45
问题 Following WPF MvvmFoundation , linking the View with the ViewModel has many choices like described on http://www.paulstovell.com/mvvm-instantiation-approaches. However their example has nothing about how to link the ViewModel with the Model . Traditionally I created the model first and then one or more views that render it. It seems that MVVM pushes people to create the View, which creates the ViewModel, which create the Model. I hope it's not the case as wiring a complex business model with

Having objects spawn, with random size within set range, with equal distance between them regardless of framerate

筅森魡賤 提交于 2020-05-31 04:47:25
问题 I am creating a script that spawns random sized cubes (later to replaced with low-poly buildings) that fly past the player on the x-axis to give the illusion of being on a moving train. I have the buildings moving at a set speed, that is constant no matter the framerate using Time.deltaTime. My script is written to wait enough time for the first spawned object to move out of the way, before spawning the next, and it works perfectly with a set size for the objects, but can't seem to keep up if