473,407 Members | 2,598 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,407 software developers and data experts.

how to get the assembly in the parent class of an ancestor

If i have Class2 that is inherited by Class1, how can Class1's methods
operate on Class2's assembly information?

For instance:
public class Component
{
public virtual List<ComponentInfo> GetAssemblyInfo()
{
try
{
List<ComponentInfo> ci = new List<ComponentInfo>();
// how can Component get the assembly of its immediate descendant?
ci.Add(fillComponentInfo(System.Reflection.Assembl y.);
return ci;
}
catch (Exception ex)
{
throw;
}
}
public class ThisComponent : Component
{
}

GetCallingAssembly doesn't return the Assembly that ThisComponent lives
in. It returns the assembly that the code that invoked the
GetAssemblyInfo. Also GetExecutingAssembly returns the assembly that
Component lives in. Check out the line above that is
fillComponentInfo(...).

The only thing i can think of now is a protected property that the
descendant sets in the constructor. I really don't want to have to add
that kind of thing to every Class that inherits from Component.

dan
May 12 '06 #1
3 2666
You could get your current type .. this.GetType() .. you can then use
Type.Assembly to get the assembly the type resides in.

In general I think this should be bringing up red flags from a design
perspective .. any time a parent is worried about its dependants there
should be cause for alarm.

Cheers,

Greg Young
MVP - C#
"Dan Holmes" <da*******@bigfoot.com> wrote in message
news:Od**************@TK2MSFTNGP04.phx.gbl...
If i have Class2 that is inherited by Class1, how can Class1's methods
operate on Class2's assembly information?

For instance:
public class Component
{
public virtual List<ComponentInfo> GetAssemblyInfo()
{
try
{ List<ComponentInfo> ci = new List<ComponentInfo>();
// how can Component get the assembly of its immediate descendant?
ci.Add(fillComponentInfo(System.Reflection.Assembl y.);
return ci;
}
catch (Exception ex)
{
throw;
}
}
public class ThisComponent : Component
{
}

GetCallingAssembly doesn't return the Assembly that ThisComponent lives
in. It returns the assembly that the code that invoked the
GetAssemblyInfo. Also GetExecutingAssembly returns the assembly that
Component lives in. Check out the line above that is
fillComponentInfo(...).

The only thing i can think of now is a protected property that the
descendant sets in the constructor. I really don't want to have to add
that kind of thing to every Class that inherits from Component.

dan

May 12 '06 #2
I added a protected field to the Component class

protected Type descendant

the constructor does as you suggest.

From a design POV, the goal is to get the assembly information and keep
that process in a central place. I was hoping that by inheriting the
Component class there wouldn't be any knowledge of the Component class
nor any code with it by its descendants. I don't think this is
intrusive since it only uses the Type information to get an assembly
that is already in memory and retrieve attributes. I am open to other
ways and designs though.

This is the information that the Component gets and returns. I didn't
want to require an explicit call to a method and was hoping that
inheriting would do that.

AssemblyInfo ci = new AssemblyInfo();
ci.Path = System.IO.Path.GetFullPath(a.Location);
ci.AssemblyFileName = System.IO.Path.GetFileName(a.Location);
ci.Name = a.FullName;
ci.Version =
((AssemblyFileVersionAttribute)Attribute.GetCustom Attribute(a,
typeof(AssemblyFileVersionAttribute))).Version;
ci.Title =
((AssemblyTitleAttribute)Attribute.GetCustomAttrib ute(a,
typeof(AssemblyTitleAttribute))).Title;
ci.Product =
((AssemblyProductAttribute)Attribute.GetCustomAttr ibute(a,
typeof(AssemblyProductAttribute))).Product;
ci.Copyright =
((AssemblyCopyrightAttribute)Attribute.GetCustomAt tribute(a,
typeof(AssemblyCopyrightAttribute))).Copyright;
ci.CompanyName =
((AssemblyCompanyAttribute)Attribute.GetCustomAttr ibute(a,
typeof(AssemblyCompanyAttribute))).Company;
ci.Description =
((AssemblyDescriptionAttribute)Attribute.GetCustom Attribute(a,
typeof(AssemblyDescriptionAttribute))).Description ;
ci.FileDateTime = System.IO.File.GetLastWriteTime(a.Location);
return ci;
--
dan

Greg Young wrote:
You could get your current type .. this.GetType() .. you can then use
Type.Assembly to get the assembly the type resides in.

In general I think this should be bringing up red flags from a design
perspective .. any time a parent is worried about its dependants there
should be cause for alarm.

Cheers,

Greg Young
MVP - C#
"Dan Holmes" <da*******@bigfoot.com> wrote in message
news:Od**************@TK2MSFTNGP04.phx.gbl...
If i have Class2 that is inherited by Class1, how can Class1's methods
operate on Class2's assembly information?

For instance:
public class Component
{
public virtual List<ComponentInfo> GetAssemblyInfo()
{
try
{ List<ComponentInfo> ci = new List<ComponentInfo>();
// how can Component get the assembly of its immediate descendant?
ci.Add(fillComponentInfo(System.Reflection.Assembl y.);
return ci;
}
catch (Exception ex)
{
throw;
}
}
public class ThisComponent : Component
{
}

GetCallingAssembly doesn't return the Assembly that ThisComponent lives
in. It returns the assembly that the code that invoked the
GetAssemblyInfo. Also GetExecutingAssembly returns the assembly that
Component lives in. Check out the line above that is
fillComponentInfo(...).

The only thing i can think of now is a protected property that the
descendant sets in the constructor. I really don't want to have to add
that kind of thing to every Class that inherits from Component.

dan


May 12 '06 #3
It should be able to use this.GetType() instead of requiring the descendent
to explicitly state its type.

Type t = this.GetType();
Assembly DescendentAssembly = t.Assembly;

"Dan Holmes" <da*******@bigfoot.com> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
I added a protected field to the Component class

protected Type descendant

the constructor does as you suggest.

From a design POV, the goal is to get the assembly information and keep
that process in a central place. I was hoping that by inheriting the
Component class there wouldn't be any knowledge of the Component class nor
any code with it by its descendants. I don't think this is intrusive
since it only uses the Type information to get an assembly that is already
in memory and retrieve attributes. I am open to other ways and designs
though.

This is the information that the Component gets and returns. I didn't
want to require an explicit call to a method and was hoping that
inheriting would do that.

AssemblyInfo ci = new AssemblyInfo();
ci.Path = System.IO.Path.GetFullPath(a.Location);
ci.AssemblyFileName = System.IO.Path.GetFileName(a.Location);
ci.Name = a.FullName;
ci.Version =
((AssemblyFileVersionAttribute)Attribute.GetCustom Attribute(a,
typeof(AssemblyFileVersionAttribute))).Version;
ci.Title =
((AssemblyTitleAttribute)Attribute.GetCustomAttrib ute(a,
typeof(AssemblyTitleAttribute))).Title;
ci.Product =
((AssemblyProductAttribute)Attribute.GetCustomAttr ibute(a,
typeof(AssemblyProductAttribute))).Product;
ci.Copyright =
((AssemblyCopyrightAttribute)Attribute.GetCustomAt tribute(a,
typeof(AssemblyCopyrightAttribute))).Copyright;
ci.CompanyName =
((AssemblyCompanyAttribute)Attribute.GetCustomAttr ibute(a,
typeof(AssemblyCompanyAttribute))).Company;
ci.Description =
((AssemblyDescriptionAttribute)Attribute.GetCustom Attribute(a,
typeof(AssemblyDescriptionAttribute))).Description ;
ci.FileDateTime = System.IO.File.GetLastWriteTime(a.Location);
return ci;
--
dan

Greg Young wrote:
You could get your current type .. this.GetType() .. you can then use
Type.Assembly to get the assembly the type resides in.

In general I think this should be bringing up red flags from a design
perspective .. any time a parent is worried about its dependants there
should be cause for alarm.

Cheers,

Greg Young
MVP - C#
"Dan Holmes" <da*******@bigfoot.com> wrote in message
news:Od**************@TK2MSFTNGP04.phx.gbl...
If i have Class2 that is inherited by Class1, how can Class1's methods
operate on Class2's assembly information?

For instance:
public class Component
{
public virtual List<ComponentInfo> GetAssemblyInfo()
{
try
{ List<ComponentInfo> ci = new List<ComponentInfo>();
// how can Component get the assembly of its immediate descendant?
ci.Add(fillComponentInfo(System.Reflection.Assembl y.);
return ci;
}
catch (Exception ex)
{
throw;
}
}
public class ThisComponent : Component
{
}

GetCallingAssembly doesn't return the Assembly that ThisComponent lives
in. It returns the assembly that the code that invoked the
GetAssemblyInfo. Also GetExecutingAssembly returns the assembly that
Component lives in. Check out the line above that is
fillComponentInfo(...).

The only thing i can think of now is a protected property that the
descendant sets in the constructor. I really don't want to have to add
that kind of thing to every Class that inherits from Component.

dan


May 12 '06 #4

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

Similar topics

0
by: Emil Karlen | last post by:
I am modelling a software system in UML using Umbrello, which stores the UML-model in a XMI-file (which exact type I only guess). Now, my goal is to: have a XSL-transformation (which I call the...
3
by: Eshrath | last post by:
Hi, I have an xsl where a particular child node (<sub1> and <sub2> )can occur in two type of parent nodes (<A> and <B>). like <A> <sub1>11</sub1> <sub2>22</sub2>
1
by: Ronald Landheer-Cieslak | last post by:
Hello all, We're coding a really nice implementation of a generic abstract factory at the moment, but we've come to a slight impass we have to work around: when automagically registering a class...
4
by: darrel | last post by:
Is there a way in XSLT to write this XSL:Value-of select statement (which I've written in plain english): value of the attribute of the first ascendent to have a value. In otherwords, I have...
12
by: Pollux | last post by:
I'm having trouble doing someting apparently simple. I'm still not very familiar with Visual Studio 2003, so apologies if I've missed something obvious. Basically my problem is the following. I...
5
by: Rob | last post by:
In many articles related to VB.net the word "class" is used... How many meanings are there to this word ? "possible to derived a class from another" "forms are full-fledged classes" "base...
3
by: Luis P. Mendes | last post by:
Hi, I have the following problem: I instantiate class Sistema from another class. The result is the same if I import it to interactive shell. s = Sistema("par") class Sistema:
5
by: gnewsgroup | last post by:
In my user control, I would like to find a Label control in the parent page (the page that uses my user control). I need to update that Label.Text when something happens in the user control. I...
1
by: michal.podlewski | last post by:
Hi All, I have a problem with a simple (as I thought till now) thing: I want to make a link in a child-window which would change site in the parent-window and along with closing child window. The...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
0
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...

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.