.net 哪些是可在枚举中使用的可接受特殊字符?

.net 哪些是可在枚举中使用的可接受特殊字符?,.net,vb.net,syntax,enums,character,.net,Vb.net,Syntax,Enums,Character,这是一个场景: 我使用的是第三方SDK dll,我应该将预定义的字符串参数传递给几乎所有的dll方法,并且存在800多个预定义的可能字符串传递给该方法,文档非常糟糕,示例已经过时,所讨论的dll是MediaInfoLib,字符串区分大小写,因此很容易发生错误(任何人都能记住所有这800个字符串的语法…),因此我想将所有可能的符放在枚举中,以便像这样调用该方法: sub method(byval param as myEnum) call API method(param.tostring)

这是一个场景:

我使用的是第三方SDK dll,我应该将
预定义的
字符串参数传递给几乎所有的dll方法,并且存在800多个预定义的可能字符串传递给该方法,文档非常糟糕,示例已经过时,所讨论的dll是
MediaInfoLib
,字符串区分大小写,因此很容易发生错误(任何人都能记住所有这800个字符串的语法…),因此我想将所有可能的符放在枚举中,以便像这样调用该方法:

sub method(byval param as myEnum)

  call API method(param.tostring)

End sub
StreamKind/String
CodecID/Url  
Public Enum MediaInfoOption

    ''' <summary>
    ''' Format used
    ''' </summary>
    Format

    ''' <summary>
    ''' Commercial name used by vendor for theses setings or Format field if there is no difference
    ''' </summary>
    Format_Commercial

    ''' <summary>
    ''' Commercial name used by vendor for theses setings if there is one
    ''' </summary>
    Format_Commercial_IfAny

    ''' <summary>
    ''' Compression method used
    ''' </summary>
    Format_Compression

    ''' <summary>
    ''' Profile of this Format
    ''' </summary>
    Format_Profile

    ''' <summary>
    ''' Settings needed for decoder used
    ''' </summary>
    Format_Settings

  etc...

End Enum
这样,任何错误都可能发生,因为正确的stringcase语法是由我在枚举中指定的,并且还有一个优点,即我不需要记住800个字符串的语法,我可以从枚举中选择所需的值

问题是有些字符串的名称如下:

sub method(byval param as myEnum)

  call API method(param.tostring)

End sub
StreamKind/String
CodecID/Url  
Public Enum MediaInfoOption

    ''' <summary>
    ''' Format used
    ''' </summary>
    Format

    ''' <summary>
    ''' Commercial name used by vendor for theses setings or Format field if there is no difference
    ''' </summary>
    Format_Commercial

    ''' <summary>
    ''' Commercial name used by vendor for theses setings if there is one
    ''' </summary>
    Format_Commercial_IfAny

    ''' <summary>
    ''' Compression method used
    ''' </summary>
    Format_Compression

    ''' <summary>
    ''' Profile of this Format
    ''' </summary>
    Format_Profile

    ''' <summary>
    ''' Settings needed for decoder used
    ''' </summary>
    Format_Settings

  etc...

End Enum
…我无法将/char放入枚举中

当然,我考虑过将“/”字符替换为“\”字符,但我不能这样做,因为还有一些其他字符串名称如下:

CodecID_Description
Width_Offset
因此,如果我替换这些字符,我会得到一个假阳性

那我能用这个做什么

我找不到任何可以在枚举中使用的特殊字符,因为它与VB运算符发生冲突

我想知道是否存在一个枚举的接受/禁止字符列表,或者是否有人知道一个好的特殊字符,我可以用它来代替“/”字符?,对于特殊字符,我指的是任何人,但不是这些字母表中的任何人:因为我正在搜索一个看起来像分隔符的接受字符

或者有其他想法吗?

我经常使用MediaInfo.DLL,我知道你在说什么。首先,您可以通过一个Info方法捕获所有参数及其返回的内容,并保存到文本文件中,例如:

Info_Parameters           (this is the mediaInfo key to use to tell it 
                          to dump all the params it knows)
General 
Count                     : Number of objects available in this stream
Status       : bit field (0=IsAccepted, 1=IsFilled, 2=IsUpdated,   3=IsFinished)
StreamCount               : Number of streams of this kind available
StreamKind                : Stream type name
显而易见的答案是,您正在尝试将枚举用作类:这不仅仅是代码中有意义的标识符,您还希望在其他地方将名称用作参数。我去过那里,做过那件事。我是这样处理的(这不会完全回答你的问题,因为你心里已经有了答案):

轮询MediaInfo以获取信息只需遍历propsList并向MediaInfo提供存储的参数:要轮询的流是MIGrp,属性键来自MIKey,这可能就是您所需要的(我的实现还存储输出、格式化输出等等)。要在开发过程中添加新项,只需添加新的枚举项即可。(我使用了一个列表(T),以便保留顺序,并避免显示顺序属性(请参见下面的链接),您可能需要一个字典通过枚举值获取各种MediaInfo属性。)

