'c# Is there a way to determine if an object value is a base type like ints and strings or like class or structs
I want to make a serializer and to do this I have to check if the current object's type can hold multiple values. (What I mean by base type are Strings and Ints)
I know there are a lot of great serializers out on the internet but I am doing this as a challenge and most of them don't have the features I want
I guess ints and strings are also classes but what I want is like this:
bool CheckIfBaseType(object value) { return //check }
I don't think there is a proper way to do this instead of saving each base type in an array
Edit:
I think I can use reflection to check if there are any public variables but is there a better way to do this?
Edit 2:
Ok, I am going to try to explain it a bit more, so what I really want is a function that can detect if a value can hold another value so I can check the child value
Algorithmic explanation:
if(objectCanHoldValues(value))
{
//switch the target object to the child object and check if
it can hold a value (this part is done)
}
please do not dislike when I say your solution doesn't work. I am really new to the Stack overflow if I make a mistake I am sorry
Solution 1:[1]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Naeem Ahmed |

