|
Using properties instead of string vars seems sensible to me. Unfortunately it could be tricky, this class is being XML Serialised/Deserialed as part of a Web Service method. I'll have to do some experimentation.
Although IEnumerable is a nice idea I think it's a little over-kill for this class, it's just a simple way for me to hold data supplied by a Web Service consumer. The processing is simply Trim()ing the strings, and setting them to null if they're empty, prior to storing them in a database.
Thanks for the help Jim, I'll keep you informed on my progress....
Pete
|
|
|
|
|
May I suggest then moving the string manipulation code into the class and scrubbing the enumeration idea. The Get property methods could perform this process.
α.γεεκ Fortune passes everywhere. Duke Leto Atreides
|
|
|
|
|
Hmm, yeah that seems sensible.
I'd still like to have the array though, as I may add more string members at a later stage and I like the idea that this would only break one bit of code...
|
|
|
|
|
Hmm,
Well I've encountered my first problem - compiler error CS0206: A property or indexer may not be passed as an out or ref parameter
Some of the methods that work on the member strings need a ref string parameter, so that they can modify the actual string rather than a copy.
I think I should be able to design my way around this though...
|
|
|
|
|
OK, that's fixed.
I'm very impressed that changing the members to properties had no effect on the XML Serialisation (at least, none that I can tell - all my tests still run 100%).
So it should be pretty simple now to move the processing functionality into the class (actually i'll probably make a generic DataInterface class that Trim()s it's string members and inherit from that).
Thanks for the help!
|
|
|
|
|
moredip wrote:
I'd like to be able to add references to these strings to a member string[] variable, so that I can perform operations on all of them at once with a foreach loop:
Let the class implement IEnumerable. Arged wrote all the code, it doesnt work!!!
New option HashTable make those fields rather properties referencing objects in a hashtable with the method name as the key. Use reflection to get /set the value.
MyDUMeter: a .NET DUMeter clone "Thats like saying "hahahaha he doesnt know the difference between a cyberneticradioactivenuclothermolopticdimswitch and a biocontainingspherogramotron", but with words you have really never heard of."
|
|
|
|
|
Again, although those are both sensible ideas, they are a bit heavy-weight for my little class. I don't really need that much functionality, at least not right now.
Being a lazy developer I like to do the least amount of work possible
|
|
|
|
|
moredip wrote:
they are a bit heavy-weight for my little class
Not heavy at all, you can provided a base class that does the enumeration, indexing etc, all via reflection. Meaning every single class have this behaviour. If this is something in SQL your are doing, I have some neat code.
moredip wrote:
Being a lazy developer I like to do the least amount of work possible
You are obviously not "economizing" (my personal word for laziness) enough. I have used the same approach to make persistant object classes. All hidden to the user. Have a look at my DBHelper article for real "lean" code. Its astonishing what can be done with so little (or just putting the pieces correctly in place).
Cheers
MyDUMeter: a .NET DUMeter clone "Thats like saying "hahahaha he doesnt know the difference between a cyberneticradioactivenuclothermolopticdimswitch and a biocontainingspherogramotron", but with words you have really never heard of."
|
|
|
|
|
Just had a look at your article, that's a nice tool. It's not really needed for what I'm doing (trying to avoid SPs), but thanks anyway.
When I said 'heavy-weight' I was kind of referring to functionality that was superfluous, rather than a lot of extra coding - although that was a factor
The classes I'm talking about are really just a handy way for me to exchange data with consumers without having to mess with DataSets, and I want to keep them as simple as possible (KISS).
Again, thanks for the help,
Pete
|
|
|
|
|
moredip wrote:
The classes I'm talking about are really just a handy way for me to exchange data with consumers without having to mess with DataSets, and I want to keep them as simple as possible (KISS).
In that case, why not just make a wrapper class to handle those "extra" functions?
MyDUMeter: a .NET DUMeter clone "Thats like saying "hahahaha he doesnt know the difference between a cyberneticradioactivenuclothermolopticdimswitch and a biocontainingspherogramotron", but with words you have really never heard of."
|
|
|
|
|
That's pretty much what this class is, a wrapper around the raw data. It does just enough for my purposes - which at the moment is just some simple pre-processing of supplied strings.
|
|
|
|
|
I'm trying to complete Chris Maunder's article for creating "your first web service" http://codeproject.com/cs/webservices/myservice.asp and am having a few problems. I've got visual studio.net installed but I don't have the option of creating a C# web service from the new project menu. The options I do have are as follows: Windows App, Class Library, Windows Control Library, ASP.Net Web App, ASP.Net Web Servce, Web Control Library, Console App, Windows Service, Empty Project, Empty Web Project, and New Project in Existing Folder. Is there something I can do to add or turn on the options I'm missing to be able to create a C# web service?
Thanks, Doug
|
|
|
|
|
Manster wrote:
ASP.Net Web Servce
that is the one, if you want to create web service, the default options spits the code for a 'hello world' web service, its commented by default.
If you are thinking about consuming webservice, you will have to add a web-reference (right click on the web reference tab and add the url for the web service you want to consume).
Hope this helps.
Cheers
Kannan
|
|
|
|
|
Is there an alternative way to create shortcuts in C# other than using the Wshell? Because everytime i include my app and distribute it to others, some people don't have the wscript.exe and even if they DID install it, they get this kind of error : "IWshShell3 failed". Are there any workarounds to this?
|
|
|
|
|
You can use the COM ShellLinkObject to create shortcuts, and this only requires shell32.dll.
In an ideal world, things would be simple and you would just have to add a reference to shell32 in the VS.NET IDE, then start playing with the objects and interfaces.
Unfortunately, the actual IShellLink interface is not declared in the shell32 namespace. You'll find ShellLinkObject and ShellLinkObjectClass but they are worthless.
That's somewhat tough since you have to do the interop yourself, ie declare COM signatures. Here is how it goes :
[ComImport, Guid("00021401-0000-0000-C000-000000000046")]
class ShellLink
{
}
[Guid("000214ee-0000-0000-c000-000000000046"),
InterfaceType(ComInterfaceType.InterfaceIsDual)]
interface IShellLinkA
{
void SetPath(string path);
void SetDescription(string path);
void Save(string where);
...
}
ShellLink c = new ShellLink();
IShellLinkA i = (IShellLinkA) c;
i.SetPath("ert");
...
That's just the begin of the code.
Be sure to read this reference MS article[^] (WIN32 C/C++ audience though).
|
|
|
|
|
i put in this :
[ComImport, Guid("00021401-0000-0000-C000-000000000046")]
class ShellLink
{
}
[Guid("000214ee-0000-0000-c000-000000000046"),
InterfaceType(ComInterfaceType.InterfaceIsDual)]
interface IShellLinkA // Cannot list any base interfaces here
{
void SetPath(string path);
void SetDescription(string path);
void SetIconLocation(string path, int index);
void Save(string where);
void SetWorkingDirectory(string path);
}
and called this:
ShellLink c = new ShellLink();
IShellLinkA i = (IShellLinkA) c;
i.SetPath(@"c:\test.txt");
i.Save(@"c:\test.lnk");
but it doesn't work (the shortcut doesn't appear). And i don't quite understand some of the stuff/code on the link you gave me (mainly because it's in C/C++). Any help would be greatly appreciated.
|
|
|
|
|
In my code snippet, IShellLink was declared as a dual interface, although, after I have double checked it, it's only a IUnknown interface.
Here is the right declaration and code :
[ComImport, Guid("00021401-0000-0000-C000-000000000046")]
class SH
{
}
[Guid("000214ee-0000-0000-c000-000000000046"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IShellLinkA
{
void GetPath(string pszFile,
int cchMaxPath,
IntPtr pfd,
int fFlags);
void GetIDList(IntPtr ppidl);
void SetIDList(IntPtr pidl);
void GetDescription(string pszName,
int cchMaxName);
void SetDescription(string pszName);
void GetWorkingDirectory(string pszDir,
int cchMaxPath);
void SetWorkingDirectory(string pszDir);
void GetArguments(string pszArgs, int cchMaxPath);
void SetArguments(string pszArgs);
IntPtr GetHotkey();
void SetHotkey(int wHotkey);
void Resolve(IntPtr hwnd,
int fFlags);
void SetPath(string pszFile);
}
SH c = new SH();
IShellLinkA i = (IShellLinkA) c;
...
UCOMIPersistFile p = (UCOMIPersistFile) i;
p.Save(@"c:\mylink.lnk",false);
|
|
|
|
|
Hi all
I need to pass a pointer to the a function that uses fread to read a file in memory. Unfortunaly MS decided to make the __UnmanagedMemoryStream internal. So now what I have done is to read all the data from a Stream object to a byte[]. Then pin it with a GCHandle and passing that pointer, freeing it after use. Now this works all nice and well, but I cant help to feel "duplication" occurs making this method rather inefficient for large files.
Any suggestions?
PS: from __UnmanagedMemoryStream I can get a GetBytePtr() value (via reading field value via reflection) which is exactly what I need (but this stream is only exposed via Assembly.GetManifestResourceStream). Damn you MS. I want this class!!!!!
MyDUMeter: a .NET DUMeter clone "Thats like saying "hahahaha he doesnt know the difference between a cyberneticradioactivenuclothermolopticdimswitch and a biocontainingspherogramotron", but with words you have really never heard of."
|
|
|
|
|
Hi all
SO I read this:
Content - The file is not compiled, but is included in the Content output group. For example, this setting is the default value for an .htm or other kind of Web file.
So now I have a assemblyname.dll.config file set as content, but its not outputted to the "output" directory.
Any suggestions?
MyDUMeter: a .NET DUMeter clone "Thats like saying "hahahaha he doesnt know the difference between a cyberneticradioactivenuclothermolopticdimswitch and a biocontainingspherogramotron", but with words you have really never heard of."
|
|
|
|
|
Hello,
As you might know CodeGuru is an excellent web site were tones of controls and software in general is posted for free.
For historical reasons the big majority of contributions are witten for MFC (VC 6.0), ATL, and alikes. If you surf it you'll colud find very valuable pieces of software.
Most of them come in files .h and .cpp that integrate smoothly whith an MFC app.
I would like to ask a question: Somebody knows a way or has tried to reuse this software from NET and C# using interop?
Thanks,
Josep L Colom
|
|
|
|
|
Basically most content from Cg and Cp don't expose (export) anything. They are classes to be added to your MFC-based VC++ projects. So that's a bit weird of a question.
With C#, I can't really figure out what you could do out of most "MFC controls" code in Cg and Cp, since interop only allows you to import dll functions, not classes. (I don't know if this has been improved with VS.NET 2K3).
With MC++, things get somewhat better. Watch out this article[^] (registration required).
That said, MFC has its use in his context ("old" C++), and Windows Forms is simply the de facto .NET UI framework to use.
|
|
|
|
|
One way to reuse I taught was (if possible, but I don't know how) to convert those .h/.cpp clas(ses) to an ActiveX control. May be creating a new MFC ActiveX DLL project, and then, through interop to access this ActiveX (COM object).
But may be I'm saying a nonsense thing..
|
|
|
|
|
Josep L Colom wrote:
One way to reuse I taught was (if possible, but I don't know how) to convert those .h/.cpp clas(ses) to an ActiveX control. May be creating a new MFC ActiveX DLL project, and then, through interop to access this ActiveX (COM object).
Although that's true in theory, since ActiveX type libraries can be imported in the .NET world, I believe you should engage this way only as last option. Reasons are :
- the marshaler (type library importer) has a few bugs, and as a consequence it's likely you have issues when calling exposed interfaces.
- you have to build the ActiveX first, which means you have to provide implementation for IOleClientSite and some other containers as well. Got my point ? You'll end drop dead before you get a simple MFC owner drawn derived control, working fine in the .NET world.
|
|
|
|
|
I though how it was really cool how I was able to just slap togeather a regular c# program in vs and just build it into an .aspx webpage with iis...
but all the sudden when ever I build my page and the browser comes up I can't see the forms or anything on my pages...
APS.NET is really cool and it's even cooler that I can make pages in C#...
What is wrong can somebody help a kid out?
/\ |_ E X E GG
|
|
|
|
|
There are many limitations for hosting form controls in IE. Odds are, you need to modify the programs permissions. Just run mscorcfg.msc and configure the assembly.
Hope it helps, else give more info.
MyDUMeter: a .NET DUMeter clone "Thats like saying "hahahaha he doesnt know the difference between a cyberneticradioactivenuclothermolopticdimswitch and a biocontainingspherogramotron", but with words you have really never heard of."
|
|
|
|