我有3个应用程序使用这个,其中一个是。除了MediaInfoitem列表之外,不需要任何代码,只需将数据发布到ListView以供显示(MIGrp的另一个用途,只是另一个循环)

HTH

我经常使用MediaInfo.DLL,我知道你在说什么。首先,您可以通过一个Info方法捕获所有参数及其返回的内容,并保存到文本文件中,例如:

Info_Parameters           (this is the mediaInfo key to use to tell it 
                          to dump all the params it knows)
General 
Count                     : Number of objects available in this stream
Status       : bit field (0=IsAccepted, 1=IsFilled, 2=IsUpdated,   3=IsFinished)
StreamCount               : Number of streams of this kind available
StreamKind                : Stream type name
显而易见的答案是,您正在尝试将枚举用作类:这不仅仅是代码中有意义的标识符,您还希望在其他地方将名称用作参数。我去过那里,做过那件事。我是这样处理的(这不会完全回答你的问题,因为你心里已经有了答案):

轮询MediaInfo以获取信息只需遍历propsList并向MediaInfo提供存储的参数:要轮询的流是MIGrp,属性键来自MIKey,这可能就是您所需要的(我的实现还存储输出、格式化输出等等)。要在开发过程中添加新项,只需添加新的枚举项即可。(我使用了一个列表(T),以便保留顺序,并避免显示顺序属性(请参见下面的链接),您可能需要一个字典通过枚举值获取各种MediaInfo属性。)

我有3个应用程序使用这个,其中一个是。除了MediaInfoitem列表之外,不需要任何代码,只需将数据发布到ListView以供显示(MIGrp的另一个用途,只是另一个循环)


HTH

我想分享我的解决方案,这段代码将MediaInfo参数检索为CSV列表,并过滤该列表以写入枚举成员及其摘要文档

一些需要澄清的事情:

  • 参数是连接和排序的,因此它们与mediainfo.dll
    GetInfoI
    方法(需要整数)不匹配,通过这种方式,此枚举可以与需要字符串的
    GetInfo
    方法完美结合使用,这样做的目的是避免使用
    GetInfoI
    ,因为对于这个枚举,我认为
    GetInfoI
    方法已经过时,没有用处

  • 生成的枚举大约有3000行,它需要手动删除一些重复项,大约20个重复项,删除它们只需5分钟

  • /
    字符被替换为
    \uuu
    ,因此我重写了原始的MediaInfo VBNET SDK示例,我的方法如下所示:

    ''' <summary>
    ''' Gets a piece of information about a file.
    ''' </summary>
    ''' <param name="StreamKind">
    ''' Kind of stream (general, video, audio...).
    ''' </param>
    ''' <param name="StreamNumber">
    ''' Stream number in this kind of stream (first, second...).
    ''' </param>
    ''' <param name="Info">
    ''' The information to retrieve.
    ''' </param>
    ''' <param name="KindOfInfo">
    ''' Kind of information you want about the parameter (the text, the measure, the help...). 
    ''' </param>
    ''' <param name="KindOfSearch">
    ''' Where to look for the parameter . 
    ''' </param>
    Public Function GetInfo(ByVal StreamKind As StreamKind,
                            ByVal StreamNumber As Integer,
                            ByVal Info As MediaInfoOption,
                            Optional ByVal KindOfInfo As InfoKind = InfoKind.Text,
                            Optional ByVal KindOfSearch As InfoKind = InfoKind.Name) As String
    
    Return System.Runtime.InteropServices.
           Marshal.PtrToStringUni(SafeNativeMethods.
                                  MediaInfo_Get(Handle,
                                                New IntPtr(StreamKind),
                                                New IntPtr(StreamNumber),
                                                Info.ToString.Replace("_s_", "(s)").Replace("__", "/"),
                                                New IntPtr(KindOfInfo),
                                                New IntPtr(KindOfSearch)))
    
    End Function
    
    “”
    ''获取有关文件的一条信息。
    ''' 
    ''' 
    ''流的类型(一般、视频、音频…)。
    ''' 
    ''' 
    ''此类流中的流编号(第一,第二…)。
    ''' 
    ''' 
    ''要检索的信息。
    ''' 
    ''' 
    ''您想要的关于参数的信息(文本、度量、帮助…)。
    ''' 
    ''' 
    ''在何处查找参数。
    ''' 
    公共函数GetInfo(ByVal StreamKind作为StreamKind,
    ByVal StreamNumber为整数,
    ByVal信息作为MediaInfoOption,
    可选的ByVal kindofino作为InfoKind=InfoKind.Text,
    
     Select Case thisEnumVal 
         Case Is =< MediaInfoParms.MAX_GENERAL
            streamKind = MediaInfo.streamGeneral
    
         Case Is =< MediaInfoParms.MAX_AUDIO
             streamKind = MediaInfo.streamAudio
         '...
    
     Public Const Max_MediaInfo_General = 278  '(whatever value)
     Public Const Max_MediaInfo_Video = 482