473,383 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

How to get hte Assembly when...

Hi,

I have a form (A) which has a collection as a property. All my forms
inhert from this base form.

I'm tring to put some code in form A where I can get the fieldInfo from
the form that imnherits from A. This is the code:

Type t = this.GetType();
FieldInfo parameterInfo = t.GetField(field,BindingFlags.Instance |
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static |
BindingFlags.FlattenHierarchy);
if(parameterInfo == null)
{
if(Assembly.GetEntryAssembly() != null )
{
MessageBox.Show("Field nod found");
fieldFound = false;
}
}

The problem with this is that it gets the Assembly from Form A (base form)
because its where the collection was called so then the field is never
found. Form A (bas form) is in another assembly/solution. All this has to be
done is design time and not runtime. How can I get the fileds or assembly of
the current form and not the inhertided form.

I hope I made my self clear..

Regards
Lucas

Nov 15 '05 #1
5 1612
I've recreated the situation you've described and haven't
encountered any errors. Perhaps I misunderstood your
problem, so let me explain what I did:

Assembly One
Defines OriginClass with one method, "public string Test
()". "Test" simply uses the code from your example and
returns either the parameterInfo.Name or "Field Not Found"

Assembly Two
Defines DerivedClass which inherits from OriginClass

Assembly Three
Defines a third assembly that defines a DerivedClass
object and calls its "Test" method (which is actually the
method from OriginClass).

Does this accurately model your situation?

Jerry Negrelli
Senior Software Engineer
Data Scientific Corporation
-----Original Message-----
Hi,

I have a form (A) which has a collection as a property. All my formsinhert from this base form.

I'm tring to put some code in form A where I can get the fieldInfo fromthe form that imnherits from A. This is the code:

Type t = this.GetType();
FieldInfo parameterInfo = t.GetField (field,BindingFlags.Instance |BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static |BindingFlags.FlattenHierarchy);
if(parameterInfo == null)
{
if(Assembly.GetEntryAssembly() != null )
{
MessageBox.Show("Field nod found");
fieldFound = false;
}
}

The problem with this is that it gets the Assembly from Form A (base form)because its where the collection was called so then the field is neverfound. Form A (bas form) is in another assembly/solution. All this has to bedone is design time and not runtime. How can I get the fileds or assembly ofthe current form and not the inhertided form.

I hope I made my self clear..

Regards
Lucas

.

Nov 15 '05 #2
Jerry,

Yes it does but I'm calling a collection in design time this is where
the problem occurs. It is at design time I want to get the field info from
the derived class. When I execute the code from the parameterInfo.... that
is in the OriginClass... it is looking for the fields in Assembly One and
not Assembly Three... al this at design time.

Regards
Lucas

"Jerry Negrelli" <je************@nospam.datascientific.com> wrote in message
news:07****************************@phx.gbl...
I've recreated the situation you've described and haven't
encountered any errors. Perhaps I misunderstood your
problem, so let me explain what I did:

Assembly One
Defines OriginClass with one method, "public string Test
()". "Test" simply uses the code from your example and
returns either the parameterInfo.Name or "Field Not Found"

Assembly Two
Defines DerivedClass which inherits from OriginClass

Assembly Three
Defines a third assembly that defines a DerivedClass
object and calls its "Test" method (which is actually the
method from OriginClass).

Does this accurately model your situation?

Jerry Negrelli
Senior Software Engineer
Data Scientific Corporation
-----Original Message-----
Hi,

I have a form (A) which has a collection as a

property. All my forms
inhert from this base form.

I'm tring to put some code in form A where I can get

the fieldInfo from
the form that imnherits from A. This is the code:

Type t = this.GetType();
FieldInfo parameterInfo = t.GetField

(field,BindingFlags.Instance |
BindingFlags.NonPublic | BindingFlags.Public |

BindingFlags.Static |
BindingFlags.FlattenHierarchy);
if(parameterInfo == null)
{
if(Assembly.GetEntryAssembly() != null )
{
MessageBox.Show("Field nod found");
fieldFound = false;
}
}

The problem with this is that it gets the Assembly from

Form A (base form)
because its where the collection was called so then the

field is never
found. Form A (bas form) is in another

assembly/solution. All this has to be
done is design time and not runtime. How can I get the

fileds or assembly of
the current form and not the inhertided form.

I hope I made my self clear..

Regards
Lucas

.

