473,480 Members | 1,661 Online
Bytes | Software Development & Data Engineering Community
Create 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 1277
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
4791
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...
0
1116
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 {...
9
1521
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
4608
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...
6
2063
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
1960
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...
6
3568
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...
5
2659
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...
5
2178
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...
0
7041
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
7044
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,...
1
6739
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
6929
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...
0
5337
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
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
181
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...

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.