472,347 Members | 2,400 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

late binding and reflection

Hi all,

what is the difference between the late binding and reflection?

clara
--
thank you so much for your help
Nov 13 '08 #1
4 2519
Reflection is the mechanism that allows to get information on a type and
other elements at runtime :

MsgBox(GetType(String).GetMembers.Count)

gets information about the string type...

Late binding is resolving a call at runtime (and in particular calling a
method on an object whose type is not known at all at compile time i.e. on a
"As Object" variable).

Dim obj As Object
obj = CreateObject("WScript.Network")
MsgBox(obj.UserName)
MsGbox(obj.ThisOneIsLikelyNotWorking)

If I change the "WScript.Network" string the first call could work or not
depending on wether or not this class exposes a UserName property but I'll
know it only at runtime...

They are somewhat related (AFAIK for now C# can use Reflection to implement
late binding whihc is not yet available as a language feature as in VB).

Try wikipedia for details :
http://en.wikipedia.org/wiki/Reflect...mputer_science)

http://en.wikipedia.org/wiki/Late_binding but I prefer
http://en.wikipedia.org/wiki/Dynamic_dispatch that is IMO closer of how
"Late binding" is used in the context of Visual Basic...

In most cases, you'll want to avoid late binding and at a less degree
System.Reflection as much as you can...

--
Patrice
"clara" <cl***@discussions.microsoft.coma écrit dans le message de groupe
de discussion : C0**********************************@microsoft.com...
Hi all,

what is the difference between the late binding and reflection?

clara
--
thank you so much for your help

Nov 13 '08 #2
On Nov 13, 2:12*pm, "Patrice" <http://www.chez.com/scribe/wrote:
Reflection is the mechanism that allows to get information on a type and
other elements at runtime :

MsgBox(GetType(String).GetMembers.Count)

gets information about the string type...

Late binding is resolving a call at runtime (and in particular calling a
method on an object whose type is not known at all at compile time i.e. on a
"As Object" variable).

* Dim obj As Object
* * * * obj = CreateObject("WScript.Network")
* * * * MsgBox(obj.UserName)
* * * * MsGbox(obj.ThisOneIsLikelyNotWorking)

If I change the "WScript.Network" string the first call could work or not
depending on wether or not this class exposes a UserName property but I'll
know it only at runtime...

They are somewhat related (AFAIK for now C# can use Reflection to implement
late binding whihc is not yet available as a language feature as in VB).

Try wikipedia for details :http://en.wikipedia.org/wiki/Reflect...mputer_science)

http://en.wikipedia.org/wiki/Late_bindingbut I preferhttp://en.wikipedia.org/wiki/Dynamic_dispatchthat is IMO closer of how
"Late binding" is used in the context of Visual Basic...

In most cases, you'll want to avoid late binding and at a less degree
System.Reflection as much as you can...

--
Patrice

"clara" <cl...@discussions.microsoft.coma écrit dans le message de groupe
de discussion : C0154300-4666-4FC2-94DC-6E3D9A2DD...@microsoft.com...
Hi all,
what is the difference between the late binding and reflection?
clara
--
thank you so much for your help
Darn, by the time I dug up the articles and got over here, you already
posted them!

:-)

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/
Nov 13 '08 #3
Hi Patrice,

Thank you very much!
My next question is usage of Reflection and especially how can we combine
Attribute with it?

Clara

--
thank you so much for your help
"Patrice" wrote:
Reflection is the mechanism that allows to get information on a type and
other elements at runtime :

MsgBox(GetType(String).GetMembers.Count)

gets information about the string type...

Late binding is resolving a call at runtime (and in particular calling a
method on an object whose type is not known at all at compile time i.e. on a
"As Object" variable).

Dim obj As Object
obj = CreateObject("WScript.Network")
MsgBox(obj.UserName)
MsGbox(obj.ThisOneIsLikelyNotWorking)

If I change the "WScript.Network" string the first call could work or not
depending on wether or not this class exposes a UserName property but I'll
know it only at runtime...

They are somewhat related (AFAIK for now C# can use Reflection to implement
late binding whihc is not yet available as a language feature as in VB).

Try wikipedia for details :
http://en.wikipedia.org/wiki/Reflect...mputer_science)

http://en.wikipedia.org/wiki/Late_binding but I prefer
http://en.wikipedia.org/wiki/Dynamic_dispatch that is IMO closer of how
"Late binding" is used in the context of Visual Basic...

In most cases, you'll want to avoid late binding and at a less degree
System.Reflection as much as you can...

--
Patrice
"clara" <cl***@discussions.microsoft.coma crit dans le message de groupe
de discussion : C0**********************************@microsoft.com...
Hi all,

