|
You misunderstand - I'm not complaining about your answer, just clarifying things.
Thanks for your interest.
|
|
|
|
|
stovesy wrote: IFactoryBase<ibusinessobjectbase>
IFactoryBase<customer> is needed then.
|
|
|
|
|
We're getting to the crux of the matter.
What you suggest does work, but I don't know the type of the generic class, only that it derives from IBusinessObjectBase
So when I try ...(customerFactory is IFactoryBase<ibusinessobjectbase>).... it fails.
Thanks for your time
|
|
|
|
|
stovesy wrote: We're getting to the crux of the matter.
Indeed
stovesy wrote: What you suggest does work, but I don't know the type of the generic class, only that it derives from IBusinessObjectBase
So when I try ...(customerFactory is IFactoryBase).... it fails.
Why not make IFactoryBase non-generic, and expose the non-generic properties/methods you need to access? Else create a non-generic IFactoryBaseBase interface
|
|
|
|
|
I have changed as you suggest, and it does work.
I still wonder why I can't do the generics thing - seems more elegant.
One for the back-burner maybe.
Thanks for your help.
|
|
|
|
|
Generics having full covariance is a common expectation, and I find the easiest way to explain it is to give a counter-example.
Say you have IBusinessObject< T > { IList< T > ListOfChildren; }.
So with our IBusinessObject< Customer > foo, we can .ListOfChildren and get a IList< Customer >.
Good so far.
Then if we could cast foo to IBusinessObject< object > - if we did .ListOfChildren we could have a IList< object >.
Still everything is peachy until we take that IList< object > and break type-safety by doing .Add(someRandomObject). We obviously can't actually Add any object to that IList, it must be a Customer. So IBusinessObject< object > is not an equivalent type.
IIRC the compiler can be nice to us and provides covariance in the case of a "read-only" generic type, identified by the type parameter being used for read-only properties, and return values only. IEnumerable< T > is probably one of these.
So in summary, IFactoryBase< Customer > cannot be cast to IFactoryBase< IBusinessObjectBase >, they are different types - it is specialized in dealing with Customers, not any IBusinessObjectBase. You might be able to get away with it if IFactoryBase< T > only uses T on the return side of it's members (like IEnumerable< T >), but I'm not sure if this behaviour is fully documented/guaranteed. (Check for me and reply? )
|
|
|
|
|
Thanks Mark.
The way of looking at it that sits well in my brain - I was seeing a generic type definition as two types: clear now that this is not the case.
You do learn something every day.
|
|
|
|
|
Hi,
I have developed a winform application which monitors files using FileSystemWatcher. This works fine.
Now I have to develop it in Windows service.
Can you see why the following line does not compile in windows service please?
//in winform I am using this which works fine...
_watcher.SynchronizingObject = this;
//this line does not compile in windows service. Please note I changed the word this to the service class name i.e. FileMonitor
_watcher.SynchronizingObject = FileMonitor;
The error is: FileMonitor.FileMonitor is a type but it's used as a variable.
|
|
|
|
|
arkiboys wrote: //in winform I am using this which works fine...
_watcher.SynchronizingObject = this;
//this line does not compile in windows service. Please note I changed the word this to the service class name i.e. FileMonitor
SynchronizingObject is not needed outside a WinForm project. It is simply there to prevent cross threaded calls. You can safely ignore that in a Window Service.
|
|
|
|
|
you need to assign the actual instantiated variable and not the class.
IE
FileMonitor FM = new FileMonitor();
_watcher.SynchronizingObject = fileMonitor;
Regards
Michael
|
|
|
|
|
I wanted to use the Regex.Split function to split an incoming string up. The problem is that the string parts are separated by a pipe | but the pipe is used inside the Split function to split different separators (e.g. if you want to split on dash and space you would write it as " |-" ). So when I use "|" the string splits into it's characters. I tried using "\|" but this is considered an Unrecognized Escape Character and doesn't compile.
Does anyone know if this is possible in another way?
|
|
|
|
|
You have to encode the characters in the expression twice. First you have to encode the pipe to put it in the regular expression, then you have to encode the regular expression to put it in a literal string in the code.
Use \\| in a regular literal string, or \| in an @ delimited string.
Example:
string pattern = "\\|";
or
string pattern = @"\|";
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks, that solved the problem
|
|
|
|
|
public string deleteDB(string strSelect)
{
try
{
cmd.Connection = objConn;
cmd.CommandText = strSelect;
cmd.ExecuteScalar();
}
catch (SqlException eException)
{
Console.Write("Error in connection : " + eException.Message);
return -10;
//return strSelect;
}
}
|
|
|
|
|
Well, did you read the error message ? Your function returns a string, and you're tring to return -10. Which is both stupid ( what does -10 mean ? ) and illegal ( an int is not a number ). The logical thing to return here is probably a bool. Why bother returning the string that was passed in ?
Where does strSelect come from ? This looks silly to me from the get go. You're just taking SQL as a string and calling it, this should not exist at all, but if it did, it should have a generic name, there is not guarentee it will delete anything.
There is so much wrong with this, you should probably go back to basics and do some reading. But, to fix the problem at hand, read your error messages and believe them. You said you were returning a string. The compiler won't turn an int to a string, so return a string, or change the return type. And, return something when the code doesn't blow up, too.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Christian Graus wrote: an int is not a number
You mean string
|
|
|
|
|
*sigh* yes, I did...
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
your trying to return an int in a method that needs to return a string... youl have to return "-10" in your catch block...
and use PRE tags when posting code please
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.passion != Programming)
|
|
|
|
|
-10 is a int not a string
|
|
|
|
|
Hello everyone,
I need some help here, maybe lots.
Want a quick way to upload images to tinypic dot com from within windows.
Its a free image hosting site. Hope I am not breaking any rules here by typing the site name.
I can think of doing this with right-click context menu.
I am a newbie in programming. This is what I have come up with so far.
Regedit : HKEY_CLASSES_ROOT\jpegfile\shell
Can add a KEY as "Upload to TinyPic". Right click "Upload to TinyPic" and add another key "command".
Right click any jpg/jpeg image file and you'll see the option "Upload to TinyPic" in the context menu.
Now what command to use so that whenever I click on that, the pic will get uploaded to the site and the uploaded site opens up showing the links or something like that.
A friend of mine told me, it can be done thru programming. So thats the reason, I am here. I don't know any programming, so give me codes and stuffs to do that. Just let me know something easy a normal person like me can use.
Kindly help me out.
Thanks a lot.
|
|
|
|
|
You're not in Kansas anymore. I recommend asking your friend to write this for you. No-one here is going to do it. Your command would be the path to the program you write to upload the files.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Maybe it uses ShellExt or something like that. My friend is not that of a programming expert as me, but we know some names, thats all.
Maybe you can do it for me. If thats not a BIG problem for you.
My guess is - this shouldn't be a big thing. Im asking for a favor
Thx
|
|
|
|
|
Sazarella wrote: My friend is not that of a programming expert as me, but we know some names, thats all.
OK, so you're both out of your depth ? If you're interested, why not do some reading and try to learn ?
Sazarella wrote: My guess is - this shouldn't be a big thing.
Well, first step is to find out if the site you're talking about even exposes a web service or other way to do what you want. Then, it's probably mostly trivial, but still more work than I can spare time for, sorry. I could easily answer 20 questions here in that time, and I don't really, strictly speaking, have time to even do that.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
"If you're interested, why not do some reading and try to learn ?"
Yeah! I am interested. Where to start from? Hope its not too hard to learn. And I can do what I am looking for.
"Well, first step is to find out if the site you're talking about even exposes a web service".
How to do that?
|
|
|
|
|
You go to the web site and look around for documentation for developers.
Then you need to buy a basic C# book, if that's the level you're at, and work through that so you have a basic idea how to create an app. Then you read up on the docs on how to interact with the site, and write something based on their samples. If they exist.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|