473,804 Members | 2,989 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do we access nested classes after loading the assembly ?

3 New Member
How do we access the nested class dynamically in .NET ? Basically I am using third party code (psn.disc assembly) to run few tasks and the requirement is to dynamically load the assembly at run-time.
Here is the code snippet:
Expand|Select|Wrap|Line Numbers
  1. namespace psn.disc
  2. {
  3.      public class discexec
  4.      {
  5.     public int name;
  6.     public discsettings settings;
  7.  
  8.     public int Name
  9.     {
  10.                    get { return this.name; }         
  11.       set { this.name = value; }
  12.            }
  13.  
  14.     public discsettings Settings
  15.     {
  16.                    get { return this.settings; }         
  17.       set { this.settings = value; }
  18.            }    
  19.  
  20.      }
  21.  
  22.  
  23.      public class discsettings
  24.      {
  25.            public int mode;
  26.            public disccolor color;
  27.  
  28.            public disccolor Color
  29.            {
  30.                        get { return this.color; }         
  31.            }
  32.  
  33.     public int Mode
  34.     {
  35.                   get { return this.mode; }         
  36.       set { this.mode = value; }
  37.            }
  38.  
  39.      }
  40.  
  41.  
  42.      public class disccolor
  43.      {
  44.     List<string> colorval;
  45.         public List<string> Add(string)
  46.         {
  47.             this.colorval.Add(string)
  48.         }
  49.      }
  50.  
  51. }
  52.  
  53. namespace digit.exec
  54. {
  55.    public class execclass
  56.    {
  57.  
  58.     public void Execute()
  59.         {
  60.                 AssemblyName asmbname = new Assemblyname();
  61.         asmbname.Name = "psn.disc";
  62.         asmbname.Culture = "";
  63.         asmbname.Version = new Version(1,0,0,0);
  64.         Assembly.Load(asmbname);
  65.  
  66.         Type classtype1 = asmbname.GetType("psn.disc.discsettings");
  67.         Type classtype2 = asmbname.GetType("psn.disc.discexec");
  68.  
  69.         object obj1 = Activator.CreateInstance(classtype1);
  70.         object obj2 = Activator.CreateInstance(classtype2);
  71.  
  72.         PropertyInfo name = classType2.GetProperty("Name");
  73.         PropertyInfo exec = classType2.GetProperty("Settings");
  74.  
  75.         PropertyInfo mode = classType1.GetProperty("mode");
  76.  
  77.         mode.SetValue(obj1, 1, null);
  78.  
  79.         PropertyInfo settings = classType1.GetProperty("Color");
  80.  
  81.         }
  82.      }
  83.  
  84. }
//How do I access the Add method within the disccolor
// class using settings property retrieved above so that I can update the list in the disccolor class ?
Oct 22 '08 #1
4 1302
Frinavale
9,735 Recognized Expert Moderator Expert
Include the psn.disc namespace in your new application.
This namespace has the disccolor class in it. Once you've included the namespace you will be able to access the disccolor and use it as you see fit. This will work because your disccolor is marked as Public. If it had been a Private class you would not be able to access it.

-Frinny
Oct 22 '08 #2
rajshresta
3 New Member
Include the psn.disc namespace in your new application.
This namespace has the disccolor class in it. Once you've included the namespace you will be able to access the disccolor and use it as you see fit. This will work because your disccolor is marked as Public. If it had been a Private class you would not be able to access it.

-Frinny

The problem is psn.disc assembly may or may not be present on the system. Hence I am loading the assembly at run-time and can not include the namespace in my application.
Thanks for your response.

-RS-
Oct 22 '08 #3
Frinavale
9,735 Recognized Expert Moderator Expert
The problem is psn.disc assembly may or may not be present on the system. Hence I am loading the assembly at run-time and can not include the namespace in my application.
Thanks for your response.

-RS-
Why can't you include it in your application?
Oct 22 '08 #4
rajshresta
3 New Member
I cannot include it in the application due to the following reasons:
If I add the third party assembly (psn.disc) reference in my application, then this assembly has to be in the GAC at run-time or I should package this assembly along with my application and load it to GAC. The first option is ruled of as this third party assembly may or may not be present in the GAC. The second option is ruled out too, as this assembly is dependent on many other assemblies and I cannot package everything.

As a result I am checking (is not implemented in the code) if the assembly is present and then loading it at run-time.
Oct 22 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
4822
by: Outshined | last post by:
I have a class library where just about every class uses its static initializer to register with a central registry object in the same assembly. I am hoping for some sort of Assembly.Load event that I can handle to go through my assembly and invoke the static initializer on each relevant class. This way, everything that needs to be registered will be registered before the first request to the registry object. So my questions are:
0
1130
by: Daniel | last post by:
when loading this dll into an assembly via late binding how do i diferentiate between outer CAsmToLoad class and the inner class CAsmToLoad inside of CAsmToLoad2? public class CAsmToLoad { public string IOCTL(string strMsg) { return "hello world"; }
9
1543
by: John Harrison | last post by:
Both gcc 3.3.1 and VC++ 7.1 compile the following code. struct Outer { struct Inner { int f() { return c; } }; private: static const int c;
4
4646
by: Dennis C. Drumm | last post by:
Is there a way with C# to allow one class access to a method or field of another class, without making that method or field visible to all other classes, as would be the case when making the method or field public? Thanks, Dennis
6
2082
by: Marco | last post by:
Howdy! Given: public abstract class A { public abstract int A1(int i); private class B { private int B1(int i) { int j;
4
1975
by: Christopher Ireland | last post by:
Hi -- I'm trying to find an example of a nested class implemented within the .NET Framework itself but without much success. I don't suppose that anybody knows of such an example off the top of their head, do they? Many thanks! -- Best Regards,
6
3593
by: z_learning_tester | last post by:
Quick question- What happens if you have a private class with a public static method? Can you still say the following? Lets say you are making this call from another class, say class2... int myVal = class1.method(); It seems that you should not be able to, after all from class2, you should not be able to see the private class1, so it's public static method is effectively wasted.
5
2693
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/callnetfrcom.asp The Joy of Interoperability Sometimes a revolution in programming forces you to abandon all that's come before. To take an extreme example, suppose you have been writing Visual Basic applications for years now. If you're like many developers, you will have built up a substantial inventory of code in that time. And if you've been following...
5
2194
by: ZikO | last post by:
Hi there. I have a problem. I have created nested classes but don't know how to access to inner classes. I know I can create objects: Hen Object; Hen::Nest ObjectNest; Hen::Nest::Egg ObjectEgg; and have access to particular elements
0
10562
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10319
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10303
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10070
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9132
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7608
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2978
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.