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

All Questions

Tagged with
0 votes
0 answers
22 views

check if given object implements certain generic interface; type argument(s) NOT known [duplicate]

I have some object. I want to check at runtime if it is an IReadOnlyCollection<T> of any T, i.e. I cannot specify that T in my check. So it should return true for e.g. IReadOnlyCollection<...
Kjara's user avatar
  • 2,794
2 votes
1 answer
62 views

C# generic method detect if T is array and then index into the array

I'm trying to write a Dbg debug function that will print out some debug info about the given parameter and then return it. I would like arrays to be printed as the list of elements, and scalars to ...
beyarkay's user avatar
  • 809
0 votes
1 answer
50 views

Dynamically set the Property name to be the name of the Type(typeof(T).Name)

var appsettings = JsonConvert.DeserializeObject<AppSettings<PersonModel>>(configData); class AppSettings<T> { [JsonProperty(PropertyName = typeof(T).Name)] public T ...
Imran K's user avatar
  • 15
0 votes
2 answers
93 views

Constrain return type to be subtype of this

I have the following interface: internal interface ITyped<EnumType> where EnumType : struct, Enum { public EnumType Type { get; } // !!! this method must always return a subtype* of the ...
Kjara's user avatar
  • 2,794
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
18 views

C# How to flexibly represent mixed intermediate scalar/vector results in DSL expression evaluator

I want to evaluate expressions like: LARGEST(A) + B A is double[] {1,2,3,4,5} B is double[] {2,3,4,5,6} I'm using Irony and can create a suitable abstract syntax tree: 1. binary_add ...
amonroejj's user avatar
  • 633
0 votes
1 answer
88 views

Storing product attributes of different types in a product aggregate

I use the EAV (Entity-Attribute-Value) pattern in an inventory management system I'm developing. It's very comparable to a typical webshop framework like Magento. Attributes have a data type, like ...
user2190492's user avatar
  • 1,174
1 vote
2 answers
115 views

Allow multiple types for one property when deserializing json using System.Text.Json

I am expecting that particular property in the incoming data would be either an array of integers or a string. What is the proper way to define this condition it in my model? using System.Text.Json....
concentriq's user avatar
2 votes
0 answers
70 views

How to detect classes marked with file modifier in C#

In C# 11, the new file type modifier was introduced. I was looking for a way to detect such non-public type using reflection, however, I have not find any "good" way to do so. There is no Is…...
Matt Stuvysant's user avatar
0 votes
2 answers
39 views

C# Generic Method passed as argument, Argument type 'bool' is not assignable to parameter type 'System.Func<bool>'

I am attempting to create a generic array iterator which goes iterates through a multidimensional array assigning each element with the result of a function. When trying the following code I get the ...
Max Heinze's user avatar
0 votes
0 answers
52 views

C#: how to create a custom type that can be a Dictionary or a List of Dictionaries

I am trying to create a custom type. Variables which are this type may be either a Dictionary, or a list of Dictionaries This is how I would create the type using python (using mypy) CustomType = ...
Sam's user avatar
  • 2,070
0 votes
0 answers
20 views

store type as variable and use in list<T> c#? [duplicate]

I am trying to store a type as a variable so that I can make a List object with a few different possible types without hard coding them all. My code basically looks like this: using System; using ...
gegb1912'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
0 votes
3 answers
103 views

Check if object of base class came from subclass [duplicate]

I have a base class and a bunch of subclasses of it. I have an object of base class and I know that it was an instance of one of the subclasses before, but it was casted to the base class. I want to ...
Daniel's user avatar
  • 7,645
0 votes
1 answer
121 views

Convert string to Int in DataSet

Sorting does not work in dataGridView1 because when reading from XML the data is read in string format. (Instead of 13-4-3-3-2 I get 13-2-3-3-4) DataXML = new DataSet(); FileStream fs = new ...
speedevil123's user avatar

15 30 50 per page
1
2 3 4 5
193