HighTechTalks DotNet Forums  

C# 3.0 Automatic Properties and CodeDom

Dotnet Framework (CLR) microsoft.public.dotnet.framework.clr


Discuss C# 3.0 Automatic Properties and CodeDom in the Dotnet Framework (CLR) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Ed
 
Posts: n/a

Default C# 3.0 Automatic Properties and CodeDom - 11-20-2007 , 04:14 PM






Anyone know how to generate an automatic property using CodeDom and VS2008?



Reply With Quote
  #2  
Old   
Alexander Vasilevsky
 
Posts: n/a

Default Re: C# 3.0 Automatic Properties and CodeDom - 11-22-2007 , 06:06 AM






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
Quote:
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


"Ed" <Ed (AT) discussions (DOT) microsoft.com> / :
news:4DF7CB2B-92A2-41B4-A9F9-9FA20FEB3EC0 (AT) microsoft (DOT) com...
Quote:
Anyone know how to generate an automatic property using CodeDom and
VS2008?





Reply With Quote
  #3  
Old   
Ed
 
Posts: n/a

Default Re: C# 3.0 Automatic Properties and CodeDom - 11-26-2007 , 08:08 AM



That'll generate the IL but not CodeDom code.



"Alexander Vasilevsky" wrote:

Quote:
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


"Ed" <Ed (AT) discussions (DOT) microsoft.com> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
news:4DF7CB2B-92A2-41B4-A9F9-9FA20FEB3EC0 (AT) microsoft (DOT) com...
Anyone know how to generate an automatic property using CodeDom and
VS2008?






Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.