what is the difference between the late binding and reflection?

clara
--
thank you so much for your help

Nov 13 '08 #4

"clara" <cl***@discussions.microsoft.comwrote in message
news:68**********************************@microsof t.com...
Hi Patrice,

Thank you very much!
My next question is usage of Reflection and especially how can we combine
Attribute with it?

Clara

--
thank you so much for your help
"Patrice" wrote:
>Reflection is the mechanism that allows to get information on a type and
other elements at runtime :

MsgBox(GetType(String).GetMembers.Count)

gets information about the string type...

Late binding is resolving a call at runtime (and in particular calling a
method on an object whose type is not known at all at compile time i.e.
on a
"As Object" variable).

Dim obj As Object
obj = CreateObject("WScript.Network")
MsgBox(obj.UserName)
MsGbox(obj.ThisOneIsLikelyNotWorking)

If I change the "WScript.Network" string the first call could work or not
depending on wether or not this class exposes a UserName property but
I'll
know it only at runtime...

They are somewhat related (AFAIK for now C# can use Reflection to
implement
late binding whihc is not yet available as a language feature as in VB).

Try wikipedia for details :
http://en.wikipedia.org/wiki/Reflect...mputer_science)

http://en.wikipedia.org/wiki/Late_binding but I prefer
http://en.wikipedia.org/wiki/Dynamic_dispatch that is IMO closer of how
"Late binding" is used in the context of Visual Basic...

In most cases, you'll want to avoid late binding and at a less degree
System.Reflection as much as you can...

--
Patrice
"clara" <cl***@discussions.microsoft.coma crit dans le message de
groupe
de discussion : C0**********************************@microsoft.com...
Hi all,

what is the difference between the late binding and reflection?

clara
--
thank you so much for your help

Here are 3 snippits of code:

1st: Create Attribute

<AttributeUsage(AttributeTargets.Property Or AttributeTargets.Method)_
Public Class MyAttribute
Inherits System.Attribute

Private _myName As String

Public ReadOnly Property MyName() As String
Get
Return _myName
End Get
End Property

Public Sub New(ByVal myName As String)
_myName = myName
End Sub
End Class
2nd: Use Attribute in object property
Imports CreatingUserAttributes
Public Class MyObject

Private _firstProp As String

<MyAttribute("Prop")_
Public Property FirstProp() As String
Get
Return _firstProp
End Get
Set(ByVal value As String)
_firstProp = value
End Set
End Property

<MyAttribute("Tester")_
Public Sub OurFirstMethod()
Dim i As Integer = 1
End Sub

<MyAttribute("moreTesting")_
Public Sub OurSecondMethod()
Dim t As Integer = 1
End Sub

End Class

3rd: Test for attribute using reflection
Imports System.Reflection

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim t As New MyObject

Dim typ As Type = t.GetType()

Dim props() As PropertyInfo = typ.GetProperties()
For Each p As PropertyInfo In props
Dim obj As Array = p.GetCustomAttributes(False)
For Each a As Attribute In obj
If a.TypeId Is GetType(MyAttribute) Then
Dim nam As String = String.Empty
Dim oo As MyAttribute = CType(a, MyAttribute)
End If
Next
Next
End Sub
End Class

Hope this helps
LS
Nov 13 '08 #5

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

Similar topics

5
by: Daniel Bass | last post by:
..Net is great for modulerising libraries, so that all you need do to access a DLL, is simply call Add Reference and wallah, it's as though the...
9
by: Scott English | last post by:
I am writing an C# program. I call a method on a COM object that returns Object. I don't know the type of the object (and reflection just says its...
9
by: John Smith | last post by:
Hey, I'm having a difficult time finding some good examples of late binding Outlook in C#. Anyone know of any good sites out there? I've...
3
by: Daniel | last post by:
how do i access methods when the .net assembly was loaded with late biding? class Class1 { public static void Main() {...
5
by: CodeRazor | last post by:
How can i load an interface from a dll using System.Reflection? I can see how its possible to do this on methods, properties in a class. You...
3
by: Thomas Müller-Lynch | last post by:
How can I avoid late binding with the directive strict = tru My ASP .net-file looks like this <%@DEBUG=true TRACE=true Strict=false...
30
by: lgbjr | last post by:
hi All, I've decided to use Options Strict ON in one of my apps and now I'm trying to fix a late binding issue. I have 5 integer arrays: dim...
4
by: Rippo | last post by:
Hi I have the following console application and am attempting to late bind a class with option strict on! However of course I cant and I get the...
1
by: nelsonivan | last post by:
Hi, i'm trying to reference some objects using reflection and Late Binding accessing. The Object API to his methods it's easy to understand,...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

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.