Results 1 to 12 of 12

Thread: Structure of Properties within a Seperate Class?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2003
    Location
    Eden Prairie Minnesota
    Posts
    301

    Question Structure of Properties within a Seperate Class?

    I am trying to make a Library for my own use. It's going to be a System.Net.Socket with support for SOCKS4/5 Proxy Servers. I have different variables, so i wanted one Struct for the Server i am connecting to and another struct for the proxy server i am connecting through. However i have two projects, one is the console and one is the library. I am not sure if i can do what i want to do.

    This is an example of what i want to do, but i am sort of learning about Inheritance and Polymorphism as i go lol

    Code:
    using System;
    
    namespace Test
    {
    	class Class1 : Class2
    	{
    		static void Main()
    		{
    			myClass Class2 = new Class2();
    			variables myClass.myStruct = new myClass.myStruct();
    			variables.x = 5;
    		}
    	}
    
    	class Class2
    	{
    		struct myStruct 
    		{
    			int x;
    			int y;
    		}
    	}
    }
    This is what i am doing

    Code:
    using System;
    using System.Text;
    using System.Net;
    using System.Net.Sockets;
    using Test.Socket;
    
    class Test {
    	static void Main()
    	{
    		Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
    
    		s.ProxyEndPoint = new IPEndPoint(IPAddress.Parse("SERVER"), PORT);
    		s.ProxyUser = "username";
    		s.ProxyPass = "password";
    		s.ProxyType = ProxyTypes.Socks5;
    
    		s.Connect("SERVER", PORT);
    	}
    }
    I want it to be like

    Proxy.User
    Proxy.Pass
    Proxy.Type
    Proxy.EndPoint
    Proxy.Server
    Proxy.Port

    However those are Properties in a different class. Is it possible to make properties within a struct within a totally different class/project?

    Sorry if i rambled alot, i am just horribly confused . If you have ANY Questions please ask and i will try my best to answer them.

    Thank You So Much
    There are only two kinds of people who are truely fascinating: people who know absolutely everything, and people who know absolutely nothing.

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Structure of Properties within a Seperate Class?

    Do you mean you want to create

    Proxy.User
    Proxy.Pass
    Proxy.Type
    Proxy.EndPoint
    Proxy.Server
    Proxy.Port

    as your own structure somewhere? How are those related to the code you have pasted above?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2003
    Location
    Eden Prairie Minnesota
    Posts
    301

    Re: Structure of Properties within a Seperate Class?

    i want to create a Structure of Properties exactly like you said. However i am using a Derived Class as a Asynchrous Socket. I can't figure out how to access the Structure of my derived class. I am not really sure i need to, but that's what i am thinking.

    Thanks

    - Joel
    There are only two kinds of people who are truely fascinating: people who know absolutely everything, and people who know absolutely nothing.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2003
    Location
    Eden Prairie Minnesota
    Posts
    301

    Re: Structure of Properties within a Seperate Class?

    Code:
    using System;
    using System.Net;
    
    namespace Test
    {
    	public class Parent
    	{
    		struct ProxyInfo
    		{
    			public enum Types {None = 0, Socks4 = 4, Socks5 = 5}
    
    			private IPEndPoint m_EndPoint;
    
    			private Types m_Type;
    
    			private string m_Username;
    
    			private string m_Password;
    
    			private string m_Server;
    
    			private int m_Port;
    
    			public IPEndPoint EndPoint 
    			{
    				get 
    				{
    					return m_EndPoint;
    				}
    				set 
    				{
    					m_EndPoint = value;
    				}
    			}
    
    			public Types Type 
    			{
    				get 
    				{
    					return m_Type;
    				}
    				set 
    				{
    					m_Type = value;
    				}
    			}
    
    			public string Username
    			{
    				get 
    				{
    					return m_Username;
    				}
    				set 
    				{
    					if (value == null)
    						throw new ArgumentNullException();
    					m_Username = value;
    				}
    			}
    
    			public string Password
    			{
    				get 
    				{
    					return m_Password;
    				}
    				set 
    				{
    					if (value == null)
    						throw new ArgumentNullException();
    					m_Password = value;
    				}
    			}
    
    			public string Server
    			{
    				get 
    				{
    					return m_Server;
    				}
    				set 
    				{
    					if (value == null)
    						throw new ArgumentNullException();
    					m_Server = value;
    				}
    			}
    
    			public int Port 
    			{
    				get 
    				{
    					return m_Port;
    				}
    				set 
    				{
    					m_Port = value;
    				}
    			}
    		}
    
    	}
    
    	public class Child
    	{
    		static void Main()
    		{
    			Parent child = new Parent();
    			child.ProxyInfo Proxy = new child.ProxyInfo();
    			Console.ReadLine();
    		}
    	}
    }
    For some reason the Intellisense never shows the struct or any of it's properties when i access it via 'child'.

    I want to access the methods INSIDE the Parent class as well as have a seperate struct object derived from the structure inside the same derived class. (wow does that sound horrible)

    Maybe i am just horribly confused and someone knows a better way to do this. I didn't want to have a whole bunch of Properties with a Prefix describing what they are for, i just wanted to use a struct to make it more organized.

    Then i can do my project like this:

    Code:
    	public class Child
    	{
    		static void Main()
    		{
    			ProxySocket s = new ProxySocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
    
    			s.ProxyInfo Proxy = new s.ProxyInfo();
    
    			Proxy.Server = "255.255.255.255";
    			Proxy.Port = 1080;
    			Proxy.EndPoint = new IPEndPoint(IPAddress.Parse(Proxy.Server), Proxy.Port);
    			Proxy.Username = "username";
    			Proxy.Password = "password";
    			Proxy.Type = Types.Socks5;
    
    			s.Connect
    
    			Console.ReadLine();
    		}
    	}
    This is the best explination i can give, i just hope someone understands my logic.

    Thanks Everybody For Your Help

    - Joel Zimmerman
    There are only two kinds of people who are truely fascinating: people who know absolutely everything, and people who know absolutely nothing.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Structure of Properties within a Seperate Class?

    Your structure is a nested type, NOT a member of an instance of the class. 'child' is an instance of the Parent class, so you should be referring to 'Parent.ProxyInfo', not 'child.ProxyInfo'.
    Attached Images Attached Images  
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Structure of Properties within a Seperate Class?

    Further, if you want the Parent class to have a member variable that is of that type then you would need to declare it so. In the code you posted previously the Parent class has no properties whatsoever. It sounds like what you may be wanting is to give the Parent class a property of the ProxyInfo type. To do that you should declare a private variable of that type and then define a public property to access that variable.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2003
    Location
    Eden Prairie Minnesota
    Posts
    301

    Re: Structure of Properties within a Seperate Class?

    Thanks for the reply. Imma study what you said because i didn't really understand it at first glance. I'm going to play with some things and look on MSDN some and i'll get back to you if i have any more problems.

    Thanks

    - Joel
    There are only two kinds of people who are truely fascinating: people who know absolutely everything, and people who know absolutely nothing.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Structure of Properties within a Seperate Class?

    In the screen shot in my previous post, an instance of the SomeClass class does not have a member property that is a SomeStruct object. If you wanted that class to have a property of that type it would have to look like this:
    Code:
        public class SomeClass
        {
            // This is a nested type.  It has nothing to do with instances of the class.
            public struct SomeStruct
            {
                public string SomeField;
            }
    
            // This is a private variable of the nested type.  It is a member an individual instance.
            private SomeStruct myVar;
    
            // This property exposes the instance variable.
            public SomeStruct MyProperty
            {
                get { return myVar; }
                set { myVar = value; }
            }	
        }
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2003
    Location
    Eden Prairie Minnesota
    Posts
    301

    Re: Structure of Properties within a Seperate Class?

    Ok, i managed to do what i wanted to do.

    THANK YOU SO MUCH

    I got one problem

    This is what i did

    Code:
    		private Proxy m_ProxyInfo;
    
    		public ProxyInfo Proxy
    		{
    			get 
    			{
    				return m_ProxyInfo;
    			}
    		}
    This is how i accessed it

    Code:
    			Parent child = new Parent();
    
    			child.Proxy.Server = "255.255.255.255";
    			child.Proxy.Port = 1080;
    			child.Proxy.EndPoint = new IPEndPoint(IPAddress.Parse(Proxy.Server), Proxy.Port);
    			child.Proxy.Username = "username";
    			child.Proxy.Password = "password";
    			child.Proxy.Type = Types.Socks5;
    Is there anyway to Shorten Child.Proxy to just Proxy?

    Thanks Again man

    - Joel

    EDIT: I figured it out Before you made your second post - YAY!
    Last edited by BaDDBLooD; Feb 20th, 2006 at 08:39 PM.
    There are only two kinds of people who are truely fascinating: people who know absolutely everything, and people who know absolutely nothing.

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2003
    Location
    Eden Prairie Minnesota
    Posts
    301

    Re: Structure of Properties within a Seperate Class?

    Sigh, this is not working out how i wanted it to afterall lol
    There are only two kinds of people who are truely fascinating: people who know absolutely everything, and people who know absolutely nothing.

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2003
    Location
    Eden Prairie Minnesota
    Posts
    301

    Re: Structure of Properties within a Seperate Class?

    This is not going as well as i had hoped. I am having trouble Setting the variables.

    Code:
    		private ProxyInfo m_ProxyVar;
    
    		public ProxyInfo Proxy
    		{
    			get 
    			{
    				return m_ProxyVar;
    			}
    			set 
    			{
    				m_ProxyVar = value;
    			}
    		}
    
    		public struct ProxyInfo
    		{
    			private IPEndPoint m_EndPoint;
    
    			private ProxyTypes m_Type;
    
    			private string m_Username;
    
    			private string m_Password;
    
    			private string m_Server;
    
    			private int m_Port;
    
    			public IPEndPoint EndPoint 
    			{
    				get 
    				{
    					return m_EndPoint;
    				}
    				set 
    				{
    					m_EndPoint = value;
    				}
    			}
    
    			public ProxyTypes Type 
    			{
    				get 
    				{
    					return m_Type;
    				}
    				set 
    				{
    					m_Type = value;
    				}
    			}
    
    			public string Username
    			{
    				get 
    				{
    					return m_Username;
    				}
    				set 
    				{
    					if (value == null)
    						throw new ArgumentNullException();
    					m_Username = value;
    				}
    			}
    
    			public string Password
    			{
    				get 
    				{
    					return m_Password;
    				}
    				set 
    				{
    					if (value == null)
    						throw new ArgumentNullException();
    					m_Password = value;
    				}
    			}
    
    			public string Server
    			{
    				get 
    				{
    					return m_Server;
    				}
    				set 
    				{
    					if (value == null)
    						throw new ArgumentNullException();
    					m_Server = value;
    				}
    			}
    
    			public int Port 
    			{
    				get 
    				{
    					return m_Port;
    				}
    				set 
    				{
    					m_Port = value;
    				}
    			}
    		}
    And

    Code:
    using System;
    using System.Text;
    using System.Net;
    using System.Net.Sockets;
    using Test.ProxySocket;
    
    class Console {
    	static void Main()
    	{
    		ProxySocket s = new ProxySocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
    
    		s.Proxy.Server = "255.255.255.255";
    		s.Proxy.Port = 1080;
    		s.Proxy.EndPoint = new IPEndPoint(IPAddress.Parse(Proxy.Server), Proxy.Port);
    		s.Proxy.Username = "username";
    		s.Proxy.Password = "password";
    		s.Proxy.Type = ProxyTypes.Socks5;
    	}
    }
    I get "Cannot Modify the return value of 'Test.ProxySocket.ProxySocket.Proxy' because it is not a variable"

    That ProxySocket.ProxySocket looks very suspicious but i have no idea why it happens.

    Any help is appreciated

    - Joel
    There are only two kinds of people who are truely fascinating: people who know absolutely everything, and people who know absolutely nothing.

  12. #12
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Structure of Properties within a Seperate Class?

    When you get an instance of a class through a property you are getting a reference to the same underlying object. That's the way reference types work. When you get an instance of a structure through a property you are getting a temporary copy of the existing object. That's the way value types work. You are not allowed to change the properties of that copy because there is no valid reason for doing so because it is immediately lost. What you need to do is assign the copy to a variable, change whatever properties you want to and then assign the object back to the property.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width