Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
0 votes
1 answer
71 views

How to convert type to generic type, whose actual type is known at the point of conversion?

I have a set of methods which simply return a stored 'object' as a different type each, like this: bool GetAsBool(); string GetAsString(); int GetAsInt(); In the real scenario, there are currently 16 ...
johnny2's user avatar
0 votes
0 answers
23 views

Bound and Unbound types in C# [duplicate]

Bound and Unbound types in C# The term unbound type refers to a non-generic type or an unbound generic type. The term bound type refers to a non-generic type or a constructed type. What does an ...
Logeshkumar S.'s user avatar
3 votes
1 answer
189 views

Get a dictionary of a generic type based on a runtime value

I wish to declare a dictionary based on a runtime type. So, instead of doing this: IEnumerable dict = null; if(type == typeof(SomeType)) dict = new Dictionary<SomeType, string>() if(type == ...
Zenith's user avatar
  • 177
3 votes
1 answer
213 views

Can I achieve type forwarding in .NET without modifying the "from" assembly?

The Problem: We are trying to move an application from .NET Framework to .NET 8. The application needs to consume some third-party .NET Framework assemblies, one of which uses the Framework-only ...
adv12's user avatar
  • 8,531
0 votes
2 answers
34 views

Search Anonymous Type List with Linq

Is there a better way to find a value in an list of anonymous types? I would like to use linq. Sub Main() Dim listOfAnonymousTypes = { New With {.Name = "John", .Age = 30}, ...
jocoder's user avatar
  • 85
0 votes
2 answers
139 views

Can ADO.NET DataTables hold data of types other than Object when grabbing data from a SQL Server?

I'm currently forced to use System.Data and System.Data.SqlClient, i.e. ADO.NET. I DataAdapter.Fill a lot of my DataTables with data from my SQL server. I know with absolute certainty that many of the ...
J. Mini's user avatar
  • 1,788
-5 votes
2 answers
87 views

How to get values from the array, that put into the object? [closed]

I am making json parser so I need the universal method, thats why I can not int[] arr = obj as int[]; int[] array = new int[] { 0, 1, 2 }; object obj = array; //I need to get value from the 'obj' I ...
justSMTH's user avatar
1 vote
2 answers
532 views

How to load assembly before param block of a Powershell script

i'm trying to write a powershell script file that has Parameters whose types require loading. A simple code example is below: [System.Windows.Forms.MessageBoxButtons] requires loading of system....
aetonsi's user avatar
  • 218
0 votes
2 answers
259 views

Generic method parameter with generic property throws T does not contain a definition error

I'm trying to abstract a method that currently takes in 2 parameters. Both parameters are of Class SecureEmail. Initially the types were specified, i want to make it generic now but i'm getting an ...
Aman's user avatar
  • 133
-1 votes
1 answer
115 views

C#: How get the actual type from Type variable

Given the Type type parameter, How can I create the dictionary: Dictionary<Type, DataCollection<T>>, where where typeof(T) == type ? I tried Dictionary<Type, DataCollection<Type>&...
Laurentiu Grigoriu's user avatar
0 votes
1 answer
47 views

Construct member name to retrieve description from XML comments file | Type.GetGenericArguments() returns incorrect result

We have a legacy WinForms app for .NET Framework. A part of this app is a module that reads an assembly's documentation from the accompanying XML comments file. The code has worked without problems ...
TecMan's user avatar
  • 2,919
0 votes
0 answers
127 views

How to pass type parameter as generic during runtime in C#

I would like to create a function that gets a string parameter, determines 2 types based on that parameter and passes that two types to a generic. public void Foo(string a) { var typeb = ...
Huak's user avatar
  • 1
0 votes
2 answers
123 views

Cast to any type

I have a txt file where from I can extract two strings (type and value). But, I need to cast it to the correct type. See the code bellow. string type; string value; //example 1 //from the txt file ...
justSomeUser4's user avatar
1 vote
0 answers
22 views

How do I implement a dynamic type in C#? [duplicate]

I have an HTTP endpoint that is like "localhost://helloworld/Dogs" I want a dynamic way to extract the last part of this endpoint, in this case Dogs, and use it as a type in my method. Does ...
HackerMan33453's user avatar
0 votes
2 answers
70 views

Casting object to type variable inside method

I have the below extension method where I pass the type and cast the object to the type but get a compile error at casting. public static void AddCellProperties(this ColumnInfo _columnInfo, Type type) ...
kumar425's user avatar

15 30 50 per page
1
2 3 4 5
43