|
After doing further research I was able to get it working. The working code is as follows:
if (predicateTable["CollectionNumber"].ToString() != "0")
db.AddInParameter(cmd, "pCollection_Number", DbType.Int32, Convert.ToInt32(predicateTable["CollectionNumber"]));
else
db.AddInParameter(cmd, "pCollection_Number", DbType.Int32, DBNull.Value);
Thanks,
Steve
|
|
|
|
|
It occurs to me that for a library that supports .net 2 to include support for Extension Methods when compiled with later versions, I should use something like:
public static SomeType
SomeMethod
(
# if SomeConstant
this
# endif
SomeType Param
)
{
...
}
But is there a built-in constant to do that? I could easily define one myself, but it wouldn't be standard.
For command-line builds I can easily add a define to C:\WINDOWS\Microsoft.NET\Framework\v3.5\csc.rsp,
but that doesn't help with Visual Studio builds. I can add the define to the project properties, but I'd have to add it to each project that might contain Extension Methods, and remove it if I have to switch the target framework back to 2 (for whatever reason).
Does anyone else have a way of dealing with this issue?
Is there simply a better/more-standard way of doing this already?
|
|
|
|
|
Unfortunately there really aren't any built in conditional symbols like you are looking for. The best/only option is to define a symbol yourself.
If you are compiling using VS2008 and the multi-framework targeting features, check out this blog post[^] by Daniel Moth. He shows how to get extension methods to work in .NET 2.0. You would still need to define your own symbol, but you would only need to have it in one place (around the .NET 2.0 extension attribute class).
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
Well, I knew about the Attribute, and I really wish they had simply allowed the use of it to decorate methods directly rather than mangling the language, but they didn't ask me. And there are other things I don't like about Extension Methods, but that's just me.
Anyway, I copied his Attribute to my library, and it compiled in VS 2008!
At the command-line, using the V3.5 CSC.EXE, I got
warning CS1685: The predefined type 'System.Runtime.CompilerServices.ExtensionAttribute' is defined in multiple assemblies in the global alias; using definition from 'c:\Projects\PIEBALD\Attributes\ExtensionAttribute.cs'
as expected.
But the V2.0 CSC.EXE doesn't like the this syntax, likewise as expected.
So that's no solution.
|
|
|
|
|
Right, the .NET 2.0 compiler won't like the syntax. You will need to use the .NET 3.5 compiler but target the projects to the 2.0 Framework.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
Scott Dorman wrote: .NET 3.5 compiler
I think I'd call that the C# 3.0 compiler.
|
|
|
|
|
PIEBALDconsult wrote: I think I'd call that the C# 3.0 compiler.
Yes...I was thinking about MSBuild, which in .NET 3.5 is marked as version 3.5. It's still the C# 3.0 compiler. Aren't these version numbers great?
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
How about running the C# file through the C++ preprocessor before build?
Somewhere in the SVN of xacc.ide I have a wrapper for 'cl -E' to process C# files (takes care of #regions). Maybe that will be of help.
I see no reason why you should not use the C# 3.0 compiler to target .NET 2, however
|
|
|
|
|
leppie wrote: through the C++ preprocessor
I already do that, at least for command-line builds, but only to prove that I can.
"C:\Program files\mingw\bin\cpp" -include "C:\Projects\PIEBALD\Defines.hs" -P -C -w %1.cs %1.csi
csc.exe @"C:\batfiles\Build.rsp" %1.csi
(Some details removed.)
And, yeah, it won't work if the file contains directives it doesn't understand.
However, this is based on how I dealt with directives when pre-processing embedded Oracle and RDB in C.
leppie wrote: I see no reason
I'm thinking of people who are stuck with VS2005.
Oh, and I did finally read up on xacc.ide and downloaded it, but that's as far as I've gotten so far.
|
|
|
|
|
Oh, and it's not entirely for how I build, but if/when I write a method to post here I may choose to write it as an Extension Method for the users who use them, but not have it break for the users who are using .net 2.
If I can, I should; if I can't, then I'll leave it out.
|
|
|
|
|
Ahh...that makes sense I suppose. I don't think I would worry too much about it, personally, but that's just me.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
Running Vista (without SP1)
Working in VS2005
I am streaming a large file (a 900mb FLV movie) over localhost, but just past the halfway, the program throws this exception:
The specified network name is no longer available at System.Net.HttpResponseStream.Write(Byte[] buffer, Int32 offset, Int32 size)
We've tried the program on 5 machines (both XP and Vista), and it works on everybody's but mine.
Does anyone know why and/or have a solution?
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
I am not sure but, when you open any webpages on local machine, at first time windows will ask you to "Enable Intranet Settings" for better performance on information bar. check that settings. may be its blocking larg file streaming.
|
|
|
|
|
I'm not using IE as my default browser.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
John Simmons / outlaw programmer wrote: or have a solution?
Steal one of the machines it works on.
led mike
|
|
|
|
|
John Simmons / outlaw programmer wrote: Does anyone know why and/or have a solution?
Anti virus, firewall? Maybe the firewall kicks in at some threshold?
Dodgy network drivers?
|
|
|
|
|
Well, I noticed that it happened in at the same spot in the file *every time*. So, I tried two other files and it worked like a champ. I suggested that we re-encode the defective file and see if that helps.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Have a look in the eventlog, make it's a bad area on the disk?
|
|
|
|
|
I chose to slow down the speed at which we were streaming the file. That seems to have worked.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hello,
I am writing a program that sends mail and let the user mange his mail locally in his computer.The second requirement is a little hard how can I use the IMAP protocol to connect to the remote mail server and download the mail like outlook using C#.
Thanks.
Dad
|
|
|
|
|
There are some articles on POP3 and IMAP available, for instance check out this one[^].
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi,
How to run a DTSx package in the .NET framework 2.0 using com object
Thanks in Advance
Regards & Thanks,
Paresh
Paresh Gujararathi
modified on Thursday, July 10, 2008 8:37 AM
|
|
|
|
|
I am just starting my adventure with test driven development (thanks to ASP.NET MVC!) and have a concern, I need to clarify something.
I have an interface like this...
public interface IUserRepository
{
IUser FetchByID(int userID);
}
and a class which implements that interface:
public class UserRepository : IUserRepository
{
public IUser FetchByID(int userID)
{
User user = null;
return user;
}
}
I want to test the FetchByID() method. I can mock IUserRepository and return a dummy User object, which is fine and works well. But this means the concrete class (UserRepository ) is never tested, so even if I didn't implement that class whatsoever, or I had throw new NotImplementedException() in that method the unit test would still pass since it's using a mock object. I thought you don't want to hit the database (or other external resources) while running your tests and that's the main reason to use mock objects, but that way you never can tell if you implemented that class correctly (or at all!). My colleague told me that when I'm testing that method I should use the concrete class and actually hit the database, and that I should mock IUserRepository only when it's needed in other tests (which are not testing FetchByID() but need data from it). Is that the correct approach?
If so, then my tests will get slower and rely on whether the test DB was properly setup, etc. Perhaps such tests should be placed in a separate project (integration tests)?
|
|
|
|
|
Pawel Krakowiak wrote: I thought you don't want to hit the database (or other external resources) while running your tests and that's the main reason to use mock objects
The concept is; "Each test should be isolated". AFAIK, the way you are testing "FetchById " is not correct. When you are testing FetchById , mocking IUserRepository won't make any sense. You will always get the expected "IUser" instance and as you said, it is not testing the real method. You have to mock only items that are nondeterministic in behaviour.
Pawel Krakowiak wrote: My colleague told me that when I'm testing that method I should use the concrete class and actually hit the database, and that I should mock IUserRepository only when it's needed in other tests (which are not testing FetchByID() but need data from it). Is that the correct approach?
Not exactly. As I said earlier, tests should be isolated. So if you are hitting database for each time, or the database you are using is a shared one, the test which executed successfully one time won't get executed next time as the data in database might have changed. So if you are not testing databases, mock/stub the data access which will help to get the test running quickly.
Consider the modified code
public class UserRepository : IUserRepository
{
IUserDataContainer container;
public UserRepository(IUserDataContainer container)
{
this.container = container;
}
public IUser FetchByID(int userID)
{
User user = null;
UserDTO dto = dataContainer.FetchUserFrom(userId);
user = UserConverter.ConvertFrom(dto);
return user;
}
} I have added a "IDataContainer" to your example which is for fetching the data. Added a parameterized constructor which can be used inject the "IDataContainer" (Dependency Injection).
According to "FetchById" method, getting data is from an external source. So that has to be mocked. So if you follow the example what I given, you can easily mock the data access and test "FetchByid" alone.
If in any other places "FetchById" is using, then you should mock "IUserRepository" and set expectations on "FetchById" method.
Are you using inbuilt testing tools in VS or tools like NUnit ? From my experience, I think MVP is better than MVC for testing.
Hope this helps
|
|
|
|
|
When I re-read your post, I had a feeling that you are not using TDD. You are writing tests but it's not test driven, is it ? If you write the test case in the begining, you might have avoided this confusion.
Initially you write the test something like
[Test]
public void CanFetchUserById()
{
UserRepository repository = new UserRepository();
IUser user = repository.FetchUserById(1);
Assert.That(user != NULL);
Assert.AreEqual(user.Id,1);
Assert.AreEqual(user.Name,"Jim");
} Now to make this test compile, you add a skeleton "FetchById" method to "UserRepository" class.
public IUser FetchByID(int userID)
{
throw new NotImplementedException();
} Now your test will compile, but it will fail. Now come back to your "FetchById" method and add it's implementation. You find that it needs an external source like database to complete processing. So you mock the database access to make your test isolated.
Hope this makes it more clear.
|
|
|
|
|