2011-08-22 64 views
0

我有一个方法问题用VB到C#转换

Public Property ConfigKeys(ByVal keyName As String) As WinItUtils.Classes.ConfigKey 
      Get 
       Return GetConfigKey(keyName) 
      End Get 
      Set(ByVal value As WinItUtils.Classes.ConfigKey) 
       SetConfigKey(value) 
      End Set 
     End Property 

和转换器http://www.developerfusion.com/tools/convert/vb-to-csharp/给我

public WinItUtils.Classes.ConfigKey ConfigKeys 
     { 
      get { return GetConfigKey(keyName); } 
      set { SetConfigKey(value); } 
     } 

这完全是无稽之谈。或者,也许这是一件我不知道:/ 我在Visual Basic中的新手,所以也许我失去了一些东西 我使用.NET 4.0

这里是ConfigKey类:

Namespace Classes 

    ''' <summary> 
    ''' Business class that implements a configuration key from WINIT_CONFIG table. 
    ''' </summary> 
    ''' <remarks></remarks> 
    Public Class ConfigKey 
     Implements IEquatable(Of ConfigKey) 

     Private _resourceKey As String 

     Private _value As String 

     Private _id As Integer 

     Private _handlerId As Integer 

     Private _configType As WinItUtils.Enums.WinItConfigTypes 

     Public Sub New() 
     End Sub 

     Public Property Id() As Integer 
      Get 
       Return _id 
      End Get 
      Set(ByVal value As Integer) 
       _id = value 
      End Set 
     End Property 

     Public ReadOnly Property IsGlobal() As Boolean 
      Get 
       Return _handlerId < 0 
      End Get 
     End Property 

     Public Property HandlerId() As Integer 
      Get 
       Return _handlerId 
      End Get 
      Set(ByVal value As Integer) 
       _handlerId = value 
      End Set 
     End Property 

     Public Property ResourceKey() As String 
      Get 
       Return _resourceKey 
      End Get 
      Set(ByVal value As String) 
       _resourceKey = value 
      End Set 
     End Property 

     Public Property ConfigType() As WinItUtils.Enums.WinItConfigTypes 
      Get 
       Return _configType 
      End Get 
      Set(ByVal value As WinItUtils.Enums.WinItConfigTypes) 
       _configType = value 
      End Set 
     End Property 

     Public Property Value() As String 
      Get 
       Return _value 
      End Get 
      Set(ByVal value As String) 
       _value = value 
      End Set 
     End Property 

     Public Overrides Function Equals(ByVal obj As Object) As Boolean 
      Return Equals(TryCast(obj, ConfigKey)) 
     End Function 

     Public Overloads Function Equals(ByVal other As ConfigKey) As Boolean _ 
     Implements IEquatable(Of ConfigKey).Equals 
      If other Is Nothing Then 
       Return False 
      End If 

      Return _handlerId = other.HandlerId And _resourceKey.Equals(other.ResourceKey) And _configType = other.ConfigType 
     End Function 

    End Class 

End Namespace 
+0

请参见[索引器(C#编程指南)](http://msdn.microsoft.com/zh-cn/library/6x16t2tx.aspx) –

+0

和[C#中的参数化属性](http://rbgupta.blogspot。 com/2007/03/parameterized-properties-in-c.html) –

+1

实现索引器的小辅助类通常会有一些希望。但是这对那个制定者来说是无望的希望,它不需要* keyname *。你别无选择,只能使用方法。不妨直接公开Get/SetConfigKey()。 –

回答

6

您没有办法。

这是一个参数化属性,C#不支持。

没有将代码直接翻译成C#。
相反,您应该创建一个返回Dictionary<string, ConfigKey>的常规属性。

+0

主要问题是getter中的whith参数keyName。我不知道如何处理它 – user278618

+1

@user:没错。这是C#不支持的参数化属性。 – SLaks

+0

+1,我不能高兴它没有。 – Marc