473,386 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Reflection and SetValue .arrrrggggggghhhhh

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.GetProperties((BindingFlags.Public Or BindingFlags.Instance))
Dim PropertyItem As PropertyInfo
Dim MyString As String

For Each PropertyItem In myProperties

With PropertyItem

If
GetType(ICollection).IsAssignableFrom(.PropertyTyp e) Then
'This works to tell if its a collection
MyString = MyString & "Collection" &
..ReflectedType.ToString & " " & .PropertyType.Name & vbCrLf

'THIS IS WHAT DOES NOT WORK
PropertyItem.SetValue(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 2324
Ok, got it.........

The typo was.....
PropertyItem.SetValue(o, .GetType, Nothing)

Should have been

PropertyItem.SetValue(o, .GetType.ReflectedType, 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...helpful....

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.GetProperties((BindingFlags.Public Or BindingFlags.Instance))
Dim PropertyItem As PropertyInfo
Dim MyString As String

For Each PropertyItem In myProperties

With PropertyItem

If
GetType(ICollection).IsAssignableFrom(.PropertyTyp e) Then
'This works to tell if its a collection
MyString = MyString & "Collection" &
.ReflectedType.ToString & " " & .PropertyType.Name & vbCrLf

'THIS IS WHAT DOES NOT WORK
PropertyItem.SetValue(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.SetValue(o, .GetType.ReflectedType, Nothing)
mmm... I don't know what you are trying to do but I think this should be

PropertyItem.SetValue(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
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...
11
by: Aaron Queenan | last post by:
Given the classes: class Class { public static implicit operator int(Class c) { return 0; } } class Holder
4
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
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...
1
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...
9
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...
2
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...
11
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...
3
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...

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.