All Questions
68
questions
0
votes
2
answers
515
views
Convert List<object> to List<model> type with only the model name c# mvc
So I'm trying to create a generic function (currently it's not but I wanted to future proof it, so in a later stage the tableName can be picked/passed through).
I want to use the string ...
0
votes
1
answer
148
views
How to pass a method parameter as object and convert it back to it's type?
I would like to pass any type variable to a method and in the method convert it back to it's original type. I am looking to wrap DevExpress Messenger functionality and the message that is sent needs ...
0
votes
1
answer
64
views
Checking is there any same type object inside of the object list? [duplicate]
I have an object list which is derived from A type (X and Y derived from A)
List<A> list = new List<A>()
{
new X(),
new Y(),
};
I have an object which is derived from A type. Z ...
-2
votes
1
answer
107
views
Check if an object is a type or a subtype [duplicate]
Consider the following code which checks if an object is of a specific type:
public MyMethod(object myObject)
{
if (myObject.GetType() != typeof(MyClass))
{
throw new ArgumentException(...
0
votes
0
answers
70
views
C# Passing a variable type to a generic method and casting the result object back to the type
I'm trying to wrap my head around how types and generic methods work with Newtonsoft.Json.
I have the following example base class:
public class Foo
{
public Type Expected;
public object ...
1
vote
1
answer
246
views
Cleaner way than using Type (possibly as?) - code smell looking for cleaner way
Dont know what object type will be passed in, if it is type of FishDTO it has a different route to generate the uri, if it is not fish than it is mammal and should follow standard route. Is there a ...
0
votes
1
answer
216
views
Replace the object type by common data types - Type safety
I am developping a system that deals with many modules, which all have their own sets of parameters. Each parameter value can be of a common data type (string, int, long, bytes, bool).
For simplicty, ...
0
votes
1
answer
5k
views
C# Json Deserialize to generic object
I have a function with its own object type:
public RaceJson GetLatestRace()
{
string filter = "example";
List<RaceJson> currentRace = await gsaClient.SendCustomRequest<List<...
1
vote
1
answer
3k
views
Get and Set System.Object value using Unity SerializedProperties
I want to be able to specify the type with an enum and assign the value to the object variable, but I keep getting 'NullReferenceException ..' error message.
I have this simple class:
[System....
0
votes
1
answer
48
views
Declare 2D array of different object types depending on if else (or switch) c#
I am working with matrix and have problem how correctly initialize different 2D array of objects, when their type depends on condition (if else). If I declare matrix and its type before if else, then ...
0
votes
0
answers
58
views
C# object{int} not equal to object{int} [duplicate]
I have a DataTable and I created a DataView from the DataTable. I grab a record from the DataTable (Let's say record 5). Then I sort the DataView and I am trying to find the new index of the record I ...
0
votes
2
answers
609
views
C# Modifying Reference Type Objects doesn't reflect changes
I have this C# code:
int i = 20;
object t = i;
object r = t;
r = 100;
Why at this point, the value of T is still 20 and not 100 ?
I supposed T and R pointed to the same location and changes to ...
0
votes
1
answer
361
views
Cast of a C# object to string in delphi
I'm converting a c# project to delphi XE5 and I'm stuck on a (i believe) simple task.
public void TransferFile(object o, Stream stream)
{
string s = o as string;
if (s != null)
{ do ...
0
votes
2
answers
776
views
Typeof not working as condition
I currently have a method to see what type of object an input is and create a SQL input based on it, Like so:
private static string PropertyToDBString(object o)
{
Debug.Log(o.GetType());
if (...
0
votes
5
answers
488
views
Pass an object variable to method - Specified cast is not valid
I have a list of objects (their types are unknown ahead of time). The example below shows hard coded values, but my actual code populates the args list by reading from a CSV file. I then want to pass ...