473,473 Members | 1,415 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Code Dom

I have an instance of a System.CodeDom.CodeNamespace. I am currently
spinning through the types, and the members of each type. I am trying to
find the Codememberfields that require creation before access. I then want
to add to the constructor the creation of each of these Items.

I have been able to figure out how to add the constructor to a type if it
doesn't have one. However, I am stuck with how to figure out if the current
member requires creation, and how to modify the code dom to add said
creation to the constructor.

Any help would be appreciated.

Thanks
Wayne
Nov 16 '05 #1
8 2470
Hi Wayne,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to know how to check if a type
already have a constructor. If there is any misunderstanding, please feel
free to let me know.

Based on my research, I didn't find any method or properties to know if a
type has already had a constructor. I think we can iterate throught the
CodeTypeDeclaration.Member collection to check each member. If one member
is a CodeConstructor object it means that the object has a constructor.
Here is an example:

private bool HasConstructor(CodeTypeDeclaration t)
{
foreach(CodeTypeMember m in t.Members)
{
if(m is CodeConstructor)
return true;
}
}

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #2
No I have figured out how to get the constructor, I did basically what you
have below. what I need is the following:

1) how to tell if a private member is required to be created, meaning it's
not a string, int, datetime, etc...
2) once I determine that it does need to be created how to insert the code
into the dom, so that the member is created and initialized in the
constructor

Thanks
Wayne
"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:iy**************@cpmsftngxa10.phx.gbl...
Hi Wayne,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to know how to check if a type already have a constructor. If there is any misunderstanding, please feel
free to let me know.

Based on my research, I didn't find any method or properties to know if a
type has already had a constructor. I think we can iterate throught the
CodeTypeDeclaration.Member collection to check each member. If one member
is a CodeConstructor object it means that the object has a constructor.
Here is an example:

private bool HasConstructor(CodeTypeDeclaration t)
{
foreach(CodeTypeMember m in t.Members)
{
if(m is CodeConstructor)
return true;
}
}

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #3
Hi Wayne,

We can go throught each member to check CodeMemberField.Type property to
see if this field needs initialization. And use
CodeMemberField.InitExpression to create the initialization expression. For
more information, please check the following link.

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemcodedomcodememberfieldclassinitexpressi ontopic.asp

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #4
Part of that is where I'm lost, I've not quite got the syntax correct yet to
check the type. Can you help with that? also if I understand correctly then
I will have to do

if type is not INt and type is not string and type is not etc....

Correct?

Thanks
Wayne
"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:Fy**************@cpmsftngxa10.phx.gbl...
Hi Wayne,

We can go throught each member to check CodeMemberField.Type property to
see if this field needs initialization. And use
CodeMemberField.InitExpression to create the initialization expression. For more information, please check the following link.

http://msdn.microsoft.com/library/de...us/cpref/html/ frlrfsystemcodedomcodememberfieldclassinitexpressi ontopic.asp

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #5
Hi Wayne,

CodeMemberField.Type will return a CodeTypeReference object. We will get
the type name with CodeTypeReference.BaseType property. I think we have to
check for each type to see if it needs initialization.

You can also use Type.GetType method to create a type object and use
IsClass or IsPrimitive property to see if this type needs initialization.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #6
That worked great, thaks for the help.

"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:up**************@cpmsftngxa10.phx.gbl...
Hi Wayne,

CodeMemberField.Type will return a CodeTypeReference object. We will get
the type name with CodeTypeReference.BaseType property. I think we have to
check for each type to see if it needs initialization.

You can also use Type.GetType method to create a type object and use
IsClass or IsPrimitive property to see if this type needs initialization.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #7
This worked great but I've run into a small issue.

I have an object where the properties Set method does something to the new
value. So I directly init the code member field. How would one go about
creating an instance in the constructor and set the new instance to the
Property?

Thanks
Wayne

--
Thanks
Wayne Sepega
Jacksonville, Fl

"When a man sits with a pretty girl for an hour, it seems like a minute. But
let him sit on a hot stove for a minute and it's longer than any hour.
That's relativity." - Albert Einstein
"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:up**************@cpmsftngxa10.phx.gbl...
Hi Wayne,

CodeMemberField.Type will return a CodeTypeReference object. We will get
the type name with CodeTypeReference.BaseType property. I think we have to
check for each type to see if it needs initialization.

You can also use Type.GetType method to create a type object and use
IsClass or IsPrimitive property to see if this type needs initialization.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #8
Never mind, I actually did a bit more looking in the help (very large help
file that the MSDN is) and found what I needed.

--
Thanks
Wayne Sepega
Jacksonville, Fl

"When a man sits with a pretty girl for an hour, it seems like a minute. But
let him sit on a hot stove for a minute and it's longer than any hour.
That's relativity." - Albert Einstein
"Wayne" <Me******@community.nospam> wrote in message
news:#2**************@TK2MSFTNGP12.phx.gbl...
This worked great but I've run into a small issue.

I have an object where the properties Set method does something to the new
value. So I directly init the code member field. How would one go about
creating an instance in the constructor and set the new instance to the
Property?

Thanks
Wayne

--
Thanks
Wayne Sepega
Jacksonville, Fl

"When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour.
That's relativity." - Albert Einstein
"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:up**************@cpmsftngxa10.phx.gbl...
Hi Wayne,

CodeMemberField.Type will return a CodeTypeReference object. We will get
the type name with CodeTypeReference.BaseType property. I think we have to check for each type to see if it needs initialization.

You can also use Type.GetType method to create a type object and use
IsClass or IsPrimitive property to see if this type needs initialization.
Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."


Nov 16 '05 #9

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

Similar topics

51
by: Mudge | last post by:
Please, someone, tell me why OO in PHP is better than procedural.
9
by: bigoxygen | last post by:
Hi. I'm using a 3 tier FrontController Design for my web application right now. The problem is that I'm finding to have to duplicate a lot of code for similar functions; for example, listing...
4
by: jason | last post by:
Hello. Newbie on SQL and suffering through this. I have two tables created as such: drop table table1; go drop table table2; go
16
by: Dario de Judicibus | last post by:
I'm getting crazy. Look at this code: #include <string.h> #include <stdio.h> #include <iostream.h> using namespace std ; char ini_code = {0xFF, 0xFE} ; char line_sep = {0x20, 0x28} ;
109
by: Andrew Thompson | last post by:
It seems most people get there JS off web sites, which is entirely logical. But it is also a great pity since most of that code is of such poor quality. I was looking through the JS FAQ for any...
5
by: ED | last post by:
I currently have vba code that ranks employees based on their average job time ordered by their region, zone, and job code. I currently have vba code that will cycle through a query and ranks each...
0
by: Namratha Shah \(Nasha\) | last post by:
Hey Guys, Today we are going to look at Code Access Security. Code access security is a feature of .NET that manages code depending on its trust level. If the CLS trusts the code enough to...
18
by: Joe Fallon | last post by:
I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My...
37
by: Alan Silver | last post by:
Hello, Newbie here, so please forgive what is probably a basic question ... I see a lot of discussion about "code behind", which if I have understood correctly, means that the script code goes...
171
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles)...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
0
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,...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.