473,569 Members | 2,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Quick CodeDOM Question

Hi,

I am working on CodeDOM to generate a more usable class to serialize
and deserialize WXS files. I have hit the wall at a pretty early
stage. :-( I am attempting to change the member public fields into
properties. I have written a generic field to property code for that.
It is almost straight out of the link that you gave me. :-)

But that always creates code with the virtual keyword. I am not sure
on how to get rid of it. For example this is the sample Icon class
created.

public class Icon {
private string _id;
private string _src;
/// <remarks/>
[System.Xml.Seri alization.XmlAt tributeAttribut e()]
public virtual string Id {
get {
return this._id;
}
set {
this._id = value;
}
}
/// <remarks/>
[System.Xml.Seri alization.XmlAt tributeAttribut e()]
public virtual string src {
get {
return this._src;
}
set {
this._src = value;
}
}
}

public virtual string Id ...
public virtual string src ...

As you can see the properties above have the ugly 'virtual' keyword. I
am not sure how to get rid of it.
--
Vagmi
http://geekswithblogs.net/vagmi.mudumbai
http://installneo.blogspot.com
Nov 16 '05 #1
4 1996
Can you show us a cut down, compilable, version of the code that generates a virtual property

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Hi,

I am working on CodeDOM to generate a more usable class to serialize
and deserialize WXS files. I have hit the wall at a pretty early
stage. :-( I am attempting to change the member public fields into
properties. I have written a generic field to property code for that.
It is almost straight out of the link that you gave me. :-)

But that always creates code with the virtual keyword. I am not sure
on how to get rid of it. For example this is the sample Icon class
created.

Nov 16 '05 #2
This is my code

