Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / November 2007

Tip: Looking for answers? Try searching our database.

C# 3.0 Automatic Properties and CodeDom

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ed - 20 Nov 2007 22:14 GMT
Anyone know how to generate an automatic property using CodeDom and VS2008?
Alexander Vasilevsky - 22 Nov 2007 12:06 GMT
Please see code belowpublic FieldBuilder BuildField_id(TypeBuilder type)
{
   FieldBuilder field = type.DefineField(
       "_id",
       typeof(Int32),
         FieldAttributes.Private
       );
   return field;
}
public MethodBuilder BuildMethodget_ID(TypeBuilder type)
{
   // Declaring method builder
   MethodBuilder method = type.DefineMethod("get_ID");
   // Preparing Reflection instances
   FieldInfo field1 = typeof(Role).GetField("_id", BindingFlags.Public |
BindingFlags.NonPublic);
   // Method attributes
   method.Attributes =
         System.Reflection.MethodAttributes.Public
       | System.Reflection.MethodAttributes.HideBySig;
   // Setting return type
   method.SetReturnType(typeof(Int32));
   // Adding parameters
   ILGenerator gen =  method.GetILGenerator();
   // Preparing locals
   LocalBuilder CS$1$0000 =  gen.DeclareLocal(typeof(Int32));
   // Preparing labels
   Label label10 =  gen.DefineLabel();
   // Writing body
   gen.Emit(OpCodes.Nop);
   gen.Emit(OpCodes.Ldarg_0);
   gen.Emit(OpCodes.Ldfld,field1);
   gen.Emit(OpCodes.Stloc_0);
   gen.Emit(OpCodes.Br_S,label10);
   gen.MarkLabel(label10);
   gen.Emit(OpCodes.Ldloc_0);
   gen.Emit(OpCodes.Ret);
   // finished
   return method;
}

http://www.alvas.net  - Audio tools for C# and VB.Net developers

> Anyone know how to generate an automatic property using CodeDom and
> VS2008?
Ed - 26 Nov 2007 14:08 GMT
That'll generate the IL but not CodeDom code.

> Please see code belowpublic FieldBuilder BuildField_id(TypeBuilder type)
> {
[quoted text clipped - 41 lines]
> > Anyone know how to generate an automatic property using CodeDom and
> > VS2008?

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.