Nov 15 '05 #3
Maybe I'm not uderstanding you correctly, but I think you're looking in the
wrong place for the property. Does this code work for you:

// Assembly1.cs
public class BaseClass
{
int SomeField;
void Test() {
Type t = this.GetType(); // I think this is wrong
t = typeof(BaseClass); // Try this instead
FieldInfo parameterInfo = t.GetField(field,BindingFlags.Instance |
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static |
BindingFlags.FlattenHierarchy);
if(parameterInfo == null)
{
if(Assembly.GetEntryAssembly() != null )
{
MessageBox.Show("Field not found");
fieldFound = false;
}
}
}
}

// Assembly2.cs
public class DerivedClass : BaseClass
{
}

--
--Grant
This posting is provided "AS IS" with no warranties, and confers no rights.
"Lucas Sain" <ls***@lidersoft.com> wrote in message
news:uL**************@TK2MSFTNGP12.phx.gbl...
Hi,

I have a form (A) which has a collection as a property. All my forms
inhert from this base form.

I'm tring to put some code in form A where I can get the fieldInfo from the form that imnherits from A. This is the code:

Type t = this.GetType();
FieldInfo parameterInfo = t.GetField(field,BindingFlags.Instance |
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static |
BindingFlags.FlattenHierarchy);
if(parameterInfo == null)
{
if(Assembly.GetEntryAssembly() != null )
{
MessageBox.Show("Field nod found");
fieldFound = false;
}
}

The problem with this is that it gets the Assembly from Form A (base form)
because its where the collection was called so then the field is never
found. Form A (bas form) is in another assembly/solution. All this has to be done is design time and not runtime. How can I get the fileds or assembly of the current form and not the inhertided form.

I hope I made my self clear..

Regards
Lucas

Nov 15 '05 #4
Grant,
Thanks for your Reply.
BaseClass has a method (BaseMehtod) that searches X control on a form
(The code I wrote before).
The problem is that in the DerivedClass I have added some Controls which
I want the BaseMethod to be able to reflect at design time because all this
validation should occure at design time, so if I use your sugestion I only
get the type of the BaseClass so no fields are found. All the fields are in
the DerivedClass.

Am I doins something wrong or am I missing something....

Regards
Lucas Sain


"Grant Richins [MS]" <gr*****@online.microsoft.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Maybe I'm not uderstanding you correctly, but I think you're looking in the wrong place for the property. Does this code work for you:

// Assembly1.cs
public class BaseClass
{
int SomeField;
void Test() {
Type t = this.GetType(); // I think this is wrong
t = typeof(BaseClass); // Try this instead
FieldInfo parameterInfo = t.GetField(field,BindingFlags.Instance |
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);
if(parameterInfo == null)
{
if(Assembly.GetEntryAssembly() != null )
{
MessageBox.Show("Field not found");
fieldFound = false;
}
}
}
}

// Assembly2.cs
public class DerivedClass : BaseClass
{
}

--
--Grant
This posting is provided "AS IS" with no warranties, and confers no rights.

"Lucas Sain" <ls***@lidersoft.com> wrote in message
news:uL**************@TK2MSFTNGP12.phx.gbl...
Hi,

I have a form (A) which has a collection as a property. All my forms
inhert from this base form.

I'm tring to put some code in form A where I can get the fieldInfo from
the form that imnherits from A. This is the code:

Type t = this.GetType();
FieldInfo parameterInfo = t.GetField(field,BindingFlags.Instance |
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static |
BindingFlags.FlattenHierarchy);
if(parameterInfo == null)
{
if(Assembly.GetEntryAssembly() != null )
{
MessageBox.Show("Field nod found");
fieldFound = false;
}
}

The problem with this is that it gets the Assembly from Form A (base form) because its where the collection was called so then the field is never
found. Form A (bas form) is in another assembly/solution. All this has

to be
done is design time and not runtime. How can I get the fileds or
assembly of
the current form and not the inhertided form.

I hope I made my self clear..

Regards
Lucas


Nov 15 '05 #5
Ahhhh! Well, design time is an entirely different beast and well out of my
league.

So you have something like this:
//assembly 1
class BaseClass {
void EnumDerivedFields() {
// code here to find "SomeField"?
}
}

