473,800 Members | 2,722 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I get the namespace of a object

I have a couple of WebForms that all inherit from a custom base class
(which in turn inherits from System.Web.UI.P age). I would like to
locate a function in the base class that iterates through the control
collection of the child page, looks at the type (looking for
System.Web.UI.W ebControls.Labe l type), and pulls out the full
namespace and ID for that control (then goes out to a resouce file and
sets the text of the control for the specified locale amoungst some
other things). Everything is pretty simplistic except I cant figure
out how to extract the object namespace from the control (if that
information is even retained in the assembly).

In other words, I need to extract the namespace of a specific member
(NOT the namespace of the member "type"). I am looking for something
like "Company.Produc t.Module.SubMod ule.lblStreetAd dress3".

Below is some sample code. Thanks for your help!

Solomon Shaffer

Child WebForm:
namespace Company.Product .Module.SubModu le
{
/// <summary>
/// Summary description for CreateAddress .
/// </summary>
public class CreateAddress : Page
{
protected System.Web.UI.W ebControls.Labe l lblStreetAddres s1;
protected System.Web.UI.W ebControls.Labe l lblStreetAddres s2;
protected System.Web.UI.W ebControls.Labe l lblStreetAddres s3;
protected System.Web.UI.W ebControls.Labe l lblCity;
protected System.Web.UI.W ebControls.Labe l lblState;
protected System.Web.UI.W ebControls.Labe l lblZipCode;

private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
}
}
}

Base class:
namespace Company.Product .Module
{
/// <summary>
/// Summary description for Page.
/// </summary>
public class Page : System.Web.UI.P age
{
private void Page_Load(objec t sender, System.EventArg s e)
{
System.Web.UI.P age oPage = (System.Web.UI. Page)sender;
SetControlText( oPage );
}

private void SetControlText( Control oParentControl )
{
ResourceManager oResourceManage r = new ResourceManager ( "English",
typeof( Page ).Assembly );

if ( oParentControl. HasControls() )
{
foreach ( Control oControl in oParentControl. Controls )
{
if ( oControl.GetTyp e().ToString() ==
"System.Web.UI. WebControls.Lab el" )
{
Label oLabel = (Label)oControl ;
//This does not work!
string sNamespace = oControl.GetTyp e().Namespace.T oString();
oLabel.Text = oResourceManage r.GetString( sNamespace + "." +
oControl.ID );
}

SetControlText( oControl );
}
}
}
}
}

Resource File:
<data name="Company.P roduct.Module.S ubModule.lblStr eetAddress3">
<value>Addres s Line 3</value>
</data>
Nov 15 '05 #1
1 1599
If you can find the namespace of a type then you could find the page that the label is on and get the namespace of that.

--
Michael Culley
"Solomon Shaffer" <so************ *@cynthetic.com > wrote in message news:a2******** *************** ***@posting.goo gle.com...
I have a couple of WebForms that all inherit from a custom base class
(which in turn inherits from System.Web.UI.P age). I would like to
locate a function in the base class that iterates through the control
collection of the child page, looks at the type (looking for
System.Web.UI.W ebControls.Labe l type), and pulls out the full
namespace and ID for that control (then goes out to a resouce file and
sets the text of the control for the specified locale amoungst some
other things). Everything is pretty simplistic except I cant figure
out how to extract the object namespace from the control (if that
information is even retained in the assembly).

In other words, I need to extract the namespace of a specific member
(NOT the namespace of the member "type"). I am looking for something
like "Company.Produc t.Module.SubMod ule.lblStreetAd dress3".

Below is some sample code. Thanks for your help!

Solomon Shaffer

Child WebForm:
namespace Company.Product .Module.SubModu le
{
/// <summary>
/// Summary description for CreateAddress .
/// </summary>
public class CreateAddress : Page
{
protected System.Web.UI.W ebControls.Labe l lblStreetAddres s1;
protected System.Web.UI.W ebControls.Labe l lblStreetAddres s2;
protected System.Web.UI.W ebControls.Labe l lblStreetAddres s3;
protected System.Web.UI.W ebControls.Labe l lblCity;
protected System.Web.UI.W ebControls.Labe l lblState;
protected System.Web.UI.W ebControls.Labe l lblZipCode;

private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
}
}
}

