C# 编辑文件元数据-代码在VB中很好,但在C中不是#
下面是当前使用的VB.NET方法,效果很好C# 编辑文件元数据-代码在VB中很好,但在C中不是#,c#,.net,vb.net,reflection,metadata,C#,.net,Vb.net,Reflection,Metadata,下面是当前使用的VB.NET方法,效果很好 Private Sub editMetadata(ByRef bmp1 As Bitmap, ByVal intTitleId As Integer, ByVal strTitle As String) Dim ci As System.Reflection.ConstructorInfo = _ GetType(PropertyItem).GetConstructor(BindingFl
Private Sub editMetadata(ByRef bmp1 As Bitmap, ByVal intTitleId As Integer, ByVal strTitle As String)
Dim ci As System.Reflection.ConstructorInfo = _
GetType(PropertyItem).GetConstructor(BindingFlags.NonPublic Or _
BindingFlags.Instance Or BindingFlags.[Public], Nothing, New Type() {}, Nothing)
Dim outPropertyItem As PropertyItem = DirectCast(ci.Invoke(Nothing), PropertyItem)
outPropertyItem.Id = intTitleId
' Type=1 means Array of Bytes.
outPropertyItem.Type = 1
outPropertyItem.Len = strTitle.Length
outPropertyItem.Value = Encoding.Unicode.GetBytes(strTitle)
bmp1.SetPropertyItem(outPropertyItem)
End Sub
现在在C#中,我遇到了这个方法的第一行的障碍
System.Reflection.ConstructorInfo ci =
GetType(PropertyItem).GetConstructor( BindingFlags.NonPublic ||
BindingFlags.Instance || BindingFlags.[Public], null, new Type() {}, null);
在将VB的语法转换为C#(我所熟悉的)之后,我在这一部分仍然有6个错误
所以,这个问题可以通过两种方式解决 上面显示的代码的正确C#语法是什么 或者 如何在C#中正确编辑文件元数据
谢谢你的帮助 在BindingFlagsAh中使用|而不是| |,这样就消除了错误#3。谢谢:)!!我已经删除了BindingFlags.Public周围的[],然后这一切都是正确的。谢谢如果允许,将在10分钟内标记为答案。
System.Reflection.ConstructorInfo ci =
typeof(PropertyItem).GetConstructor( BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.Public, null, new Type[] {}, null);