473,382 Members | 1,332 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,382 software developers and data experts.

Using reflection to read the page properties...

Stu
Hi,

I am trying to write a detailed logging system for a site. The client
basically wants us to save the values of the properties on the page every
time someone presses a save button.

I have written the following function that formats the properties of a basic
class and rreturns it as a formatted string - but it does not work when I
try and pass it the Page class - it displays the error 'Object not set to an
instance....']

Anybody any ideas how I should do this?

Thanks in advance,

Stu

--/ snip /--

'THE PAGE
Public Class Test
Inherits System.Web.UI.Page

private m_Test as string="My test text"

Public Property Test1() As String
Get
Test1 = m_Test1
End Get
Set(ByVal Value As String)
m_Test1 = Value
End Set
End Property

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim log As New clsLogAction
Dim log As New clsLogAction
Response.Write(log.LogAction(Me))
End Sub
End Class

'The Log class
Class LogAction
Public Function returnValues(ByVal obj As Object) As String
Dim sb As New System.Text.StringBuilder
For Each iField As System.Reflection.FieldInfo In
obj.GetType.GetFields(BindingFlags.NonPublic Or BindingFlags.Instance)
sb.Append(iField.Name.ToString + "|" +
iField.GetValue(obj).ToString + vbCrLf)
Next
Return sb.ToString
End Function
End Class
Feb 21 '06 #1
1 1139
Errors:
1. For Each iField As System.Reflection.FieldInfo In
obj.GetType.GetFields(BindingFlags.NonPublic Or BindingFlags.Instance)
Call the method that enumerate the fields FIRST, and not on ITERATION;

2. iField.GetValue(obj).ToString + vbCrLf) > The value obtained is probally
null; Check it before calling ToString();

--
Ravi Wallau
no****@nospam.org
"Stu" <s.****@cergis.com> wrote in message
news:uP*************@TK2MSFTNGP14.phx.gbl...
Hi,

I am trying to write a detailed logging system for a site. The client
basically wants us to save the values of the properties on the page every
time someone presses a save button.

I have written the following function that formats the properties of a
basic class and rreturns it as a formatted string - but it does not work
when I try and pass it the Page class - it displays the error 'Object not
set to an instance....']

Anybody any ideas how I should do this?

Thanks in advance,

Stu

--/ snip /--

'THE PAGE
Public Class Test
Inherits System.Web.UI.Page

private m_Test as string="My test text"

Public Property Test1() As String
Get
Test1 = m_Test1
End Get
Set(ByVal Value As String)
m_Test1 = Value
End Set
End Property

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim log As New clsLogAction
Dim log As New clsLogAction
Response.Write(log.LogAction(Me))
End Sub
End Class

'The Log class
Class LogAction
Public Function returnValues(ByVal obj As Object) As String
Dim sb As New System.Text.StringBuilder
For Each iField As System.Reflection.FieldInfo In
obj.GetType.GetFields(BindingFlags.NonPublic Or BindingFlags.Instance)
sb.Append(iField.Name.ToString + "|" +
iField.GetValue(obj).ToString + vbCrLf)
Next
Return sb.ToString
End Function
End Class

Feb 21 '06 #2

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

Similar topics

3
by: J E E | last post by:
Hi! Is it possible to access fields in a derived class using reflection? Code below works fine when I access it as a private member in the Page class, but not when accessing base class member...
3
by: TT (Tom Tempelaere) | last post by:
Hi there I am making a service project in C#, and I'm in the process of writing the installer. I made an installer class by using the "Add Installer" menu-item in the design window of the service,...
0
by: John R. | last post by:
I have a class that I am serializing. I put on the properties I don't want to serialize. I want to deserialize it to itself like this: XmlSerializer deserializer = new...
6
by: Simon Verona | last post by:
I would normally use code such as : Dim Customer as new Customer Dim t as new threading.thread(AddressOf Customer.DisplayCustomer) Customer.CustomerId=MyCustomerId t.start Which would create...
16
by: Dennis | last post by:
I have a class named "myclass" and an arraylist containing elements of type "MyClass". I want to get the value of a property of "MyClass" (a string type) for one of the arraylist elements. I...
9
by: Mario Vázquez | last post by:
Hi, I have a component which exposes an extended property. I want to edit this property using a UITypeEditor. The problem is that when the designer raises my UITypeEditor sends a reference of...
3
by: Steve Amey | last post by:
Hi all I am using reflection to read the values of properties from a class. The class is returned from a Web Service so I have to access the class using FieldInfo (Using VS 2003 which converts...
2
by: diego | last post by:
hi everyone, i have a sub that opens a form given the form's name as string and opens it using System.Reflection. How can I set the form's properties at runtime. Here is my code. Public Sub...
3
by: George | last post by:
Hello, I am building an assembly that connects to a third party application via http. I need create a http message that I post to the third party application. The message is very complicated...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.