generic-list

c# Create generic list dynamically at runtime

自闭症网瘾萝莉.ら 提交于 2021-01-27 17:42:21
问题 Following the example on this post, I found out how to create a list of generic types dynamically. Now, my issue is that I want to ADD items to the created list from an unknown source list - is there some way to achieve this? EDIT I start with a source list containing business objects, but I absolutely need the right type of my output list, because of downstream bindings that require it. My non-compiling code is as follows: IList<object> sourceList; // some list containing custom objects Type

Find item from generic list

蓝咒 提交于 2021-01-27 07:43:40
问题 I have a problem in fetching the record from a generic list. I have created a common function from where i want to get the records from any type of class. Below is sample code:- public void Test<T>(List<T> rEntity) where T : class { object id = 1; var result = rEntity.Where(x => x.id == id); } Please suggest. Thanks in advance. 回答1: With method like that a usual question for compiler is 'what is T' ? If it's just a class it could be anything even a StringBuilder as Jon has mentioned and there

Find item from generic list

旧巷老猫 提交于 2021-01-27 07:43:39
问题 I have a problem in fetching the record from a generic list. I have created a common function from where i want to get the records from any type of class. Below is sample code:- public void Test<T>(List<T> rEntity) where T : class { object id = 1; var result = rEntity.Where(x => x.id == id); } Please suggest. Thanks in advance. 回答1: With method like that a usual question for compiler is 'what is T' ? If it's just a class it could be anything even a StringBuilder as Jon has mentioned and there

Generic List of Structs in VBA

邮差的信 提交于 2020-07-24 04:03:51
问题 I started working in Excel with VBA and would like to save some kind of List. My approach is the following, but I fear that I am looking into the totally wrong direction. Public Type MyType ID As Integer Name As String MyInt As Integer End Type Public ListVar As New Collection Public Sub MySub Dim MyVar As MyType MyVar.ID = 1 MyVar.Name = "name" MyVar.MyInt = 2000 ListVar.Add MyVar, MyVar.ID End Sub When trying to execute, I get a compile error: "Only user-defined types defined in public

Generic List of Structs in VBA

吃可爱长大的小学妹 提交于 2020-07-24 04:02:20
问题 I started working in Excel with VBA and would like to save some kind of List. My approach is the following, but I fear that I am looking into the totally wrong direction. Public Type MyType ID As Integer Name As String MyInt As Integer End Type Public ListVar As New Collection Public Sub MySub Dim MyVar As MyType MyVar.ID = 1 MyVar.Name = "name" MyVar.MyInt = 2000 ListVar.Add MyVar, MyVar.ID End Sub When trying to execute, I get a compile error: "Only user-defined types defined in public

Generic List of Structs in VBA

↘锁芯ラ 提交于 2020-07-24 04:01:17
问题 I started working in Excel with VBA and would like to save some kind of List. My approach is the following, but I fear that I am looking into the totally wrong direction. Public Type MyType ID As Integer Name As String MyInt As Integer End Type Public ListVar As New Collection Public Sub MySub Dim MyVar As MyType MyVar.ID = 1 MyVar.Name = "name" MyVar.MyInt = 2000 ListVar.Add MyVar, MyVar.ID End Sub When trying to execute, I get a compile error: "Only user-defined types defined in public

Convert generic list to BindingList<T>

点点圈 提交于 2020-06-27 07:49:11
问题 I have BindingList object which is attched with DataGridView. BindingList<FilesToProcessDataModels> Listfiles = new BindingList<FilesToProcessDataModels>(); dataGridFiles.DataSource = Listfiles; I want to filter items list by given condition in Where. like following: dataGridSheets.DataSource = Listfiles.Where(i => i.Status == FileStatus.NotProcessed).ToList(); Above code is working fine but I want to assign filter resut to the same type object [Listfiles] instead datagrid, When I am doing

How to handle the generic type Object with protocol buffers, in the .proto file?

余生颓废 提交于 2020-06-24 07:33:21
问题 I've spent some time looking for some alternative to handle generic objects, I've seen questions similar to mine, but not as specific I suppose? Protocol buffers has multiple scalar types that I can use, however they are mostly primitive. I want my message to be flexible and be able to have a field that is a List of some sort. Let's say my .proto file looked like this: message SomeMessage { string datetime = 1; message inputData // This would be a list { repeated Object object = 1; } message

How to look into generic tList during Delphi debugging

北城余情 提交于 2020-03-16 05:54:06
问题 I use Delphi 10.3.1 COMMUNITY version and can't look into generic tList while I debug the project. I know the latest version of Delphi doesn't support the old-typed debug feature which allows to look into generic tList. So I used tList.List in the following code to evaluate the tList. In tList<tRecord>.List I can look into it but can't do it in tList<Integer>.List . type tRecord = record Field: Integer; end; procedure TForm1.FormCreate(Sender: TObject); var _Record: tRecord; _List1: TList

why doesn't it add to the list

拜拜、爱过 提交于 2020-02-25 05:45:27
问题 this question is based on this Link I haven't found an answer, but I am trying on a solution and resulted to another question.. Public Class markerRow Public MarkerName As String Public CameraID As Integer Public HostAddress As String End Class Public mr As New markerRow Dim aList As New List(Of markerRow) For Each dtrow In markerDtable.Rows mr.MarkerName = dtrow("MarkerName") mr.CameraID = dtrow("CameraID") mr.HostAddress = dtrow("HostAddress") aList.Add(New markerRow()) Next from what I