|
It does seem like its impossible, but it isn't (thankfully)
C# (and .NET) supports the ability to specify which methods/properties should be used to implement an interface.
To do so, precede the method/property name with the name of the interface and drop the visibility modifier (because interface methods must always be public).
In your case...
public MyType this[int index] {
get { return (MyType)this.myArrayList[index]; }
set { return this.myArrayList[index] = value; }
}
object IList.this[int index] {
get { return this.myArrayList[index]; }
set { return this.myArrayList[index] = value; }
} As an aside, if you're using an ArrayList for the underlying implementation why not inherit from CollectionBase and not have to worry about implementing IList, ICollection, etc. You just need to worry about the typesafe methods for your collection.
James
- out of order -
|
|
|
|
|
Thank you very much! This works great!
James T. Johnson wrote:
As an aside, if you're using an ArrayList for the underlying implementation why not inherit from CollectionBase and not have to worry about implementing IList, ICollection, etc. You just need to worry about the typesafe methods for your collection.
Right... I knew that... really
Methinks my lack of FCL knowledge has made me do a lot more work than I meant to. Thanks for this as well!
-Domenic Denicola- [CPUA 0x1337]
“I was born human. But this was an accident of fate—a condition merely of time and place. I believe it's something we have the power to change…”
|
|
|
|
|
Domenic [Geekn] wrote:
Methinks my lack of FCL knowledge has made me do a lot more work than I meant to.
You are better off for it though Now you know that it exists and you also learned how you can implement IList in a strongly-typed collection.
James
- out of order -
|
|
|
|
|
Wow James, you never fail to amaze me
"I dont have a life, I have a program." Also, I won't support any software without the LeppieRules variable.
|
|
|
|
|
Ditto here. My only problem was when he said this:
It does seem like its impossible, but it isn't (thankfully)
He didn't use the emoticon! He should have put the extra dash in there. Seriously James, you're an editor! I am really disappointed.
I don't know whether it's just the light but I swear the database server gives me dirty looks everytime I wander past.
-Chris Maunder
Microsoft has reinvented the wheel, this time they made it round.
-Peterchen on VS.NET
|
|
|
|
|
David Stone wrote:
He should have put the extra dash in there.
I've gotten too used to Trillian's emoticons, I'll go hang my head in shame now.
James
- out of order -
|
|
|
|
|
It's okay James. I forgive you. Now go make a pilgrimage to the shrine of and sacrifice a Mac on the altar.
I don't know whether it's just the light but I swear the database server gives me dirty looks everytime I wander past.
-Chris Maunder
Microsoft has reinvented the wheel, this time they made it round.
-Peterchen on VS.NET
|
|
|
|
|
Dear Masters of .NET,
Does anyone have proper sample or documentation about
creating a custom forms designer like VS.NET's or SharpDevelop's designer.
I have search the NET for quite a while, but no success.
I also dug the SharpDevelop's code and found that without documentation it
is very hard to see what the developers have done.
Any help is welcome and appreciated.
C:\>csc *.cs
Microsoft (R) Visual C# .NET Compiler
error CS2001: Source file 'brains.cs' could not be found
fatal error CS2008: No [brains.cs] specified
C:\>
|
|
|
|
|
This is a complicated task, and understanding the SharpDevelope code isn't an unreasonable way to begin your task.
If, on the other hand, you are not actually trying to duplicate all of the functionality, (maybe you only want labels, text boxes, and buttons on your forms), you could try simply writing the thing from scratch in a way that seems logical to you. This method requires using the container form's .Capture property in order to catch the clicks that normally would have set the focus to the child control, allowing you to select and move the controls.
John :D
|
|
|
|
|
Since it's really easy to access resources and modify them in .net, what do people think about storing application configs inside of the .exe itself (maybe storing the first date the program was ran inside of the executable itself, granted it's easy to modify, but I'm sure other methods will be used as well). Anybody have any thoughts on this? good idea? bad idea? I just think it might be nice to have an executable with no attachment to the registry and no other required files (sans runtimes).
|
|
|
|
|
To my opinion the general purpose of such configuration file is the ability
to manipulating an application’s behavior whenever necessary.
I am not sure if you could modify a .NET exe/dll file without reconstructing.
Perhaps it is possible to use Soap/Binary Serialization in combination with PropertyGrid and a command line argument to do the trick. This way you create a “PropertyGrid enabled” class that holds the configuration, then you Serialize and/or DeSerialize the class when the application starts with a startup argument like /conf
Any way, this is my opinion.
C:\>csc *.cs
Microsoft (R) Visual C# .NET Compiler
error CS2001: Source file 'brains.cs' could not be found
fatal error CS2008: No [brains.cs] specified
C:\>
|
|
|
|
|
Okay, I am unable to find all the info on this.
We are creating dynamic C# code with the assembly files and project file.
I want to pass the project to the C# compiler programmatically.
What are the steps I need to take to accomplish this?
I am at a loss as to even where to start! I'd be happy if someone can even just point me to a tutorial on this!
Thanks much fellow CP'ers.
_____________________________________________
The world is a dangerous place. Not because of those that do evil, but because of those who look on and do nothing.
|
|
|
|
|
System.CodeDom.Compiler & System.Reflection.Emit
Its hard, very hard to understand, but once u grasp it, its pretty easy. Look on dotnet247
"I dont have a life, I have a program." Also, I won't support any software without the LeppieRules variable.
|
|
|
|
|
Thanks for the input.
Once I get it all figured out....it sounds like a good article to publish!
Gee...I might actually get published here.
_____________________________________________
The world is a dangerous place. Not because of those that do evil, but because of those who look on and do nothing.
|
|
|
|
|
C# also has a managed compiler, but I havent used that yet.
Microsoft.CSharp.Compiler class
"I dont have a life, I have a program." Also, I won't support any software without the LeppieRules variable.
|
|
|
|
|
Leppie,
First of all: I have implemented LeppieRules in all of my own system variables, so I feel fine in asking this.
I have the managed compiler functioning and I am 90% of the way there. It seems like you know more about reflection than I do at the moment so I was hoping you can help with this.
What I want to do is build a collection of each DLL that is to be included as references for my compiled code. I also want to make it version independant. So I thought that I could use Reflection to say "Here is the name space System" -or- "Here is the dll System.dll" then have Reflection give me that path construct to get to the System.dll location. I think this is possible via Reflection, but I keep getting lost in it when I try to find the component that can give me this answer.
Any suggestions on where to begin my easter egg hunt?
Thanks a heap,
Condor
_____________________________________________
The world is a dangerous place. Not because of those that do evil, but because of those who look on and do nothing.
|
|
|
|
|
theRealCondor wrote:
First of all: I have implemented LeppieRules in all of my own system variables, so I feel fine in asking this.
You are using it wrong!
OK, over to the series stuff!
theRealCondor wrote:
What I want to do is build a collection of each DLL that is to be included as references for my compiled code. I also want to make it version independant. So I thought that I could use Reflection to say "Here is the name space System" -or- "Here is the dll System.dll" then have Reflection give me that path construct to get to the System.dll location. I think this is possible via Reflection, but I keep getting lost in it when I try to find the component that can give me this answer.
Any suggestions on where to begin my easter egg hunt?
Start looking for an egg and not a bunny! What on earth are you trying to do? Reflection can only be used on compiled assemblies. Need more info, BUFFERUNDERUN EXCEPTION HALT!
PS: give me a code snippet of what you are trying to get
DBHelper - SQL Stored Procedure Wrapper & Typed DataSet Generator for .NET low popularity, please visit
|
|
|
|
|
leppie wrote:
What on earth are you trying to do?
Michael wryly smiles as he slowly types out the answer:
Okay...what I am trying to do is build a list of project references to make my code compile correctly from the instance of the managed C# compiler. The references are to system.dll, system.data.dll, and system.xml.dll. (Maybe you begin to see a hint of potential problems here)
Now I can take the obviously simplistic approach which is to build a string array with hard coded directory locations for each dll. But that thought makes me want to stick my finger down my throat. It also locks my code into version 1.0.3705 of the framework. (part of the directory structure name) It would also lock me into either a machine with C:\WINNT or C:\WINDOWS as the system directory name for locating system.dll.
So the obvious next step is to get very generic by having my code say " Where is the assembly for System? " " Where is the assembly for System.XML?" or even " Where is the assembly for system.dll?". That way if my wizard runs on a machine with 1.0.3705 it will find the current version of system.dll compile the code correctly, AND when someone runs my wizard on a machine with 1.1.0000 then it too will find the current version of system.dll and compile correctly as well!!!!!
whew --- so that is the off-the-wall thing I am trying to do. End result is so cool you would not believe it.
We take a complex XML file, build a compressed schema of the file, run that through a SchemaToXML transform (our developed transform) that expresses all parts of the XML file as objects, then we do three transforms to create object.cs, reader.cs, and writer.cs. The final step is those three files get compiled into a dll and VOILA --- you now have an object model representation of that complex XML file for locating data, reading data, and updating data. In our case, that complex XML file is a fully externalized set of business rules that control parts of our application code. From a coders' viewpoint, accessing that xml file is no different that doing a "SELECT where TYPE = 'funky'" and getting back a collection of entries from the XML file that matches that type.
I'm writing the wizard that makes that whole build process an automated generation for any XML file fed to it, complete to the compiled DLL.
That is as long as I can systematically get the path name of the three system DLL's. I also tried exploring the File object to see if it exposed a FindFile method but that did not pan out either. I keep coming back to reflection, since it is dealing with known DLL's and it should be able to provide me with the assembly information that includes pathname. (After all, the assembly info when you Create Reference includes the full pathname!!!)
<publicnameexposed> Michael
Thanks for ANY help you can provide!
Condor
_____________________________________________
The world is a dangerous place. Not because of those that do evil, but because of those who look on and do nothing.
|
|
|
|
|
theRealCondor wrote:
That is as long as I can systematically get the path name of the three system DLL's. I also tried exploring the File object to see if it exposed a FindFile method but that did not pan out either. I keep coming back to reflection, since it is dealing with known DLL's and it should be able to provide me with the assembly information that includes pathname. (After all, the assembly info when you Create Reference includes the full pathname!!!)
I would suggest using CodeDom 's compilers instead. Like this:
CompilerParameters pars = new CompilerParameters();
pars.ReferencedAssemblies.Add("System.dll");
pars.ReferencedAssemblies.Add("System.Data.dll");
pars.ReferencedAssemblies.Add("System.Xml.dll");
CompilerResults res = new Microsoft.CSharp.CSharpCodeProvider().CreateCompiler().CompileAssemblyFromFileBatch(
pars, new String[]{"one.cs","two.cs","three.cs"});
Now you have a ReferencedAssemblies collection, also I STILL dont understand why you wanna do this. AFAIK your assembly can ONLY use the framework version its been built on or newer (why would you ever want to use something older if you have something newer? Answer: dont install newer framework then!).
theRealCondor wrote:
That way if my wizard runs on a machine with 1.0.3705 it will find the current version of system.dll compile the code correctly, AND when someone runs my wizard on a machine with 1.1.0000 then it too will find the current version of system.dll and compile correctly as well!!!!!
As above, this will be (AFAIK) the default behaviour. I have used my above method without having to specify a path to it....with NO problems.
Hope this helps
DBHelper - SQL Stored Procedure Wrapper & Typed DataSet Generator for .NET popularity better now, thank you
|
|
|
|
|
Thanks. I am using the CodeDOM compiler....in my version of the Framework it is called the C# Managed Compiler.
So close and so far. I was looking at the ReferencedAssemblies but it shows it taking a string[] value that I assumed I had to build by hand. I never looked beyond it to see that it had an Add method. I put it together as you suggested and it works just great.
I think you misunderstood me, I DO want to most current version...I did not want an older version and I do not want to be locked into any given version. I also was unaware of the fact that providing just a dll name like that would actually find the dll.
Thanks much it helped tremendously. I now have a dll in my bin directory!!!
_____________________________________________
The world is a dangerous place. Not because of those that do evil, but because of those who look on and do nothing.
|
|
|
|
|
Quote from above:Thanks. I am using the CodeDOM compiler....in my version of the Framework it is called the C# Managed Compiler.
There are to 2 different ways to compile. Either like you have done, or the way I have shown above. I prefer my way as you can emit generated code as well.
DBHelper - SQL Stored Procedure Wrapper & Typed DataSet Generator for .NET popularity better now, thank you
|
|
|
|
|
leppie wrote:
DBHelper - SQL Stored Procedure Wrapper & Typed DataSet Generator for .NET
Heh Heh --- so great minds think alike! Your wrapper process looks like the SQL Server version of what I'm building for XML files.
Once again, I must implement the method call:
developer.LeppieRules
_____________________________________________
The world is a dangerous place. Not because of those that do evil, but because of those who look on and do nothing.
|
|
|
|
|
Hi all,
Here's a quick question that has been bugging me for a while.
All I want to do is implement a ReplaceColor function for a given bitmap. I have written a simple version in GDI+ using ImageAttributes, ColorMap and Graphics.DrawImage, which works ok. It replaces a given rgb value with a new rgb value.
What I really want to do is include a threshold value. For example, if I had a bitmap of a red square gradient from red (255, 0, 0) to white (255, 255, 255). If the theshold value was high enough and the find colour was red (255, 0, 0) and the replace color was blue (0, 0, 255). The result would be a blue square gradient from blue (0, 0, 255) to white (255, 255, 255).
Any ideas? Is there a built in GDI+ method for doing this or would I need to write my own? I've seen the SetThreshold method of ImageAttributes, can I use this?
Thanks in advance
Andy
|
|
|
|
|
I dont think this is possible to do.
Just because the image is gradient of red and white, doesnt mean that only two colors are used. There can be many more (off white, light pink, dark pink...etc)
|
|
|
|
|
how can I realize a simple syntax highlightning richTextBox?
thanks
|
|
|
|