|
Yes it helps me a lot for my understanding.
I thought that because c2 is inherited from c1, I1<c2> and I1<c1> was the same thing. So I1<c1> is the base of I1<c2> and in this case, it could be possible to cast from a I1<c2> to I1<c1>.
The problem with your solution #1 is that I can't put both return value from GetG1() & GetG2() in the same objet or an array of the same type (Ex: I1<c1>[]). The solution #2 is better but you're gonna be able to add an object of type c1.
Is there a pattern to do what I want? I mean, you have a factory accepting a base class X and you want to inherite a new factory but in this one, you only want to accept an inherited class from X.
Thanks for your help!!!
|
|
|
|
|
Hello
You didn't specify, you want to return what type in the GetG2() method??
daveroberge wrote: Only want to accept an inherited class from X.
If X is c1 then you want to return c2, right? G1 is the factory of c1, so G2 is the factory of C2, so, where is the problem? You could implement an I1< c2 > in G2 class!
Regards
|
|
|
|
|
No I can't because both returned object from G1 and G2 will be put in the same object but at different time. Here's some changes in my code.
****old*****
private void TestMethod(){
I1<c1> oTest1 = GetG1();
I1<c1> oTest2 = GetG2();}
****new****
private I1<c1> TestMethod(int iVal){
if(iVal == 1 ) return GetG1();
else return GetG2();}
private void CallMethod() {
I1<c1> oValue = TestMethod(1);
oValue = TestMethod(2); } ****** Error while casting in GetG2()***
Thanks again for your help
D.
|
|
|
|
|
Hello
Alright I got another way. Thank God for explicit casts..
Try adding this to your g2<t> class:
public static explicit operator g1<c1>(g2<t>
{
g1<c1> Toreturn = new g1<c1>();
//conversion here
return Toreturn;
}
now in GetG2() method return (g1<c1>)oG2;
I hope it works this time.
Regards
|
|
|
|
|
Yeah I also tried that and that's my better option now but there's a hic... the returned object will not be the same after casting. All c2 objects will be the same but not the container g1. In my example, this case is not important I agree but it could be in another case. Anyway, it's still the better way... but I'm still confusing with the fact that there's an automatic override made on methods but the casting is not clearly working....
Thanks a lot
|
|
|
|
|
First of all (I don't know if this is because you stipped out the <> tags), your interface I1 does not expose a generic type, it should be declared as
interface I1<T>
{
void meth(T t);
} Unless of course I1 is declared inside another generic class which exposes the generic type T , but from your code this is not the case.
The same applies for the declarations of g1 and g2 , you need to include the <T> after the name (unless it's part of a parent class). Then everything should work. Although in your lines of code which create the generics you will need to specify which type to implement: e.g.
I1 ol1 = null;
g2 = og2 = new g2<int>();
ol1 = (I1) og2; So in summary your code should probably look along the lines of
class c1
{
}
class c2 : c1
{
}
interface I1<T>
{
void meth(T t);
{
}
}
class g1<T> : I1 where T : c1
{
}
class g2<T> : g1 where T : c2
{
}
static void Main(...)
{
I1<object> oI1 = null;
g2 og2 = new g2<object>();
oI1 = (I1)og2;
} Of couse this would be much nicer if the variables and types were named more appropriately.
As of how to accomplish this I have no idea, have you tried Google? Faiing that try
|
|
|
|
|
I'm sorry, I didn't check the box <Ignore HTML tags....> so all my <> tags were removed. I also tried on Google many times with different parameters but I have not found anything about that....
Thanks
|
|
|
|
|
Can you post the correct source code which is not working properly then?
As of how to accomplish this I have no idea, have you tried Google? Faiing that try
|
|
|
|
|
Yes, my code is in a previous post...
thanks
|
|
|
|
|
How does microsoft insert descriptions of their classes?
I mean, if you type "System" and then a period, you're presented with a list of classes, methods, & namespaces to choose from.
Many of these items contain descriptions. For example if you type "System", and then scroll down to "WeakReference", it displays "References a weak reference, which represents an object...."
How can I insert these types of descriptions into my own custom classes and methods?
thanks.
-Goalie35
|
|
|
|
|
Hello
Just type "///" in the line before the method or property name and the snippet wizard will make a lock like this:
/// <summary>
/// Write a description here
/// </summary>
/// <param name="ParamA"></param> Write a description here
/// <param name="ParamB"></param> Write a description here
public void MyMethod(int ParamA, int ParamB)
{
}
Now when you use this method in your project, or when you link to the project from another project in the solution, you will see the description.
To make this happen when you compile the code as a dll - exe don't need description, do they?- you must make an xml documentation file. To do that:
Your Projects property => Build => Check "XML doxumentation" in the lower part of the screen.
Regards
|
|
|
|
|
That did it!
Thanks Rose.
-Goalie35
|
|
|
|
|
Hello
Goalie35 wrote: Thanks Rose.
My name isn't Rose . It's the rose gif in my signature. It didn't appear because I removed html tags from my post.. My name is Nader Elshehabi.
Anyway, you are welcome.
Regards
|
|
|
|
|
So, a rose by any other name is Nader Elshehabi
only two letters away from being an asset
|
|
|
|
|
Regards
|
|
|
|
|
Hello,
Is there any free class library, or solution or command line software available for converting an HTML document to either MS Word or RTF ?
Thanks
|
|
|
|
|
bashiwala wrote: Is there any free class library, or solution or command line software available for converting an HTML document to either MS Word or RTF ?
Ummmm you mean like MS Word?
"Alot of the people on this forum are incredibly stupid, thinking that the internet is real" Score: 1.0 in the Soap Box
led mike
|
|
|
|
|
Hi,
My software will edit html and finally the html should be saved as an MS Word .doc file or .rtf file. In order to do that, I am searching for solutions, either Class library or free command line programs (so that I can call them using System.Diagnostic.Process) etc..
Do you know if there is anything like that available ?
|
|
|
|
|
Well I don't know of anything like that but you can access much of the functionality of MS Word through it's COM interface.
"Alot of the people on this forum are incredibly stupid, thinking that the internet is real" Score: 1.0 in the Soap Box
led mike
|
|
|
|
|
Not free but http://www.aspose.com[^] has some components which do this I think. They're not that expensive either.
As of how to accomplish this I have no idea, have you tried Google?
Failing that try
|
|
|
|
|
Hi,
thanks for your reply,
I checked the website, and the solution was looking for was found for US$2700 Did you mean it as a cheap price
I am still searching internet and I found a VBSCript who can convert HTML to Text. But I dont know how to use VBSCript within C#. So do you think if I just call SHELL (Diagnostic.Process.Start(...)) that VBSCRIPT, it should work on Every client's pc ?
Anyway thanks again for giving me clue.
Regards.
|
|
|
|
|
bashiwala wrote: US$2700
I don't remember it ever being priced that high, I seem to remember ~$100.
Re: Calling VBScript from C# yes you'll have to use Process.Start etc and all those namespaces. There are however some free controls which will allow html to be converted to rtf and vice versa. I did come across a small pure C# HTML browser component a short while ago which I seem to remember had an export to rtf function. Darned if I can remember the name of it though, I think it was posted as an article here on CP.
Re: Working on every client's PC, as long as they have VBScript installed (which I think is optional) then yes it will work.
As of how to accomplish this I have no idea, have you tried Google? Faiing that try
|
|
|
|
|
In my MDI application. I want some variables available in all forms. How can I do this?
Thanks
Syed Shahid Hussain
|
|
|
|
|
Hi,
To my knowledge, there is an easy way to do that, I am not aware of any other and more efficient techniqies.
VERY VERY EASY WAY:
Make an XML file, with all the variables name and value. Every time the value is changed from any Form, update the XML file. And
All forms will share the XML file to load the value of the variable.
You may Use lock to prevent concurrent modification to that xml. OR you can choose Database to store the name value pairs which takes care of concurrent modification.
|
|
|
|
|
That the perfect way but unfortunately I dont Know XML but I have some idea of it. However so thanks
Bye
Syed Shahid Hussain
|
|
|
|