Imports System
Imports System.Reflection
Imports System.Reflection.Assembly
Imports System.Runtime
Imports System.Runtime.InteropServices
Imports System.Diagnostics'这是VB里的一个取得程序集自身各种属性的代码,可是我把它转成C#就是没通过,
'总提示未将对象实例化。
'Naming rule for Assembly Attributes:
' AssemblyTitle: Short application name, ex: Download MO
' AssemblyDescription: Application version date, ex: 2006/02/28
' AssemblyCompany: Company name, must be "Wistron Corp."
' AssemblyProduct: Application ID, ex: DOWNLOADMO
' AssemblyVersion: Application version, ex: 1.0.0.0Public Module mduAssemblyInfo
Public Enum enumAssemblyInfo
AssemblyTitle = 0
AssemblyDescription
AssemblyCompany
AssemblyProduct
AssemblyCopyright
AssemblyTrade
AssemblyVersion
CLSCompliant
Debuggable
Guid
End Enum Public Function GetAssemblyInfo(ByVal piAssemblyInfo As enumAssemblyInfo) As String
Select Case piAssemblyInfo
Case enumAssemblyInfo.AssemblyCompany
Dim loCompany As AssemblyCompanyAttribute = AssemblyCompanyAttribute.GetCustomAttribute(GetExecutingAssembly, GetType(AssemblyCompanyAttribute))
Return loCompany.Company
'我把它改成这样的
/* Case enumAssemblyInfo.AssemblyCompany:
AssemblyCompanyAttribute loCompany=(AssemblyCompanyAttribute)Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(AssemblyCompanyAttribute));
*/
Case enumAssemblyInfo.AssemblyCopyright
Dim loCopyright As AssemblyCopyrightAttribute = AssemblyCopyrightAttribute.GetCustomAttribute(GetExecutingAssembly, GetType(AssemblyCopyrightAttribute))
Return loCopyright.Copyright Case enumAssemblyInfo.AssemblyDescription
Dim loDescription As AssemblyDescriptionAttribute = AssemblyDescriptionAttribute.GetCustomAttribute(GetExecutingAssembly, GetType(AssemblyDescriptionAttribute))
Return loDescription.Description Case enumAssemblyInfo.AssemblyProduct
Dim loProduct As AssemblyProductAttribute = AssemblyProductAttribute.GetCustomAttribute(GetExecutingAssembly, GetType(AssemblyProductAttribute))
Return loProduct.Product Case enumAssemblyInfo.AssemblyTitle
Dim loTitle As AssemblyTitleAttribute = AssemblyTitleAttribute.GetCustomAttribute(GetExecutingAssembly, GetType(AssemblyTitleAttribute))
Return loTitle.Title Case enumAssemblyInfo.AssemblyTrade
Dim loTrade As AssemblyTradeAttribute = AssemblyTradeAttribute.GetCustomAttribute(GetExecutingAssembly, GetType(AssemblyTradeAttribute))
Return loTrade.Trade Case enumAssemblyInfo.AssemblyVersion
Return System.Reflection.Assembly.GetExecutingAssembly.GetName.Version.ToString() Case enumAssemblyInfo.CLSCompliant
Dim loCLSCompliant As CLSCompliantAttribute = CLSCompliantAttribute.GetCustomAttribute(GetExecutingAssembly, GetType(CLSCompliantAttribute))
Return loCLSCompliant.IsCompliant.ToString() Case enumAssemblyInfo.Debuggable
Dim loDebuggable As DebuggableAttribute = DebuggableAttribute.GetCustomAttribute(GetExecutingAssembly, GetType(DebuggableAttribute))
Return loDebuggable.IsJITTrackingEnabled.ToString() Case enumAssemblyInfo.Guid
Dim loGuid As GuidAttribute = GuidAttribute.GetCustomAttribute(GetExecutingAssembly, GetType(GuidAttribute))
Return loGuid.Value
End Select
End FunctionEnd Module
Imports System.Reflection
Imports System.Reflection.Assembly
Imports System.Runtime
Imports System.Runtime.InteropServices
Imports System.Diagnostics'这是VB里的一个取得程序集自身各种属性的代码,可是我把它转成C#就是没通过,
'总提示未将对象实例化。
'Naming rule for Assembly Attributes:
' AssemblyTitle: Short application name, ex: Download MO
' AssemblyDescription: Application version date, ex: 2006/02/28
' AssemblyCompany: Company name, must be "Wistron Corp."
' AssemblyProduct: Application ID, ex: DOWNLOADMO
' AssemblyVersion: Application version, ex: 1.0.0.0Public Module mduAssemblyInfo
Public Enum enumAssemblyInfo
AssemblyTitle = 0
AssemblyDescription
AssemblyCompany
AssemblyProduct
AssemblyCopyright
AssemblyTrade
AssemblyVersion
CLSCompliant
Debuggable
Guid
End Enum Public Function GetAssemblyInfo(ByVal piAssemblyInfo As enumAssemblyInfo) As String
Select Case piAssemblyInfo
Case enumAssemblyInfo.AssemblyCompany
Dim loCompany As AssemblyCompanyAttribute = AssemblyCompanyAttribute.GetCustomAttribute(GetExecutingAssembly, GetType(AssemblyCompanyAttribute))
Return loCompany.Company
'我把它改成这样的
/* Case enumAssemblyInfo.AssemblyCompany:
AssemblyCompanyAttribute loCompany=(AssemblyCompanyAttribute)Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(AssemblyCompanyAttribute));
*/
Case enumAssemblyInfo.AssemblyCopyright
Dim loCopyright As AssemblyCopyrightAttribute = AssemblyCopyrightAttribute.GetCustomAttribute(GetExecutingAssembly, GetType(AssemblyCopyrightAttribute))
Return loCopyright.Copyright Case enumAssemblyInfo.AssemblyDescription
Dim loDescription As AssemblyDescriptionAttribute = AssemblyDescriptionAttribute.GetCustomAttribute(GetExecutingAssembly, GetType(AssemblyDescriptionAttribute))
Return loDescription.Description Case enumAssemblyInfo.AssemblyProduct
Dim loProduct As AssemblyProductAttribute = AssemblyProductAttribute.GetCustomAttribute(GetExecutingAssembly, GetType(AssemblyProductAttribute))
Return loProduct.Product Case enumAssemblyInfo.AssemblyTitle
Dim loTitle As AssemblyTitleAttribute = AssemblyTitleAttribute.GetCustomAttribute(GetExecutingAssembly, GetType(AssemblyTitleAttribute))
Return loTitle.Title Case enumAssemblyInfo.AssemblyTrade
Dim loTrade As AssemblyTradeAttribute = AssemblyTradeAttribute.GetCustomAttribute(GetExecutingAssembly, GetType(AssemblyTradeAttribute))
Return loTrade.Trade Case enumAssemblyInfo.AssemblyVersion
Return System.Reflection.Assembly.GetExecutingAssembly.GetName.Version.ToString() Case enumAssemblyInfo.CLSCompliant
Dim loCLSCompliant As CLSCompliantAttribute = CLSCompliantAttribute.GetCustomAttribute(GetExecutingAssembly, GetType(CLSCompliantAttribute))
Return loCLSCompliant.IsCompliant.ToString() Case enumAssemblyInfo.Debuggable
Dim loDebuggable As DebuggableAttribute = DebuggableAttribute.GetCustomAttribute(GetExecutingAssembly, GetType(DebuggableAttribute))
Return loDebuggable.IsJITTrackingEnabled.ToString() Case enumAssemblyInfo.Guid
Dim loGuid As GuidAttribute = GuidAttribute.GetCustomAttribute(GetExecutingAssembly, GetType(GuidAttribute))
Return loGuid.Value
End Select
End FunctionEnd Module
'我把它改成这样的
case enumAssemblyInfo.AssemblyCompany:
AssemblyCompanyAttribute loCompany=(AssemblyCompanyAttribute)Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(AssemblyCompanyAttribute));总是提示没有实例化的错误,我就郁闷,为什么VB可以直接赋值,而C#就不可以了????
劝你放弃C#吧,何必翻译它
但要说到强大还是C#。