By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,579 Members | 1,765 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,579 IT Pros & Developers. It's quick & easy.

type cannot be used as an expression

P: n/a
Hi

I tried to convert the following C# code to vb.net.

code in C#
__________________________________________________ ______________
using System;
using System.Reflection;
using System.Resources;

namespace LivingObjects.Resources
{
/// <summary>
/// This Class is used to create the ResourceManager for the site.
/// It manages a single instance of this object.
/// </summary>
internal class ResourceFactory
{
/// <summary>
/// Private Contructor. This factory is a static implementation.
/// It cannot be instanciated.
/// </summary>
private ResourceFactory()
{
}

private static ResourceManager _rm;

public static ResourceManager ResourceManager
{
get
{
if(_rm == null)
{
lock(typeof(LivingObjects.Resources.ResourceFactor y))
{
if(_rm == null)
{
string resxNamespace =
typeof(LivingObjects.Resources.ResourceFactory).Na mespace;
_rm = new ResourceManager(resxNamespace + ".Labels",
System.Reflection.Assembly.GetExecutingAssembly()) ;
}
}
}
return _rm;
}
}

public static string GetLabel(string resourceID)
{
return ResourceManager.GetString(resourceID);
}
}
}
__________________________________________________ _______________________

code in VB.Net
__________________________________________________ _______________________
Imports System
Imports System.Reflection
Imports System.Resources

Namespace LivingObjects.Resources

' This Class is used to create the ResourceManager for the site.
' It manages a single instance of this object.

Friend Class ResourceFactory

' Private Contructor. This factory is a static implementation.
' It cannot be instanciated.
Private Sub New()
End Sub

Private Shared _rm As ResourceManager

Public Shared ReadOnly Property ResourceManager() As
ResourceManager
Get
If _rm Is Nothing Then
Lock(Type.GetType(LivingObjects.Resources.Resource Factory))
If _rm Is Nothing Then
Dim resxNamespace As String =
Type.GetType(LivingObjects.Resources.ResourceFacto ry).Namespace
_rm = New ResourceManager(resxNamespace +
".Labels", System.Reflection.Assembly.GetExecutingAssembly())
End If
Unlock(Type.GetType(LivingObjects.Resources.Resour ceFactory))
End If
Return _rm
End Get
End Property

Public Shared Function GetLabel(ByVal resourceID As String) As
String
Return ResourceManager.GetString(resourceID)
End Function

End Class

End Namespace
__________________________________________________ ________________________

The error comes in vb.net whenever I use
'LivingObjects.Resources.ResourceFactory'.
The build error says: "'ResourceFactory' is a type in 'Resources' and
cannot be used as an expression."

How can it be implemented then in vb.net? any ideas?

Thanks,

Eelis

