TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
matt Gomm
NA
18
841
create or generate automatically struct
Jul 30 2019 3:00 AM
Hello everyone,
I am actually trying to create or generate automatically struct using the class "TypeBuilder".
I have already found a solution to create an "enum".
Here is the Code that I found as example on the microsoft-page:
using
System.Reflection;
using
System.Reflection.Emit;
namespace
testnamespace
{
class
test
{
public
void
CreateEnum()
{
// Get the current application domain for the current thread.
AppDomain currentDomain = AppDomain.CurrentDomain;
// Create a dynamic assembly in the current application domain,
// and allow it to be executed and saved to disk.
AssemblyName aName =
new
AssemblyName(
"TempAssembly"
);
AssemblyBuilder ab = currentDomain.DefineDynamicAssembly(
aName, AssemblyBuilderAccess.RunAndSave);
// Define a dynamic module in "TempAssembly" assembly. For a single-
// module assembly, the module has the same name as the assembly.
ModuleBuilder mb = ab.DefineDynamicModule(aName.Name, aName.Name +
".dll"
);
// Define a public enumeration with the name "Elevation" and an
// underlying type of Integer.
EnumBuilder eb = mb.DefineEnum(
"Elevation"
, TypeAttributes.Public,
typeof
(
int
));
// Define two members, "High" and "Low".
eb.DefineLiteral(
"Low"
, 0);
eb.DefineLiteral(
"High"
, 1);
// Create the type and save the assembly.
Type finished = eb.CreateType();
ab.Save(aName.Name +
".dll"
);
foreach
(
object
o
in
Enum.GetValues(finished) )
{
Console.WriteLine(
"{0}.{1} = {2}"
, finished, o, ((
int
) o));
}
}
How can I do the same procedure to get a struct (NOT A CLASS ;) )
Thank you.
Reply
Answers (
4
)
How to create a document in Adobe in-design in C# or Java
DMA (Direct Memory access)