C# 中的 ansi class 是什么?
What's an ansi class in C#?
我开始在我的项目中使用反射。
当我创建一个类型并想要指定 TypeAttributes 时,我有两个选择:
AnsiClass
和 Class
。它们在枚举 TypeAttributes
.
中都设置为 0
public enum TypeAttributes
{
// LPTSTR is interpreted as ANSI.
AnsiClass = 0,
//
// Summary:
// Specifies that the type is a class.
Class = 0,
...
1- 什么是ANSI Class
(我注意到了,它与LPTSTR
有关,但我理解不够)?
2- 当我使用 Reflection
.
时,AnsiClass
和 Class
有什么区别
编辑
下面是在反射中指定 TypeAttributes 的示例:
TypeBuilder typeBuilder = mbuilder.DefineType("DataRow", TypeAttributes.Public | TypeAttributes.AnsiClass | TypeAttributes.Class);
好吧,如果你看一下 MSDN 是这样说的
https://msdn.microsoft.com/en-us/library/system.type.isansiclass%28v=vs.110%29.aspx
Property Value
Type: System.Boolean
true if the string format attribute AnsiClass is selected for the Type; otherwise, false.
Implements
_Type.IsAnsiClass
这一点用处不大,但如果您查看 TypeAttributes
枚举的 StringFormatMask
,您会发现它的可能值为 {AnsiClass,UnicodeClass,AutoClass,CustomFormatClass}
所以基本上它会通知编译器如何将 class 中的字符串解释为 ANSI 或 Unicode,据我所知,这对 c# 和 vb 没有影响,但会导致如果您使用 c++ classes
会遇到各种问题
见http://www.codeproject.com/Articles/2995/The-Complete-Guide-to-C-Strings-Part-I-Win-Chara
I have two options: AnsiClass and Class
不,它们是正交的。 AnsiClass
告诉编组器所有字符串属性都将编组为 ANSI 字符串。该类别中的其他选项是:
UnicodeClass
AutoClass
CustomFormatClass
Class
表示他们键入的是 class
。该组中唯一的其他选项是 Interface
。有意思的是,看framework types的属性,类、structs、interfaces都有Class
属性,不知道是干什么用的
typeof(object).Attributes.Dump();
typeof(int).Attributes.Dump();
typeof(ICloneable).Attributes.Dump();
输出:
AutoLayout, AnsiClass, Class, Public, Serializable, BeforeFieldInit
AutoLayout, AnsiClass, Class, Public, SequentialLayout, Sealed, Serializable, BeforeFieldInit
AutoLayout, AnsiClass, Class, Public, ClassSemanticsMask, Abstract
我开始在我的项目中使用反射。
当我创建一个类型并想要指定 TypeAttributes 时,我有两个选择:
AnsiClass
和 Class
。它们在枚举 TypeAttributes
.
public enum TypeAttributes
{
// LPTSTR is interpreted as ANSI.
AnsiClass = 0,
//
// Summary:
// Specifies that the type is a class.
Class = 0,
...
1- 什么是ANSI Class
(我注意到了,它与LPTSTR
有关,但我理解不够)?
2- 当我使用 Reflection
.
AnsiClass
和 Class
有什么区别
编辑
下面是在反射中指定 TypeAttributes 的示例:
TypeBuilder typeBuilder = mbuilder.DefineType("DataRow", TypeAttributes.Public | TypeAttributes.AnsiClass | TypeAttributes.Class);
好吧,如果你看一下 MSDN 是这样说的
https://msdn.microsoft.com/en-us/library/system.type.isansiclass%28v=vs.110%29.aspx
Property Value
Type: System.Boolean
true if the string format attribute AnsiClass is selected for the Type; otherwise, false.
Implements _Type.IsAnsiClass
这一点用处不大,但如果您查看 TypeAttributes
枚举的 StringFormatMask
,您会发现它的可能值为 {AnsiClass,UnicodeClass,AutoClass,CustomFormatClass}
所以基本上它会通知编译器如何将 class 中的字符串解释为 ANSI 或 Unicode,据我所知,这对 c# 和 vb 没有影响,但会导致如果您使用 c++ classes
会遇到各种问题见http://www.codeproject.com/Articles/2995/The-Complete-Guide-to-C-Strings-Part-I-Win-Chara
I have two options: AnsiClass and Class
不,它们是正交的。 AnsiClass
告诉编组器所有字符串属性都将编组为 ANSI 字符串。该类别中的其他选项是:
UnicodeClass
AutoClass
CustomFormatClass
Class
表示他们键入的是 class
。该组中唯一的其他选项是 Interface
。有意思的是,看framework types的属性,类、structs、interfaces都有Class
属性,不知道是干什么用的
typeof(object).Attributes.Dump();
typeof(int).Attributes.Dump();
typeof(ICloneable).Attributes.Dump();
输出:
AutoLayout, AnsiClass, Class, Public, Serializable, BeforeFieldInit
AutoLayout, AnsiClass, Class, Public, SequentialLayout, Sealed, Serializable, BeforeFieldInit
AutoLayout, AnsiClass, Class, Public, ClassSemanticsMask, Abstract