Linked Questions

0 votes
1 answer
801 views

How can I pass a generic method type parameter as a variable to it? Below given is the crud example of what I want to achieve. It's just for a demo purpose, not the actual code. I can use if...else or ...
Farhan Ghumra's user avatar
1 vote
1 answer
511 views

Why can I not do this? Where obj value is a valid type. Type type = obj.Value.GetType(); this.unityContainer.RegisterType<type>(); OR this.unityContainer.RegisterType(obj.Value); When I can do ...
Marsh's user avatar
  • 188
-1 votes
1 answer
179 views

I am trying to create a list of object of Student in School. Instead of Student the School can also have Teacher as a list. I want to use the class name as a parameter instead of the actual class type ...
Jeetendra Tandel's user avatar
89 votes
2 answers
47k views

Is it possible to achieve the following code? I know it doesn't work, but I'm wondering if there is a workaround? Type k = typeof(double); List<k> lst = new List<k>();
Chris's user avatar
  • 1,089
5 votes
4 answers
6k views

I have the following example-class: public class MyClass<T> { public IList<T> GetAll() { return null; // of course, something more meaningfull happens here... } } And ...
sl3dg3's user avatar
  • 5,238
3 votes
4 answers
8k views

I have a type like this: public class TypeValue { public Type Type { get; private set; } public object Value { get; private set; } } so I can do something like: TypeValue tv = ... int count =...
Joan Venge's user avatar
  • 334k
1 vote
3 answers
1k views

I'm not sure how to correct this. I have public void get_json(String TYPE) { Type t = Type.GetType("campusMap." + TYPE); t[] all_tag = ActiveRecordBase<t>.FindAll(); } But I always ...
Quantum's user avatar
  • 1,476
1 vote
1 answer
1k views

I have a generic method : public static T GetSetting<T>(string Key){ .... } Which returns a setting value from database. Now I'm trying to make it fill the class automatically with Settings: ...
Ashkan Mobayen Khiabani's user avatar
1 vote
1 answer
1k views

<GenericInputFor> provides markup based on the argument it receives and its type, it behaves fine with compile time types, but when I try to iterate through some class properties with reflection ...
Takelovski's user avatar
0 votes
0 answers
455 views

I am working on a razor component library in which I would like to expose some components. However I would like to have the user of the library be able to set some global (generic) object that all ...
Dylan Snel's user avatar
-1 votes
2 answers
177 views

Let's say I'm working with generic function : public interface IFoo { Type Type; TValue Read<TValue>(); } public class Foo : IFoo {} var f = new Foo(); I'd like to write : var value = ...
BaltoStar's user avatar
  • 9,151
0 votes
2 answers
205 views

Compilation errors: Visual Basic.NET Compilation error: "Type t is not defined" C# Compilation error: 't' is a variable but is used like a type Why i can not do this: VB: For i = 0 To dt....
Jonathan Applebaum's user avatar
1 vote
2 answers
101 views

I have the following class in c#: public class WorkOrderStatus : ICustomEnum<WorkOrderStatus> { } during runtime I need to figure out if a property of the following class implements the custom ...
AnKing's user avatar
  • 2,224
0 votes
2 answers
151 views

I have realized that there are questions that sounds similar to mine but they do not solve my problem. So I want to change a string into a class reference but I cannot change into a variable of type ...
Proff_D's user avatar
  • 41
1 vote
1 answer
61 views

I've extended the Enum type as such: public class Enum<TEnum> where TEnum : notnull, Enum, IConvertible { public static int Length => Enum.GetNames(typeof(TEnum)).Length; } I've also ...
krowe's user avatar
  • 2,300

15 30 50 per page