473,546 Members | 2,205 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reflection and SetValue .arrrrggggggghh hhh

Ok, Im missing something simple here.

I have an object o its a person , I want to "blank" out any properties
that are a type of a collection

The follwoing code will loop through and tell me if it is or not.

BUT I cannot figure out how to Set the Value

Dim myProperties() As PropertyInfo =
o.GetType.GetPr operties((Bindi ngFlags.Public Or BindingFlags.In stance))
Dim PropertyItem As PropertyInfo
Dim MyString As String

For Each PropertyItem In myProperties

With PropertyItem

If
GetType(ICollec tion).IsAssigna bleFrom(.Proper tyType) Then
'This works to tell if its a collection
MyString = MyString & "Collection " &
..ReflectedType .ToString & " " & .PropertyType.N ame & vbCrLf

'THIS IS WHAT DOES NOT WORK
PropertyItem.Se tValue(o, .GetType, Nothing)

End If
End With

Next
Any Help would be super, I know its got to be just a syntax issue,
steroids, or lack of sleep :)

Thanks

Chris

Dec 18 '06 #1
2 2346
Ok, got it.........

The typo was.....
PropertyItem.Se tValue(o, .GetType, Nothing)

Should have been

PropertyItem.Se tValue(o, .GetType.Reflec tedType, Nothing)

Next Problem is how do I get the Object for that Property ?

I want to DEAL with it seperatley.

So say the collection contains addresses, I want to get the collection
as an Object and do something else with it.

GetValue ? but another typo ?????

Help on that would be....errr...he lpful....

Sad lack of Reflection and Generics Documentation in VB.Net....or im
too tired to find it even though looking
cw******@gmail. com wrote:
Ok, Im missing something simple here.

I have an object o its a person , I want to "blank" out any properties
that are a type of a collection

The follwoing code will loop through and tell me if it is or not.

BUT I cannot figure out how to Set the Value

Dim myProperties() As PropertyInfo =
o.GetType.GetPr operties((Bindi ngFlags.Public Or BindingFlags.In stance))
Dim PropertyItem As PropertyInfo
Dim MyString As String

For Each PropertyItem In myProperties

With PropertyItem

If
GetType(ICollec tion).IsAssigna bleFrom(.Proper tyType) Then
'This works to tell if its a collection
MyString = MyString & "Collection " &
.ReflectedType. ToString & " " & .PropertyType.N ame & vbCrLf

'THIS IS WHAT DOES NOT WORK
PropertyItem.Se tValue(o, .GetType, Nothing)

End If
End With

Next
Any Help would be super, I know its got to be just a syntax issue,
steroids, or lack of sleep :)

Thanks

Chris
Dec 18 '06 #2
<cw******@gmail .comha scritto nel messaggio
Should have been

PropertyItem.Se tValue(o, .GetType.Reflec tedType, Nothing)
mmm... I don't know what you are trying to do but I think this should be

PropertyItem.Se tValue(o, Nothing, Nothing)

Next Problem is how do I get the Object for that Property ?

I want to DEAL with it seperatley.
Please describe a lillte clearly the scenario :)

Dec 18 '06 #3

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

Similar topics

5
451
by: Andre | last post by:
I have two questions; 1) When executing the sub routine "TestStructure", I'm trying to update the member "intTyres" in the structure "structureCar" dynamically using System.Reflection. The code executes, but the value does not change, nor is there an exception thrown. 2) Read comments in sub routine "TestIntegerProperty"
11
12730
by: Aaron Queenan | last post by:
Given the classes: class Class { public static implicit operator int(Class c) { return 0; } } class Holder
4
1975
by: Lucas Tam | last post by:
Hi all, I need to set a property on a subclass such as: Report.ExportOptions.ExportFormatType = ExportFormatType.Excel AND Report.ExportOptions.FormatOptions = excelFormatOpts
1
1467
by: Chad Dollins | last post by:
I've got everything going nearly except one line of code. I think I'm in over my head here so, I'm going to ask for some help. Basically what the preposal is that you will be able to open a folder browse dialogue with a root other than those specified in Environment::SpecialFolders::. and I'm hoping that I would be able to specify network...
1
1411
by: Eric | last post by:
I have here a little sample which does reflection on a class. I striked me that 1.1 is nearly two times faster. Could me somebody give a hint why? For the sample: Compile it via "csc.exe /optimize+ Program.cs" with the two compiler for 1.1 and 2.0. Thanks Eric
9
2379
by: Bill Grigg | last post by:
All, Can anyone supply an example or reference to an example of using reflection to determine the data types and array lengths contained in a nested stucture in C#? Actually, it is a structure that I use to communicate to some unmanaged code in a DLL written in C. It is not complicated, but will change and I would like to be able to...
2
2314
by: Torben Laursen | last post by:
I have a complicated class that I use to store a lot of values Now I need a copy of that class and I have been trying to find a way to do this automatic so I don't have to assign all properties and classes by hand (about 200 properties). I found this post on google: http://www.thescripts.com/forum/thread225825.html But how does this code...
11
6364
by: =?Utf-8?B?dG9iaXdhbl9rZW5vYmk=?= | last post by:
The following code is in a custom deserializer: object value = (int) 1; string nameToParse = Enum.GetName(field.FieldType, value); value = Enum.Parse(field.FieldType, nameToParse); Currently we follow the path below: intValue --enum name --enum value
3
1358
by: Elan Dro | last post by:
How we can pass the structure type (GUID) as value parameter to the object using reflection setValue method of FieldInfo, PropertyInfo and etc Ex : Public Class A Public GUIDField as GUID End Class ... ...
0
7507
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...
0
7435
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7947
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...
1
7461
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7794
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...
0
6030
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...
1
5361
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3472
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
747
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...

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.