Hi,
I have an .aspx page that needs to instantiate an object whose type in
not known until runtime. The definition of said object resides in
/App_code/CMS.cs
CMS.cs
=============== ===
namespace CMS{
public interface IWindmill{
string emit
{get;}
}
public class MyObject : IWindmill{
string html;
public MyObject(){
html = "Hello World"
}
public string emit{
get { return html; }
}
}
In my webpage, I am trying to instantiate myObject dynamically, like
so:
Default.aspx.cs
============
protected void Page_Load(objec t sender, EventArgs e){
Type t = Type.GetType("C MS.MyObject"); //This object will vary and
won't be determined until runtime
CMS.IWindmill myObj = (CMS.IWindmill) Activator.Creat eInstance(t);
MethodInfo m = myObj.GetType() .GetMethod("get _emit");
if (m != null){
string s = (string)m.Invok e(myObj, null);
Response.Write( s);
}
}
My Type t will return null unless I include the CMS namespace in the
Default.aspx.cs file. Is there a way for me to return the proper value
if the object is defined in an external file? I understand I could
package the CMS namespace in an assembly and reference it through its
qualified name, but is there an easier and more direct way to get the
type in an external .cs file?
Regards,
Chris 1 2052
<ha******@hotma il.comwrote:
<snip>
My Type t will return null unless I include the CMS namespace in the
Default.aspx.cs file. Is there a way for me to return the proper value
if the object is defined in an external file? I understand I could
package the CMS namespace in an assembly and reference it through its
qualified name, but is there an easier and more direct way to get the
type in an external .cs file?
Well, it will certainly be in *an* assembly by the time it's running.
Will you always want types from the same assembly, and do you know
*one* of those types at compile-time? If so, use typeof(...) to get
that type, then get the Assembly reference from that, then call
Assembly.GetTyp e.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Suresh |
last post by:
Hi,
I have an C# CSEXE.exe (CSexe.cs) and a CSDll.dll
(CSdll.cs). exe is compiled with a reference to dll.
Calling for the class Type defined in CSDLL.dll using
Type.GetType( "myDLLnamespace.CSDll" ) returns null. I
made sure that the fully qualified class defined in the
dll is case-sensitive.
// CSEXE.exe
|
by: Marco |
last post by:
Hi.
I am trying to get a type object using GetType. For this,
I use:
Type type = Type.GetType("System.Windows.Forms.TextBox");
But after this line, when I check, type is null.
What am I doing wrong ? How to do it right ?
|
by: ron |
last post by:
Hi,
I am currently using the base class GetType() in the
following way and was woundering if there was a different
way of looking at types and doing a comparison for
equality.
Thanks Ron
foreach(System.Web.UI.Control ctl in this.Controls)
{
|
by: Jimi |
last post by:
What am I doing wrong?
I'm trying to get a type object for a type which is not currently
loaded in my project (otherwise I'd use "typeof").
System.Type oType = System.Type.GetType("SomeNamespace.SomeType");
But oType is always "<undefined value>" after this line.
Any help is much appreciated.
|
by: hazz |
last post by:
"Value cannot be null.\r\nParameter name: type" is the exception thrown
after the CreateInstance method below.
Type t = Type.GetType(GetConfigValue("PasswordProvider"));
IPasswordProvider ppdr= (IPasswordProvider)Activator.CreateInstance(t);
GetConfigValue DOES return the correct value from the config file -
"namespace.DBPassword, namespace"
It appears that Type.GetType is NOT finding the assembly whose name is the
| |
by: Nicolas |
last post by:
I want to return the proper Null to the SQL Database if my property is
nothing
Also I thought about creating a function so I don't have to put so many if
statement for each property for each classes etc.
However if I call ReturnValue(myClass.CompanyName) and CompanyName is
Nothing then it crash where it shoud return SqlTypes.SqlString.Null
Private _CompanyName As String
|
by: Sky |
last post by:
I have been looking for a more powerful version of GetType(string) that will
find the Type no matter what, and will work even if only supplied
"{TypeName}", not the full "{TypeName},{AssemblyName}"
As far as I know yet -- hence this question -- there is no 'one solution
fits all', but instead there are several parts that have to be put together
to check.
What I have so far is, and would like as much feedback as possible to ensure
I've...
|
by: Carlos Rodriguez |
last post by:
I have the following function in C#public void Undo(IDesignerHost host)
{
if (!this.componentName.Equals(string.Empty) && (this.member != null))
{
IContainer container1 = (IContainer)
host.GetService(typeof(IContainer));
IComponent component1 =
container1.Components;
PropertyInfo info1 =
component1.GetType().GetProperty(this.member.Name);
|
by: Martin Eckart |
last post by:
Hi folks,
Who can explain me why the following expression does not result in getting
the correct type, but null:
Type t = Type.GetType("System.Xml.XmlReader");
For "System.String" it works as well as for "System.IO.Stream" or
"System.Globalization.CultureInfo". Does that related to the constructor of
XmlReader being not public?
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |