473,396 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Classes and Interfaces at reflection

Question:

public interface Interface1
{}
public interface Interface2:Interface1
{}
public class Foo:Interface2
{}

I want while creating new instance of Foo cast it into Interface1 so doing:
Interface1 i = (Interface1)new Foo;
i.FooMe();
Working fine, BUT

while reading Foo from assemblies like
Interface1 i =
(Interface1)Activator.CreateInstance(FooAssembly.G etType(FooAssembly.GetType().ToString()));
failed on "Invalid Cast".
Whide doing
Object o =
Activator.CreateInstance(FooAssembly.GetType(FooAs sembly.GetType().ToString()));
it rerurns me Foo
So why the cast is invalid???

TNX
--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
Nov 16 '05 #1
1 1095
Just got an answer (tnx to Jon) ;)
If you have the same problem just build your projects into one file library
and use the lib from there. If you'll do it regular VS name you'll have a
couple of interfaces instances so it impossible to case from different
assemplies(even the same class) as instances.

TNX to Jon ;)

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:uN****************@TK2MSFTNGP15.phx.gbl...
Question:

public interface Interface1
{}
public interface Interface2:Interface1
{}
public class Foo:Interface2
{}

I want while creating new instance of Foo cast it into Interface1 so
doing:
Interface1 i = (Interface1)new Foo;
i.FooMe();
Working fine, BUT

while reading Foo from assemblies like
Interface1 i =
(Interface1)Activator.CreateInstance(FooAssembly.G etType(FooAssembly.GetType().ToString()));
failed on "Invalid Cast".
Whide doing
Object o =
Activator.CreateInstance(FooAssembly.GetType(FooAs sembly.GetType().ToString()));
it rerurns me Foo
So why the cast is invalid???

TNX
--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

Nov 16 '05 #2

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

Similar topics

9
by: Gomaw Beoyr | last post by:
Two question about the "partial classes" (in the next wersion of ..NET). Question 1 ========== Will partial classes (in the next version of C#) have to be declared "partial" in ALL places. ...
2
by: Saso Zagoranski | last post by:
Hi! Here's my problem: Let's say I have 2 interfaces: interface Module1 { public void method1(); } interface Module2
4
by: glenn | last post by:
Is there a way to loop through a classes fields without first knowing what fields are there? Trying to write a generic class that could build a query based on a classes fields and types. This...
30
by: Frank Rizzo | last post by:
We are having one of those religious debates at work: Interfaces vs Classes. My take is that Classes give you more flexibility. You can enforce a contract on the descendant classes by marking...
12
by: Josema | last post by:
Hi, Im starting develop a portal, and i never used interfaces in the past. As any portal will be possible register (add), delete, modify a user. In this portal also will be possible...
9
by: Sean Kirkpatrick | last post by:
To my eye, there doesn't seem to be a whole lot of difference between the two of them from a functional point of view. Can someone give me a good explanation of why one vs the other? Sean
6
by: s99999999s2003 | last post by:
hi i come from a non OO environment. now i am learning about classes. can i ask, in JAva, there are things like interface. eg public interface someinterface { public somemethod (); .... ... }...
47
by: Larry Smith | last post by:
I just read a blurb in MSDN under the C++ "ref" keyword which states that: "Under the CLR object model, only public single inheritance is supported". Does this mean that no .NET class can ever...
5
by: | last post by:
I am having problems with casting or converting a class to to an interface from which it derives. I'm certain that it's due to how it's being loaded, but I'm not sure how to get past the problem....
5
by: =?Utf-8?B?UmljaA==?= | last post by:
Greetings, I am actually a VB.Net guy, but I have worked somewhat with C++ and C#. I just want to ask about the relationship between Abstract Classes and Interfaces. My first question is if...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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...
0
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,...
0
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
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
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...

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.