error on Dim info1 As PropertyInfo = component1.GetType.GetProperty(Me.member.Name)

C

Carlos Rodriguez

I have the following function in C#public void Undo(IDesignerHost host)
{
if (!this.componentName.Equals(string.Empty) && (this.member != null))
{
IContainer container1 = (IContainer)
host.GetService(typeof(IContainer));
IComponent component1 =
container1.Components[this.componentName];
PropertyInfo info1 =
component1.GetType().GetProperty(this.member.Name);
if (this.isCollection)
{
IList list1 = (IList) info1.GetValue(component1, null);
if (this.oldValue != null)
{
if (this.isComponentCollection)
{
int num1 = 0;
foreach (string text1 in ((object[])
this.oldValue))
{
try
{
if (list1 is
Menu.MenuItemCollection)
{
((Menu.MenuItemCollection)
list1).Add(num1++, (MenuItem) host.Container.Components[text1]);
}
else
{
list1.Add(host.Container.Components[text1]);
}
}
catch (Exception exception1)
{
Debug.WriteLine(exception1.Message);
}
}
}
else
{
foreach (object obj1 in ((object[])
this.oldValue))
{
list1.Add(obj1);
}
}
if (component1 is Control)
{
((Control) component1).Refresh();
}
}
}
else
{
info1.SetValue(component1, this.oldValue, null);
}
}
}
and when I convert it to VB.NET is this:public Sub Undo(ByVal host As
IDesignerHost)
If (Not Me.componentName.Equals(String.Empty) AndAlso (Not Me.member
Is Nothing)) Then
Dim container1 As IContainer =
DirectCast(host.GetService(GetType(IContainer)), IContainer)
Dim component1 As IComponent =
container1.Components.Item(Me.componentName)
Dim info1 As PropertyInfo =
component1.GetType.GetProperty(Me.member.Name)
If Me.isCollection Then
Dim list1 As IList = DirectCast(info1.GetValue(component1,
Nothing), IList)
If (Not Me.oldValue Is Nothing) Then
If Me.isComponentCollection Then
Dim num1 As Integer = 0
Dim text1 As String
For Each text1 In DirectCast(Me.oldValue,
Object())
Try
If TypeOf list1 Is
MenuItemCollection Then
DirectCast(list1,
MenuItemCollection).Add(num1++,
DirectCast(host.Container.Components.Item(text1), MenuItem))
Else
list1.Add(host.Container.Components.Item(text1))
End If
Catch exception1 As Exception
Debug.WriteLine(exception1.Message)
End Try
Next
Else
Dim obj1 As Object
For Each obj1 In DirectCast(Me.oldValue,
Object())
list1.Add(obj1)
Next
End If
If TypeOf component1 Is Control Then
DirectCast(component1, Control).Refresh
End If
End If
Else
info1.SetValue(component1, Me.oldValue, Nothing)
End If
End If
End Sub
how do I do to get the Type (component1.GetType) this cause an error Dim
info1 As PropertyInfo = component1.GetType.GetProperty(member.Name)
 
S

Stephany Young

Dim info1 As PropertyInfo = component1.GetType().GetProperty(member.Name)

The clue is clearly present in the c# version.
 
C

Carlos Rodriguez

Found it!!!!!

Here`s the good way:


Dim info1a As PropertyInfo = CType(component1,
Object).GetType.GetProperty(member.Name)


because in here :
Dim info1 As PropertyInfo = component1.GetType().GetProperty(member.Name)

the component1 it is a IComponent tthat does not have the GetType member,
so its converted to an object first to get the GetType



Young said:
Dim info1 As PropertyInfo = component1.GetType().GetProperty(member.Name)

The clue is clearly present in the c# version.


Carlos Rodriguez said:
I have the following function in C#public void Undo(IDesignerHost host)
{
if (!this.componentName.Equals(string.Empty) && (this.member !=
null))
{
IContainer container1 = (IContainer)
host.GetService(typeof(IContainer));
IComponent component1 =
container1.Components[this.componentName];
PropertyInfo info1 =
component1.GetType().GetProperty(this.member.Name);
if (this.isCollection)
{
IList list1 = (IList) info1.GetValue(component1, null);
if (this.oldValue != null)
{
if (this.isComponentCollection)
{
int num1 = 0;
foreach (string text1 in ((object[])
this.oldValue))
{
try
{
if (list1 is
Menu.MenuItemCollection)
{
((Menu.MenuItemCollection)
list1).Add(num1++, (MenuItem) host.Container.Components[text1]);
}
else
{

list1.Add(host.Container.Components[text1]);
}
}
catch (Exception exception1)
{

Debug.WriteLine(exception1.Message);
}
}
}
else
{
foreach (object obj1 in ((object[])
this.oldValue))
{
list1.Add(obj1);
}
}
if (component1 is Control)
{
((Control) component1).Refresh();
}
}
}
else
{
info1.SetValue(component1, this.oldValue, null);
}
}
}
and when I convert it to VB.NET is this:public Sub Undo(ByVal host As
IDesignerHost)
If (Not Me.componentName.Equals(String.Empty) AndAlso (Not Me.member
Is Nothing)) Then
Dim container1 As IContainer =
DirectCast(host.GetService(GetType(IContainer)), IContainer)
Dim component1 As IComponent =
container1.Components.Item(Me.componentName)
Dim info1 As PropertyInfo =
component1.GetType.GetProperty(Me.member.Name)
If Me.isCollection Then
Dim list1 As IList =
DirectCast(info1.GetValue(component1, Nothing), IList)
If (Not Me.oldValue Is Nothing) Then
If Me.isComponentCollection Then
Dim num1 As Integer = 0
Dim text1 As String
For Each text1 In DirectCast(Me.oldValue,
Object())
Try
If TypeOf list1 Is
MenuItemCollection Then
DirectCast(list1,
MenuItemCollection).Add(num1++,
DirectCast(host.Container.Components.Item(text1), MenuItem))
Else

list1.Add(host.Container.Components.Item(text1))
End If
Catch exception1 As Exception

Debug.WriteLine(exception1.Message)
End Try
Next
Else
Dim obj1 As Object
For Each obj1 In DirectCast(Me.oldValue,
Object())
list1.Add(obj1)
Next
End If
If TypeOf component1 Is Control Then
DirectCast(component1, Control).Refresh
End If
End If
Else
info1.SetValue(component1, Me.oldValue, Nothing)
End If
End If
End Sub
how do I do to get the Type (component1.GetType) this cause an error Dim
info1 As PropertyInfo = component1.GetType.GetProperty(member.Name)
 
Top