//assembly 2
class DerviedClass : BaseClass {
int SomeField;
}
So basically you have a base class that somehow needs to change according to
which specific derived class instance it is? It sounds like what you should
really be doing is having more virtual methods or properties in the derived
classes...
--
--Grant
This posting is provided "AS IS" with no warranties, and confers no rights.
"Lucas Sain" <ls***@lidersoft.com> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
Grant,
Thanks for your Reply.
BaseClass has a method (BaseMehtod) that searches X control on a form
(The code I wrote before).
The problem is that in the DerivedClass I have added some Controls which I want the BaseMethod to be able to reflect at design time because all this validation should occure at design time, so if I use your sugestion I only
get the type of the BaseClass so no fields are found. All the fields are in the DerivedClass.

Am I doins something wrong or am I missing something....

Regards
Lucas Sain


"Grant Richins [MS]" <gr*****@online.microsoft.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Maybe I'm not uderstanding you correctly, but I think you're looking in the
wrong place for the property. Does this code work for you:

// Assembly1.cs
public class BaseClass
{
int SomeField;
void Test() {
Type t = this.GetType(); // I think this is wrong
t = typeof(BaseClass); // Try this instead
FieldInfo parameterInfo = t.GetField(field,BindingFlags.Instance |
BindingFlags.NonPublic | BindingFlags.Public |

BindingFlags.Static |
BindingFlags.FlattenHierarchy);
if(parameterInfo == null)
{
if(Assembly.GetEntryAssembly() != null )
{
MessageBox.Show("Field not found");
fieldFound = false;
}
}
}
}

// Assembly2.cs
public class DerivedClass : BaseClass
{
}

--
--Grant
This posting is provided "AS IS" with no warranties, and confers no

rights.


"Lucas Sain" <ls***@lidersoft.com> wrote in message
news:uL**************@TK2MSFTNGP12.phx.gbl...
Hi,

I have a form (A) which has a collection as a property. All my forms inhert from this base form.

I'm tring to put some code in form A where I can get the fieldInfo

from
the form that imnherits from A. This is the code:

Type t = this.GetType();
FieldInfo parameterInfo = t.GetField(field,BindingFlags.Instance |
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static |
BindingFlags.FlattenHierarchy);
if(parameterInfo == null)
{
if(Assembly.GetEntryAssembly() != null )
{
MessageBox.Show("Field nod found");
fieldFound = false;
}
}

The problem with this is that it gets the Assembly from Form A (base

form) because its where the collection was called so then the field is never found. Form A (bas form) is in another assembly/solution. All this has

to
be
done is design time and not runtime. How can I get the fileds or

assembly
of
the current form and not the inhertided form.

I hope I made my self clear..

Regards
Lucas



Nov 15 '05 #6

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

Similar topics

1
by: Daylor | last post by:
can shadowcopy be done with private assembly ? any info about how shadowcopy actually works ? when im compiling an assembly (while the assembly file is in use ), what i need to do ? change...
26
by: nospam | last post by:
Just wondering, What do you think the difference in performance would be between (1.) Compiled C# (2.) Compiled C++ (3.) and Assembly Language And how would the mix be if some if any of...
2
by: Carlos G Benevides | last post by:
I have a ASP.Net web application that has two assemblies that run under com+. Under Windows 2000 the two assemblies are added to com+ automatically when instantiated from the web site. For this...
2
by: Theodore | last post by:
Hi, from within an executable I am calling class A located in a dll file which in turn calls class B located in another dll file. I want class B to be able to resolve the last entry assembly. By...
3
by: DDE | last post by:
Hi everybody, I developed an assembly common to all my Web Services, so I registered it and put it in the Global Assembly Cache. Now, I modified this assembly, but cannot succed to have this new...
10
by: jojobar | last post by:
Hello, I am trying to use vs.net 2005 to migrate a project originally in vs.net 2003. I started with creation of a "web site", and then created folders for each component of the site. I read...
2
by: john | last post by:
Maybe I haven't had that "a-ha" moment yet, but I think the new approach to web projects is a step in the wrong direction. My main beef is that control over the assembly generation process has...
3
by: Richard Lewis Haggard | last post by:
We are having a lot of trouble with problems relating to failures relating to 'The located assembly's manifest definition with name 'xxx' does not match the assembly reference" but none of us here...
1
by: Tim F | last post by:
Problem: I'm receiving the error "File or assembly name XXXXX or one of its dependencies, was not found." when trying to execute code in an assmebly that has both a strong-name and has been...
14
by: Monty | last post by:
Hello, I have created a solution which has both a web UI and a winform UI, the latter is just for administrators. The Web UI (a Web Application Project) and the winform project both...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.