471,089 Members | 1,116 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,089 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 1555
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

26 posts views Thread by nospam | last post: by
2 posts views Thread by Theodore | last post: by
3 posts views Thread by DDE | last post: by
10 posts views Thread by jojobar | last post: by
2 posts views Thread by john | last post: by

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.