eelisdotnet
Programmer
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.ResourceFactory))
{
if(_rm == null)
{
string resxNamespace =
typeof(LivingObjects.Resources.ResourceFactory).Namespace;
_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.ResourceFactory))
If _rm Is Nothing Then
Dim resxNamespace As String =
Type.GetType(LivingObjects.Resources.ResourceFactory).Namespace
_rm = New ResourceManager(resxNamespace +
".Labels", System.Reflection.Assembly.GetExecutingAssembly())
End If
Unlock(Type.GetType(LivingObjects.Resources.ResourceFactory))
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.(
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.ResourceFactory))
{
if(_rm == null)
{
string resxNamespace =
typeof(LivingObjects.Resources.ResourceFactory).Namespace;
_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.ResourceFactory))
If _rm Is Nothing Then
Dim resxNamespace As String =
Type.GetType(LivingObjects.Resources.ResourceFactory).Namespace
_rm = New ResourceManager(resxNamespace +
".Labels", System.Reflection.Assembly.GetExecutingAssembly())
End If
Unlock(Type.GetType(LivingObjects.Resources.ResourceFactory))
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.(