473,804 Members | 2,132 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Property of List of Classes

I asked this question before but got no responses. Let me rephrase the
question. I have a class that as a property defined as a list of
classes.

Public Class ClassA

Public Property Prop1 as List(of ClassB)

In a code segment, I can add an instance of ClassB to the Prop1
property of an instance of ClassA with the statement:

myClassA.Prop1. Add myClassB

Can I add an instance of ClassB to the Prop1 List using the
..InvokeMember method of the Type class?

Feb 16 '06 #1
2 1621
Try:

Public Class ClassB

End Class

Public Class ClassA
Public Prop1 As New List(Of ClassB)
End Class

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

Dim objA As New ClassA
Dim objArray(0) As ClassB

objA.Prop1.Add( New ClassB)

objArray(0) = New ClassB
objA.Prop1.GetT ype.InvokeMembe r("Add", Reflection.Bind ingFlags.Instan ce
Or Reflection.Bind ingFlags.Public Or Reflection.Bind ingFlags.Invoke Method,
Nothing, objA.Prop1, objArray)

MessageBox.Show (objA.Prop1.Cou nt.ToString) ' Result: 2

End Sub

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com
<za***@construc tion-imaging.com> escribió en el mensaje
news:11******** *************@g 47g2000cwa.goog legroups.com...
I asked this question before but got no responses. Let me rephrase the
question. I have a class that as a property defined as a list of
classes.

Public Class ClassA

Public Property Prop1 as List(of ClassB)

In a code segment, I can add an instance of ClassB to the Prop1
property of an instance of ClassA with the statement:

myClassA.Prop1. Add myClassB

Can I add an instance of ClassB to the Prop1 List using the
.InvokeMember method of the Type class?

Feb 16 '06 #2
Carlos J. Quintero [VB MVP] wrote:
objArray(0) objA.Prop1.GetT ype.InvokeMembe r("Add", Reflection.Bind ingFlags.Instan ce
Or Reflection.Bind ingFlags.Public Or Reflection.Bind ingFlags.Invoke Method,
Nothing, objA.Prop1, objArray)


Oh, man, I was thinking the only way to set a property value in
InvokeMethod was to use the bindings flag of SetProperty. I never
thought of Invoking the Add method!! Very elegant. I will try your
suggestion!

Feb 16 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
11558
by: manuel | last post by:
Exist a sintax like import Foo for property in Foo print property ?
2
277
by: rob | last post by:
You are probably familiar with constructs like: DataGridView datagridview1; datagridview1.Columns.DataPropertyName datagridview1.Columns.Count datagridview1.Columns.Add(..) I would like to implement something similar, i.e. class MyClass
4
4042
by: Pritcham | last post by:
Hi all I've got a number of classes already developed (basic entity classes) like the following: Public Class Contact Private _firstname as String Private _age as Integer Public Property FirstName As String
2
1605
by: chris.dannemiller | last post by:
1. I have a MDI document what is the best way to link data form a specific MDI document to parameters of a property grid. In this case I have a palette that can change from document to document, and I want my customized color picker to support the diffrent palettes depending on what document is active. 2. I have a large set of bjects that use a single class in the Property grid, However the classes that derive this need to ensure that...
7
1646
by: Nemisis | last post by:
Hi everyone, Can anyone tell me if it is possible to pass in a property of an object into a sub, and within that sub, find out the name of the item that was passed along with the property name?? Example would be ......Code Dim ObjA As New ObjectA
0
25600
ADezii
by: ADezii | last post by:
The motivation for this Tip was a question asked by one of our Resident Experts, FishVal. The question was: How to Declare Default Method/Property in a Class Module? My response to the question was inadequate to say the least, but I was determined to come up with the correct answer, especially since my primary background is Visual Basic, and I knew that there was an answer. Well, I did come up with an answer and I decided to incorporate it into...
2
12511
by: ME | last post by:
I have a property that is a generic list of type IAddress (List<IAddress>). When I attempt to view this property using the Property Grid control it plainly says "Collection" and offers the typical generic CollectionEditor that ships with .NET to edit the property. The trouble comes up though when I attempt to Add an item to the collection via the CollectionEditor. Obviously the Collection editor can not create an IAddress object since it...
4
4914
by: ocramedl | last post by:
Hi all, I work in C# and I have created a custom panel (called CustomPanel) which inherits from UserControl. I have added to my CustomPanel a protected property, called Title. The goal of such property is to be able to draw a title for the panel by simply setting the Title property. I made it protected, since I have several classes derived from my CustomPanel and I want only derived classes to be able to set the Title property (I need a...
6
3043
by: phancey | last post by:
I want to define a class like this class MyClass { List<TMyList<Twhere T : IMyList {get; set;} } or something like this. I don't want to put <Ton my class definition
0
9715
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10603
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10353
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10099
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9176
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3836
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3003
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.