Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's an ansi class in C#?

I started using reflection in my project.

When I create a type and I want to specify the TypeAttributes, I have two options: AnsiClass and Class. They are both set to 0 in the enum TypeAttributes.

public enum TypeAttributes
{
    //     LPTSTR is interpreted as ANSI.
    AnsiClass = 0,
    //
    // Summary:
    //     Specifies that the type is a class.
    Class = 0,
...

1- What's an ANSI Class (I noticed that, it's related to the LPTSTR, but I didn't understood well enough)?

2- What's the difference between an AnsiClass and a Class when I use Reflection.

EDIT

Here's an example of specifying the TypeAttributes in Reflection:

TypeBuilder typeBuilder = mbuilder.DefineType("DataRow", TypeAttributes.Public | TypeAttributes.AnsiClass | TypeAttributes.Class);
like image 999
billybob Avatar asked Mar 11 '15 14:03

billybob


1 Answers

I have two options: AnsiClass and Class

No, those are orthogonal. AnsiClass tells the marshaller that all string properties are to be marshalled as ANSI strings. The other options in that category are:

UnicodeClass
AutoClass
CustomFormatClass

Class indicates that they type is, well, a class. The only other option in that group is Interface. Interestingly, when you look at the attributes of framework types, classes, structs, and interfaces all have the Class attribute, so I'm not sure what it's used for.

 typeof(object).Attributes.Dump();   
 typeof(int).Attributes.Dump();   
 typeof(ICloneable).Attributes.Dump();  

output:

AutoLayout, AnsiClass, Class, Public, Serializable, BeforeFieldInit
AutoLayout, AnsiClass, Class, Public, SequentialLayout, Sealed, Serializable, BeforeFieldInit
AutoLayout, AnsiClass, Class, Public, ClassSemanticsMask, Abstract
like image 137
D Stanley Avatar answered Sep 27 '22 19:09

D Stanley