|
Hi,
I'm just wondering whether it is possible to force a class, which implements my Interface, to provide a specific ctor (say with an int parameter). If yes, how do write the interface then?
Is this possible or do I have to fall back on a baseclass model?
Thanks in advance.
Matthias
If eell I ,nust draw to your atenttion to het fakt that I can splel perfrectly well - i;ts my typeying that sukcs.
(Lounge/David Wulff)
www.emvoid.de
|
|
|
|
|
No, you can't force specific constructor, but you can force to have a method that returns an instance and create factory for it.
<br />
interface IFoo<br />
{<br />
... methods here...<br />
}<br />
<br />
interface IFooFactory<br />
{<br />
IFoo CreateIFoo(string a, int b);<br />
}<br />
<br />
public class MyFoo : IFoo<br />
{<br />
... methods from IFoo...<br />
public static IFooFactory factory = new MyFooFactory();<br />
<br />
}<br />
<br />
class MyFooFactory : IFooFactory<br />
{<br />
public IFoo CreateIFoo(string a, int b)<br />
{<br />
return new MyFoo(a, b);<br />
}<br />
}<br />
<br />
then to use it:<br />
IFoo foo = IFoo.factory.CreateIFoo("hello", 1);<br />
<br />
|
|
|
|
|
Thanks Werdna,
this is just what I needed.
Matthias
If eell I ,nust draw to your atenttion to het fakt that I can splel perfrectly well - i;ts my typeying that sukcs.
(Lounge/David Wulff)
www.emvoid.de
|
|
|
|
|
Interfaces cannot contain instance constructors. It seems to be a useful feature at first glance, but how would you implement separate interfaces which require a constructor with the same signature?
You could fake it by including an Init method declaration on your interface or use an abstract base class to force the matter.
Charlie
if(!curlies){ return; }
|
|
|
|
|
I am trying to read a file off a CD, I use this code:
FileStream oFileStream;
oFileStream = new FileStream( this.filename, FileMode.Open);
and the exception is that access is denied. My CD drive has no security settings, this is happening on all the files I try to read from CD. What could be wrong ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
You need to use a different version of the constructor.
Try this:
FileStream oFileStream;
oFileStream = new FileStream( this.filename, FileMode.Open, FileAccess.Read, FileShare.Read);
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
|
|
|
|
|
You are my hero, again. Thanks. Funny enough, the problem was in some code I found online ( to read ID3 tags ), and every other file read he did ( in different classes ) used this constructor.
As you may have guessed by the flurry of questions, my deadline is fast approaching. I'm cool with most of my project, but this parallel port access thing in particular has me worried enough that I'm starting to stress over everything...
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
From the .NET Framework SDK:The constructor is given read/write access to the file, and it is opened sharing Read access (that is, requests to open the file for writing by this or another process will fail until the FileStream object has been closed, but read attempts will succeed). The buffer size is set to the default size of 4096 bytes (4 KB). Since you can't simply write to a CD, the request to open the file with FileAccess.ReadWrite would fail. You must, therefore, use another constructor so that you can specify FileAccess.Read only.
Software Design Engineer
Developer Division Sustained Engineering, Microsoft
My Articles
|
|
|
|
|
Hey Everyone -
How can I go about monitoring the TCP packets going to and from my computer?
I have a client that connects to a server and can send data to the server, and I'm looking to use a second client to read the data being sent from the server to the first client (which the first client doesn't see). Is there a way for the second client to tap into the first's streams?
Thanks.
|
|
|
|
|
Checkiar this out http://www.mentalis.org/soft/projects/pmon/
/\ |_ E X E GG
|
|
|
|
|
|
Hi all,
I am trying to develop a stand-alone windows application using C# .NET that uses the Amazon.com web services. I added the WSDL to my project as a web reference, but now I'm having a little trouble figuring out how to send a search request. in the API, there is an ItemSearch object, and ItemSearchRequest object, and an ItemSearchResponse object - could anyone show me how to use these to search by a keyword, passed to my function as a parameter? I know how to do it using AWS 3.0, but I cant figure it out in 4.0. Any help would be much appreciated.
Thanks,
Justin
|
|
|
|
|
|
I'm working on an application that will use a custom input device, supplied by the client, which connects to the parallel port. They've given me a disagram which looks like this
25 Status 0 1 2 3
11 S7 ML H Men LF
15 S3 LB A/T PB A>>Z
13 S4 Z<
|
|
|
|
|
|
No, because I need to interact with the parallel port, not the serial port. Is there some way I can use that article to access the parallel port ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Sorry CG, I missed that part. If I see something I will let you know.
- Nick Parker My Blog | My Articles
|
|
|
|
|
Maybe this link will help:
Interfacing the Enhanced Parallel Port[^]
If I had to make a guess (without seeing an actual schematic of the device) - S3 probably corresponds to Base+3 which is an EPP address port and S4 probably corresponds to the EPP data port - so you have to send information S3 (the request) and then read informationfrom S4 (the response). I don't have a good guess about the other stuff
Steve
|
|
|
|
|
I have been trying to figure out the best way to run a script(any kind...vbscript, Jscipt, JavaScript..whatever works) inside a c# application. I've been looking at WSH, VBA, and script component stuff and can't seem to figure out how to use these and which one actually does what I want. I want to be able to send a parameter to a script method, like an integer, and have it return the parameter altered (multiply it by two). Just a proof of concept thing. Also, I don't want to use IIS, so ASP is out!
I'm new to .Net/C#/Windows programming, so this has not been easy for me!
Thanks for any help in advance!
-Johanna
|
|
|
|
|
|
There was a discussion on this yesterday. I suggest you browse through this forum or use the "Search comments" link above.
The scripting environment and the .NET Framework are two completely different things. Scripting revolves around OLE/COM Automation, while the .NET Framework revolves around the CLR (Common Language Runtime).
There articles on MSDN Online[^] and this web site. A good starting point is Interoperating with Unmanaged Code[^] in the .NET Framework SDK. Experience with COM development is very useful. There are also a few books available on COM interop with .NET that you can find on Amazon[^] I recommend you pick up, especially since you're new to Windows and .NET development.
This site - CodeProject - is also a useful resource but keep an eye on the article ratings. Just because someone posts an article doesn't make them an authority on the subject (true for everything else on the web).
Software Design Engineer
Developer Division Sustained Engineering, Microsoft
My Articles
|
|
|
|
|
Heath,
Okay, I think I found the discussion you were referring to - I had ran acrossed it before while searching for help on this subject before (I have done quite a bit of searching on both cp and msdn...i must be using the wrong code words...) I just had to read and re-read the article a bit to see how it applies...
This is now my understanding - I can interact in some way with scripted code using COM objects in some fashion (VSA? Windows Script Components?). I do understand there is a difference between COM and .Net, I just didn't find in my research that the scripting environment was a COM thing.
By following a link from the discussion you referred me to ( generating and compiling source code), I am now under the impression that as long as I write JScript code, i can compile and run my code using the System.CodeDom classes.
Please let me know if I am right about this!
Thanks for your help, I do appreciate it.
-Johanna
|
|
|
|
|
johanna42 wrote:
By following a link from the discussion you referred me to ( generating and compiling source code), I am now under the impression that as long as I write JScript code, i can compile and run my code using the System.CodeDom classes.
Any language targeting the .NET Framework can access the System.ComDom namespace (assuming it's running on Windows), however what you need to understand is that you can't write an assembly in C# and then simply write a VBScript file where you can call CreateObject and use your C# classes within the VBScript. There are ways to generate MSIL at runtime and invoke them; however again, this is entirely different than OLE Automation's mechanism for late bound objects in VB/VBScript.
- Nick Parker My Blog | My Articles
|
|
|
|
|
Nick Parker wrote:
what you need to understand is that you can't write an assembly in C# and then simply write a VBScript file where you can call CreateObject and use your C# classes within the VBScript.
Maybe I'm not making myself clear. I don't want to access my C# code from VBScript, I want to do the opposite. I want to invoke a method in my VBScript from inside my C# code. I'm not trying to create a com object to run my .Net stuff, I know better than that!
I have seen examples on msdn (using Windows Scripting host setting up your script to be read as a COM object, using VSA by attempting to compile and run a script, trying to figure out how to pull in WSH into my code) but I can't figure out which of these ways are valid, reasonable solutions(or if none of them are).
I guess what I was trying to say is if I used JScript as my scripting language (which runs on CLR as far as I know), then I can use the .Net namespace System.CodeDom (inside my c# code)in order to run the script. Is that correct?
Also, if I am attempting to read VBScript or some other scripting language, then I assume I have to use some other non-.Net scripting engine in order to compile and read the script. From what I understand of the past e-mails, this engine may only exist in COM terms and I will need to understand how to use com objects with .Net stuff.
If this is all wrong, please let me know!
thanks,
Johanna
|
|
|
|
|
Dear Johanna,
adding scripting capabilities to .NET programs is, indeed, possible.
There was an article on that subject in a german .NET magazine some time ago. Here's the link to a sample project (comments in german, though):
Scripting .NET
The sample shows how to set up a scripting host in your program, make objects available to scripts and how to load and execute JScript scripts to modify your application's behaviour.
If you have problems with understanding the code or comments, then drop me a line, I'll translate.
Regards,
mav
|
|
|
|