Base class:
namespace Company.Product .Module
{
/// <summary>
/// Summary description for Page.
/// </summary>
public class Page : System.Web.UI.P age
{
private void Page_Load(objec t sender, System.EventArg s e)
{
System.Web.UI.P age oPage = (System.Web.UI. Page)sender;
SetControlText( oPage );
}

private void SetControlText( Control oParentControl )
{
ResourceManager oResourceManage r = new ResourceManager ( "English",
typeof( Page ).Assembly );

if ( oParentControl. HasControls() )
{
foreach ( Control oControl in oParentControl. Controls )
{
if ( oControl.GetTyp e().ToString() ==
"System.Web.UI. WebControls.Lab el" )
{
Label oLabel = (Label)oControl ;
//This does not work!
string sNamespace = oControl.GetTyp e().Namespace.T oString();
oLabel.Text = oResourceManage r.GetString( sNamespace + "." +
oControl.ID );
}

SetControlText( oControl );
}
}
}
}
}

Resource File:
<data name="Company.P roduct.Module.S ubModule.lblStr eetAddress3">
<value>Addres s Line 3</value>
</data>

Nov 15 '05 #2

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

Similar topics

88
5155
by: Tim Tyler | last post by:
PHP puts most of its functions into a big flat global namespace. That leads to short function names - but creates a namespace minefield for programmers. Lots of the functions are legacies from the days before PHP got object-oriented features. For instance we currently have:
2
1958
by: Fritz Bosch | last post by:
Hi experts Is is possible to import/manipulate a module such that I can supply its __dict__? I want to supply my own dict subclass object to be filled by the import, e.g. a class like: >>> class MyModuleDict(dict): .... def __setitem__(self,name,val):
6
555
by: clinton__bill | last post by:
Hi, I usually use "using namespace <namespace_name>" to reference a namespace. Today I run across a code, in its header file it has this, namespace SP1{ class C1; } While SP1::C1 is a namespace::class declared and defined somewhere else. It seems the above 3 lines is similar to "using namespace SP1;",
7
7440
by: Kevin Newman | last post by:
I've been toying with a namespace manager, and wanted to get some input. So what do you think? if (typeof com == 'undefined') var com = {}; if (!com.unFocus) com.unFocus = {}; com.unFocus.Namespaces = new function() { this.register = function(namespace) { namespace = namespace.split('.');
27
2112
by: Ron Adam | last post by:
Hi, I found the following to be a useful way to access arguments after they are passed to a function that collects them with **kwds. class namespace(dict): def __getattr__(self, name): return self.__getitem__(name) def __setattr__(self, name, value): self.__setitem__(name, value) def __delattr__(self, name):
20
3872
by: Patrick Guio | last post by:
Dear all, I have some problem with insertion operator together with namespace. I have a header file foo.h containing declaration of classes, typedefs and insertion operators for the typedefs in a named namespace namespace foo { class Foo
5
10013
by: SenthilSS | last post by:
My application produces XML Data files which have XML namespace qualified XML elements (nodes), but the namespace itself is not declared in the data file. My task is to read these data files in a C# app for viewing purposes. I am using "XmlDocument" and "DataSet" for displaying the XML data in the Data grid. Problem: If I add the Namespace declaration to the data file itself (by manually opening the file and adding a new Root element...
2
5065
by: Pathogenix | last post by:
Greetings, I'm trying to fix a web service client which has been implemented in a dailywtf worthy manner. I've decided to rip all the old code out and start again from the proxy generated by wsdl.exe. I've immediately run up against the same problem that spawned the original, deeply fascinating code. I can make a request, and Fiddler shows that the service is returning a valid response, but the client is returning a null object....
0
9691
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10507
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...
1
10255
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
9092
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
7582
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
6815
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5473
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4150
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 we have to send another system
3
2948
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.