【发布时间】:2013-10-02 13:49:56
【问题描述】:
这是目前使用的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(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# 中正确编辑文件元数据。
感谢您的帮助!
【问题讨论】:
-
使用 |而不是 ||在 BindingFlags
-
啊,消除了错误 #3。谢谢你:) !!
标签: c# .net vb.net reflection metadata