Pacrombie
Pacrombie
CC#
Created by Pacrombie on 3/21/2023 in #help
❔ ✅ Reflection to get all Properties of a certain type
I have this in a class:
List<KeyCode> keyCodeProperties = typeof(SettingsData)
.GetProperties(System.Reflection.BindingFlags.Public)
.Select(property => property.GetValue(GameManager.Instance.Settings))
.ToList();
List<KeyCode> keyCodeProperties = typeof(SettingsData)
.GetProperties(System.Reflection.BindingFlags.Public)
.Select(property => property.GetValue(GameManager.Instance.Settings))
.ToList();
And this in the referenced Settings object:
public float MouseSens
{
get
{
return _mouseSens;
}
set
{
_mouseSens = value;
}
}
public KeyCode PrimaryFireKey
{
get
{
return _primaryFireKey;
}
set
{
_primaryFireKey = value;
}
}
public KeyCode AltFireKey
{
get
{
return _altFireKey;
}
set
{
_altFireKey = value;
}
}
...
public float MouseSens
{
get
{
return _mouseSens;
}
set
{
_mouseSens = value;
}
}
public KeyCode PrimaryFireKey
{
get
{
return _primaryFireKey;
}
set
{
_primaryFireKey = value;
}
}
public KeyCode AltFireKey
{
get
{
return _altFireKey;
}
set
{
_altFireKey = value;
}
}
...
The first block of code I sent does not compile because all the crap after the equals sign returns a list of objects, and I need a list of
KeyCode
KeyCode
s. I've hardly ever used Reflection and I'm just a little lost. I know my code as it stands (if I were to change my list to a
List<object>
List<object>
gets the values of all properties in my given class), but I just want the
KeyCode
KeyCode
properties in a List. Any help would be appreciated. I'm starting to think it would just be better to have them in a Dictionary in my Settings class since the names of the properties do matter (I could use Dictionary keys). Anyways, thank u in advance :)
47 replies
CC#
Created by Pacrombie on 3/11/2023 in #help
Is this bad practice?
3 replies
CC#
Created by Pacrombie on 3/10/2023 in #help
❔ Abstract forced empty constructor inheritance
32 replies
CC#
Created by Pacrombie on 3/10/2023 in #help
❔ Empty event computational power
If I invoke an Action<SomeClass> as such: someAction?.Invoke(this) how much efficiency am I losing by invoking the event when it has no subscribers? Is this something I should worry about?
4 replies
CC#
Created by Pacrombie on 3/10/2023 in #help
❔ C# EventArgs
I'm starting to use System.EventHandler events and I'm just wondering if there is a point to the EventArgs class other than to be inherited for custom args? Like, I'm calling StartEvent?.Invoke(this, new EventArgs()); and the new EventArgs() just seems kind of pointless since its empty. Can I send something through the default EventArgs with a lambda expression or something?
63 replies
CC#
Created by Pacrombie on 3/10/2023 in #help
❔ ✅ C# event question
Really simple question: when a C# event is invoked, are the methods added to it cleared, or can I invoke an event repeatedly with the same methods?
8 replies
CC#
Created by Pacrombie on 3/10/2023 in #help
❔ ✅ Inheritance/sharing variables
5 replies
CC#
Created by Pacrombie on 3/9/2023 in #help
I have a super weird thing I'm trying to do with interfaces
14 replies
CC#
Created by Pacrombie on 3/9/2023 in #help
Trying to learn about interfaces
21 replies
CC#
Created by Pacrombie on 3/8/2023 in #help
❔ C# Fundamental: does setting one object to another point or copy?
public SomeType someObject = new SomeType();
public SomeType anotherObject = someObject;
public SomeType someObject = new SomeType();
public SomeType anotherObject = someObject;
this is probably a braindead question but in this code, is anotherObject "pointing" to someObject (changing the instance variables of one will change the other's) or does anotherObject copy the values of someObject into a new object? im new to the language and trying to develop an understanding
13 replies
CC#
Created by Pacrombie on 2/1/2023 in #help
❔ Trying to figure out a data type
6 replies
CC#
Created by Pacrombie on 1/31/2023 in #help
❔ Singleton Pattern StackOverflowException
12 replies