p.s. The C# code was created by Jonathan
Gauthier.(http://www.codetools.com/cs/miscctrl...emListView.asp)
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Try replacing Type.GetType with the GetType function:

GetType(LivingObjects.Resources.ResourceFactory)
instead of:
Type.GetType(LivingObjects.Resources.ResourceFacto ry)
Imran.

"eelis.net" <ee*****@yahoo.com> wrote in message
news:32**************************@posting.google.c om...
Hi

I tried to convert the following C# code to vb.net.

code in C#
__________________________________________________ ______________
using System;
using System.Reflection;
using System.Resources;

namespace LivingObjects.Resources
{
/// <summary>
/// This Class is used to create the ResourceManager for the site.
/// It manages a single instance of this object.
/// </summary>
internal class ResourceFactory
{
/// <summary>
/// Private Contructor. This factory is a static implementation.
/// It cannot be instanciated.
/// </summary>
private ResourceFactory()
{
}

private static ResourceManager _rm;

public static ResourceManager ResourceManager
{
get
{
if(_rm == null)
{
lock(typeof(LivingObjects.Resources.ResourceFactor y))
{
if(_rm == null)
{
string resxNamespace =
typeof(LivingObjects.Resources.ResourceFactory).Na mespace;
_rm = new ResourceManager(resxNamespace + ".Labels",
System.Reflection.Assembly.GetExecutingAssembly()) ;
}
}
}
return _rm;
}
}

public static string GetLabel(string resourceID)
{
return ResourceManager.GetString(resourceID);
}
}
}
__________________________________________________ _______________________

code in VB.Net
__________________________________________________ _______________________
Imports System
Imports System.Reflection
Imports System.Resources

Namespace LivingObjects.Resources

' This Class is used to create the ResourceManager for the site.
' It manages a single instance of this object.

Friend Class ResourceFactory

' Private Contructor. This factory is a static implementation.
' It cannot be instanciated.
Private Sub New()
End Sub

Private Shared _rm As ResourceManager

Public Shared ReadOnly Property ResourceManager() As
ResourceManager
Get
If _rm Is Nothing Then
Lock(Type.GetType(LivingObjects.Resources.Resource Factory)) If _rm Is Nothing Then
Dim resxNamespace As String =
Type.GetType(LivingObjects.Resources.ResourceFacto ry).Namespace
_rm = New ResourceManager(resxNamespace +
".Labels", System.Reflection.Assembly.GetExecutingAssembly())
End If
Unlock(Type.GetType(LivingObjects.Resources.Resour ceFactory)) End If
Return _rm
End Get
End Property

Public Shared Function GetLabel(ByVal resourceID As String) As
String
Return ResourceManager.GetString(resourceID)
End Function

End Class

End Namespace
__________________________________________________ ________________________

The error comes in vb.net whenever I use
'LivingObjects.Resources.ResourceFactory'.
The build error says: "'ResourceFactory' is a type in 'Resources' and
cannot be used as an expression."

How can it be implemented then in vb.net? any ideas?

Thanks,

Eelis

p.s. The C# code was created by Jonathan
Gauthier.(http://www.codetools.com/cs/miscctrl...emListView.asp)

Nov 21 '05 #2

P: n/a
Hi again

That didn't work either. It makes a build error described as:
"value of type 'System.Type' cannot be converted to 'Integer'" for the
whole expression (GetType(LivingObjects.Resources.ResourceFactory)) .

Any other ideas...

Thanks a lot!

eelis

"Imran Koradia" <no****@microsoft.com> wrote in message news:<OG**************@TK2MSFTNGP11.phx.gbl>...
Try replacing Type.GetType with the GetType function:

GetType(LivingObjects.Resources.ResourceFactory)
instead of:
Type.GetType(LivingObjects.Resources.ResourceFacto ry)
Imran.

Nov 21 '05 #3

P: n/a

"eelis.net" <ee*****@yahoo.com> wrote
That didn't work either. It makes a build error described as:
"value of type 'System.Type' cannot be converted to 'Integer'" for the
whole expression (GetType(LivingObjects.Resources.ResourceFactory)) .

Any other ideas...

How about

LivingObjects.Resources.ResourceFactory.GetType.Na mespace
The docs say GetType expects a string, at best you're giving it
an object. If the above doesn't work, try passing it a string with
that full name in it.

HTH
LFS

Nov 21 '05 #4

P: n/a
Sorry for the late reply - my outlook express is way out of whack with
message threads.

Anyway, the 'lock' in C# and VB.NET mean different things. Here's how your
VB.NET code should look like:

Imports System
Imports System.Reflection
Imports System.Resources

Namespace LivingObjects.Resources

' This Class is used to create the ResourceManager for the site.
' It manages a single instance of this object.

Friend Class ResourceFactory

' Private Contructor. This factory is a static implementation.
' It cannot be instanciated.
Private Sub New()
End Sub

Private Shared _rm As ResourceManager

Public Shared ReadOnly Property _
ResourceManager() As ResourceManager
Get
If _rm Is Nothing Then
SyncLock GetType( _
LivingObjects.Resources.ResourceFactory)
If _rm Is Nothing Then
Dim resxNamespace As String = _
GetType( _

LivingObjects.Resources.ResourceFactory).Namespace
_rm = New ResourceManager(resxNamespace + ".Labels",
_

System.Reflection.Assembly.GetExecutingAssembly())
End If
End SyncLock
End If
Return _rm
End Get
End Property

Public Shared Function GetLabel( _
ByVal resourceID As String) As String
Return ResourceManager.GetString(resourceID)
End Function

End Class

End Namespace
hope that helps..
Imran.

"eelis.net" <ee*****@yahoo.com> wrote in message
news:32**************************@posting.google.c om...
Hi again

That didn't work either. It makes a build error described as:
"value of type 'System.Type' cannot be converted to 'Integer'" for the
whole expression (GetType(LivingObjects.Resources.ResourceFactory)) .

Any other ideas...

Thanks a lot!

eelis

"Imran Koradia" <no****@microsoft.com> wrote in message

news:<OG**************@TK2MSFTNGP11.phx.gbl>...
Try replacing Type.GetType with the GetType function:

GetType(LivingObjects.Resources.ResourceFactory)
instead of:
Type.GetType(LivingObjects.Resources.ResourceFacto ry)
Imran.

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.