<style type="text/css">.cf { font-family: Courier New; font-size: 10pt;
color: #000000; background: #ffffff; border-top: windowtext 1pt solid;
padding-top: 0pt; border-left: windowtext 1pt solid; padding-left: 0pt;
border-right: windowtext 1pt solid; padding-right: 0pt; border-bottom:
windowtext 1pt solid; padding-bottom: 0pt; }.cl { margin: 0px; }.cb1 { color:
#0000ff; }.cb2 { color: #008000; }</style><div class="cf"><p class="cl"><spa n
class="cb1">for each</span>(CodeTypeD eclaration type <span
class="cb1">in</span> ns.Types)</p><p class="cl"> {</p><p
class="cl"> <span class="cb1">if</span>(type.IsCl ass ||
type.IsStruct)</p><p class="cl"> {</p><p class="cl">
CodeTypeMember[] members=<span class="cb1">new </span>
CodeTypeMember[type.Members.Co unt];</p><p class="cl">
type.Members.Co pyTo(members,0) ;</p><p class="cl"> <span
class="cb1">for each</span>(CodeTypeM ember member <span class="cb1">in</span>
members)</p><p class="cl"> {</p><p class="cl">
<span class="cb1">if</span>(member <span class="cb1">is</span>
CodeMemberField )</p><p class="cl"> {</p><p
class="cl"> CodeMemberPrope rty prop=<span
class="cb1">new </span> CodeMemberPrope rty();</p><p class="cl">
prop.Name=membe r.Name;</p><p class="cl">
prop.Attributes =MemberAttribut es.Public;</p><p class="cl">
prop.Type=((Cod eMemberField)me mber).Type;</p><p class="cl">
prop.HasGet=<sp an class="cb1">tru e</span>;</p><p
class="cl"> prop.HasSet=<sp an
class="cb1">tru e</span>;</p><p class="cl">
prop.CustomAttr ibutes.AddRange (member.CustomA ttributes);</p><p class="cl">
member.CustomAt tributes.Clear( );</p><p class="cl">
prop.Comments.A ddRange(member. Comments);</p><p
class="cl"> member.Comments .Clear();</p><p
class="cl">
member.Attribut es=MemberAttrib utes.Private;</p><p class="cl">
<span class="cb1">cha r</span>[]
letters=member. Name.ToCharArra y();</p><p class="cl">
letters[0]=Char.ToLower(l etters[0]);</p><p class="cl">
member.Name=Str ing.Concat("_", <span class="cb1">new </span> <span
class="cb1">str ing</span>(letters)) ;</p><p class="cl"> </p><p class="cl">
<span class="cb2">//add get and set</span></p><p
class="cl"> CodeFieldRefere nceExpression
refReturnStatem ent=<span class="cb1">new </span>
CodeFieldRefere nceExpression(< span class="cb1">new </span>
CodeThisReferen ceExpression(), member.Name);</p><p class="cl">
CodeMethodRetur nStatement retStatement=<s pan
class="cb1">new </span> CodeMethodRetur nStatement(refR eturnStatement) ;</p><p
class="cl">
prop.GetStateme nts.Add(retStat ement);</p><p class="cl"> </p><p class="cl">
<span class="cb2">//_member=value</span></p><p
class="cl"> CodeArgumentRef erenceExpressio n
refValuePart=<s pan class="cb1">new </span>
CodeArgumentRef erenceExpressio n("value");</p><p class="cl">
CodeAssignState ment asStatement=<sp an class="cb1">new </span>
CodeAssignState ment(refReturnS tatement,refVal uePart);</p><p class="cl">
prop.SetStateme nts.Add(asState ment);</p><p
class="cl"> type.Members.Ad d(prop);</p><p
class="cl"> }</p><p class="cl">
}</p><p class="cl"> }</p></div>
Nov 16 '05 #3
Sorry about the earlier message. It was rouge HTML. This is a much readable
version of the code. Thanks for all your help.

foreach(CodeTyp eDeclaration type in ns.Types)
{
if(type.IsClass || type.IsStruct)
{
CodeTypeMember[] members=new CodeTypeMember[type.Members.Co unt];
type.Members.Co pyTo(members,0) ;
foreach(CodeTyp eMember member in members)
{
if(member is CodeMemberField )
{
CodeMemberPrope rty prop=new CodeMemberPrope rty();
prop.Name=membe r.Name;
prop.Attributes =MemberAttribut es.Public;
prop.Type=((Cod eMemberField)me mber).Type;
prop.HasGet=tru e;
prop.HasSet=tru e;
prop.CustomAttr ibutes.AddRange (member.CustomA ttributes);
member.CustomAt tributes.Clear( );
prop.Comments.A ddRange(member. Comments);
member.Comments .Clear();
member.Attribut es=MemberAttrib utes.Private;
char[] letters=member. Name.ToCharArra y();
letters[0]=Char.ToLower(l etters[0]);
member.Name=Str ing.Concat("_", new string(letters) );
//add get and set
CodeFieldRefere nceExpression refReturnStatem ent=new
CodeFieldRefere nceExpression(n ew CodeThisReferen ceExpression(), member.Name);
CodeMethodRetur nStatement retStatement=ne w
CodeMethodRetur nStatement(refR eturnStatement) ;
prop.GetStateme nts.Add(retStat ement);
//_member=value
CodeArgumentRef erenceExpressio n refValuePart=ne w
CodeArgumentRef erenceExpressio n("value");
CodeAssignState ment asStatement=new
CodeAssignState ment(refReturnS tatement,refVal uePart);
prop.SetStateme nts.Add(asState ment);
type.Members.Ad d(prop);
}
}
}

"Richard Blewett [DevelopMentor]" wrote:
Can you show us a cut down, compilable, version of the code that generates a virtual property

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Hi,

I am working on CodeDOM to generate a more usable class to serialize
and deserialize WXS files. I have hit the wall at a pretty early
stage. :-( I am attempting to change the member public fields into
properties. I have written a generic field to property code for that.
It is almost straight out of the link that you gave me. :-)

But that always creates code with the virtual keyword. I am not sure
on how to get rid of it. For example this is the sample Icon class
created.

Nov 16 '05 #4
TO save me having to extract the bits from this code snippet that produce the result you see and then create the type form the codeDOM, and so I then don't have to wrap it in a method body and a class just so I can try it out and experiment.

Any chance you could post something short, that *compiles* that shows your issue. I'm sure it will be quicker for you to strip down to the bare essentials your code rather than me try to build it up from what you have provided.

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Sorry about the earlier message. It was rouge HTML. This is a much readable
version of the code. Thanks for all your help.

foreach(CodeTyp eDeclaration type in ns.Types)
{
if(type.IsClass || type.IsStruct)
{
CodeTypeMember[] members=new CodeTypeMember[type.Members.Co unt];
type.Members.Co pyTo(members,0) ;
foreach(CodeTyp eMember member in members)
{
if(member is CodeMemberField )
{
CodeMemberPrope rty prop=new CodeMemberPrope rty();
prop.Name=membe r.Name;
prop.Attributes =MemberAttribut es.Public;
prop.Type=((Cod eMemberField)me mber).Type;
prop.HasGet=tru e;
prop.HasSet=tru e;
prop.CustomAttr ibutes.AddRange (member.CustomA ttributes);
member.CustomAt tributes.Clear( );
prop.Comments.A ddRange(member. Comments);
member.Comments .Clear();
member.Attribut es=MemberAttrib utes.Private;
char[] letters=member. Name.ToCharArra y();
letters[0]=Char.ToLower(l etters[0]);
member.Name=Str ing.Concat("_", new string(letters) );
//add get and set
CodeFieldRefere nceExpression refReturnStatem ent=new
CodeFieldRefere nceExpression(n ew CodeThisReferen ceExpression(), member.Name);
CodeMethodRetur nStatement retStatement=ne w
CodeMethodRetur nStatement(refR eturnStatement) ;
prop.GetStateme nts.Add(retStat ement);
//_member=value
CodeArgumentRef erenceExpressio n refValuePart=ne w
CodeArgumentRef erenceExpressio n("value");
CodeAssignState ment asStatement=new
CodeAssignState ment(refReturnS tatement,refVal uePart);
prop.SetStateme nts.Add(asState ment);
type.Members.Ad d(prop);
}
}
}

"Richard Blewett [DevelopMentor]" wrote:
Can you show us a cut down, compilable, version of the code that generates a virtual property


Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1901
by: Ron Bullman | last post by:
Hi, I havent been able to find any documentation about @ in the CodeDom context. The problem is when generating C# code from CodeDom it will associate a @-tag with all C# specific types. Why? And how to configure the CodeDom to generate code without @-tags? Ron A short example follows whic produces following kind of output:
2
2353
by: Guillaume | last post by:
I don't think I'm the only one with this challenge so… I made code with the CodeDom classes and made code to create a new solution and a new project Now I want to get the codedom code in the new created IDE instance How can do that? Is there a way to paste the string (CodeDom output) into a class? Out is the a way to insert the created...
0
1067
by: Shawn A. Hall | last post by:
First, I apologize if this isn't the right group to post this question, but I didn't see a newsgroup specific to CodeDom so here I am. On to my question: I am trying to use CodeDom to generate Method, Property, and Member code, but ONLY that code. It appears as though the only way to generate code is through the CodeGenerator/CodeProvider,...
1
2284
by: John Livermore | last post by:
Hello, We have an application that uses CodeDom for dynamic in-memory compilation of code. The same code (library) is used by both an ASP.net web site and a Windows Service. The code runs fine in the web environment, but I get file IO errors related to temporary files when it is run in by the Service. I realize that CodeDom has to...
1
1429
by: Russell Mangel | last post by:
Sorry about the crosspost, I posted in the wrong group... I am using C# CLR 2.0 CodeDom: I need to create the following array: SqlParametersqlParameters={ new SqlParameter("@invID", SqlDbType.Int, 4, "invID"), new SqlParameter("@imaID", SqlDbType.Int, 4, "imaID"), new SqlParameter("@qtret", SqlDbType.Float, 8, "qtret")};
9
3973
by: lee.chappers | last post by:
How can I make the CodeDom generate the following C# method? protected sealed override void Test() { } I've tried using: domMethod.Attributes = MemberAttributes.Override | MemberAttributes.Family | MemberAttributes.Final;
6
5750
by: moondaddy | last post by:
will CodeDom create XAML windows or just regular windows forms? If so, how to I tell it to create a xaml window instead of a windows form? thanks -- moondaddy@noemail.noemail
2
2272
by: CodeMonkey775 | last post by:
I'm having problems passing a variable to a method which is executed and compiled using CodeDom. The situation is I have a List<CellData> with cells, each containing a formula (like Excel). I am trying to pass this list to an executable section of code which is compiled during run-time. The formulas are calculated in CodeDom and the result is...
0
1179
by: thisismykindabyte | last post by:
Hello, I was wondering if anyone might know the easiest way to access static methods through a namespace(MyNamespace) from CodeDom generated code? Basically I have this in my MyNamespace.Form: //////// Most of this below is almost useless jargon just to give an idea of what values are set or not public...
0
7618
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6287
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5223
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3657
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2117
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.