|
WSDL and all of that is way outside of my experience (and doesn't seem to be something you are really having questions about, just complaints), so I won't speak to that.
Doing a search for "generic delegate inference" showed other people that were having the same problem as you, along with some explanations I will rephrase here. I'm sure I've run into the problem before and just don't remember where. The problem seems to come down to the compiler having to infer too many things at once. The rest of this post is how I assume the general flow of compilation goes, but I am by no means an authority on the compiler.
When you say Invoke(globalService.logout) , the compiler first has to guess what type to make globalService.logout , before it can determine what types to use for Invoke . It will then look to the method signature of Invoke to try to determine what type of delegate to create from the method group globalService.logout . It will see that it is based on a generic parameter, so it can't make any assumptions there. In this case, there is only one possible overload of logout, but there could be more logout definitions, and then there would be no way to know which one you want. The compiler team probably decided it wasn't worth adding the special case for when you have only one overload. One reason against that feature would be that adding an overload to the method would suddenly break previously working code.
Since there are no other parameters, the compiler has no more information to help it determine what types to fill in for the generic declaration and gives up. If you were to change Invoke to be Invoke<TRequest, TRepsone>(Func<TRequest, TResponse> method, TRequest param) , the compiler would then figure it out from the second parameter. It can determine this because you are not allowed to overload methods solely by return type. Thus when it sees the second parameter is, for example, string , the first parameter becomes Func<string, TResponse> which is apparently just enough for it to do the rest of the work itself. As you might guess, giving Invoke a parameter of TResponse will not clear up the error (because you could still have multiple definitions that would match).
|
|
|
|
|
I've referenced a dll made in VB.Net and now I need to inherit from some of the classes in the dll. Below is an example of how I did that:
class Tag : DataProvider.Trend.Tag
{
}
Now if I do like this:
DataProvider.Trend.Tag myBaseTag = new DataProvider.Trend.Tag();
Tag myTag = myBaseTag as Tag;
this results in that 'myTag' gets the value null. Why is that? How can I assign the value of myBaseTag to myTag?
Thanks for help!
|
|
|
|
|
Tag myTag = new Tag();
DataProvider.Trend.Tag myBaseTag = myTag as DataProvider.Trend.Tag;
Because myTag inherite from DataProvider.Trend.Tag.
|
|
|
|
|
Thanks for the reply.
But the problem for me is that I call methods in the dll I mention and they return the type 'DataProvider.Trend.Tag' BUT I need to cast that to type 'Tag'. I don't want to cast 'Tag' to 'DataProvider.Trend.Tag' (the reason is that 'Tag' so that it is accepted by a Web Service).
Thanks again.
|
|
|
|
|
You can cast an object of type A to a type B that inherits from A only when the object was already declared as B.
What you want to achieve is possible by creating a new object of type Tag and then initializing all its properties by using values from the 'DataProvider.Trend.Tag' original object (you can create a copy constructor for this).
|
|
|
|
|
xkrja wrote: DataProvider.Trend.Tag myBaseTag = new DataProvider.Trend.Tag();
Tag myTag = myBaseTag as Tag;
Of course that does not work. You can cast down, you cannot cast up. You need to read a basic book on OO
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
That's not going to work 'out of the box', you need to provide an explicit/implicit conversion method if you want to upcast.
|
|
|
|
|
Say we have
class A { protected string field1; }
class B : A { protected string field2; }
class C : B { protected string field3; }
void foo(A a) {}
void bar(B b) {}
void foobar(C c) {}
Now consider what instances of these objects *actually* will be inside your hardware. (We can safely ignore the fact that A extends object for the purpose of looking at why your attempted cast doesn't make sense.)
First a word about references: A reference is what we might also call a "managed pointer": Like a pointer, it simply contains the address where the data is stored, but unlike a pointer, we cannot obtain this address and the memory manager can move stuff around and update pointers as needed without us knowing anything about it.
Since string is a reference type, an instance of A is a word of memory (4 bytes on a 32-bit system) containing a reference to string data. An instance of B however is two words of data, containing two references, to field1 and field2 data. And C of course is three words, laid out in memory like an instance of B appended with the additional reference to field3 data.
What you want to do is the equivalent of trying to use an instance of A and pass it to foobar, which takes a parameter of type C. Since an A is just the word for the field1 reference, foobar might access memory outside the bounds of the object and it could screw up other live objects (placed next to the instance of A in memory). So clearly the compiler shouldn't let you do that.
If you wanted the compiler to just go ahead and create an instance of C for you when you make the cast, it wouldn't know what to do with field2 and field3. There is no way *in general* to know that the MotorBike class (descendant type) works just fine with only the data it inherited from the Vehicle class. If there were, we could just go like this:
AmazingWebSerive s = (AmazingWebService)(new object());
Sadly, this doesn't work. Instead, it's you as a programmer who may know this and provide a way to construct a B with only A data, or a C with only A data, and so on. Then you decide what the defaults should be for the data that doesn't exist in A.
class A { protected string field1; }
class B : A { protected string field2; }
class C : B
{
protected string field3;
public C(A a) { field1 = a.field1; }
}
Now if I have an A and I want to "use it as a C" I can simply go C c = new C(a); and work from there.
BUT... if the reason you derived your own Tag class was because you wanted to add operations (methods) rather than data, there is another way. If you're using C# 2.0 you can write your methods as extension methods instead. For example, let's say I want to add a GoCrazy() method to A but A is defined in my generated web service proxy code and I don't want to touch that stuff (perhaps because I may need to regenerate it later). Then I can declare the extension method in any class I want, like this:
namespace MyExtentions
{
public class Whatever
{
static public void GoCrazy(this A a) { ... }
static public C ToC(this A a, string field2, string field3)
{
C c = new C(a);
c.field2 = field2;
c.field3 = field3;
}
}
}
a.GoCrazy();
C c = a.ToC("foo", "bar");
The keyword "this" before the first parameter of a static method makes the method an extension method, so the compiler can find it when "a.GoCrazy()" cannot be resolved as an instance method of A.
Hope this helps!
|
|
|
|
|
Hi,
i have a GSM modem connected to my computer, when i receive a call on my MODEM i can issue an AT command to answer the call, i use C# Serial port communication to issue the AT Commands. So after i issue AT Command to answer the call, i will play a sound file in my system using C#, I need to stream this sound into the GSM Modem, so that the person who calling can hear the sound playing on the System.
In short, i need to know how to stream audio from my computer into the GSM Modem, and also how to stream the voice from GSM modem to the System.
Hope my question is clear, Also i am not sure whether i had posted in the correct Forum topic. Thanks for your understandings.... Please do ask me any questions you have...
|
|
|
|
|
I dont know how to get voice transmission with GSM modem, I have always used it for send/receive SMS and placing calls. few months ago I had created an IVRS system, at that time I had tried using GSM modem, but no luck. so I end up using 'Internal FAX/DATA/Voice Modem' with TAPI classes, and it worked. so if you can consider that option, then that will sure work (and one more thing implementation of TAPI in .net is bit difficult).
|
|
|
|
|
Hi
I'm using DotNetOpenMail to send emails frommy .net applications, recently we updated to Exchange 2007 using active directory for authentication. this resulted in all my apps crashing, how do i add authentication to my emails,using the following code i get the error message:
Unrecognized authentication type
is there another way to to the authentication?
thanx in advance
EmailMessage emailMessage = new EmailMessage();
emailMessage.FromAddress = new EmailAddress("admin@ftech.co.za", "SMS Service");
emailMessage.AddToAddress(new EmailAddress("ismail@ftech.co.za"));
emailMessage.AddToAddress(new EmailAddress("Brynn@ftec.co.za"));
emailMessage.Subject = "Company Bulk SMS Billing " + StartDate + " - " + EndDate;
emailMessage.BodyText = @"" + StrEmialBody;
SmtpServer smtpServer = new SmtpServer("pmbex-01");
smtpServer.SmtpAuthToken = new SmtpAuthToken("administrator", "password");
emailMessage.Send(smtpServer);
|
|
|
|
|
What is DotNetOpenMail and why do you need to use more than the mail libraries built into the framework ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
i've been using it for a long time, i've actually never used the built in library..i once head it was not very good..
|
|
|
|
|
DotNetCoderJunior wrote: .i once head it was not very good.
Never take another person's "advice" without trying it out yourself (at least when it comes to programming )
There are always people who are going to say this or that "sucks" but without trying it yourself you don't know if it's true.
Also that person's advice could be misguided, he could have try'd to use it for something to complex or that it wasn't designed to do.
|
|
|
|
|
Tom Deketelaere wrote: Never take another person's "advice" without trying it out yourself (at least when it comes to programming )
With all due respect, but no undue respect, that's a bit silly. The logical implication is that we should try every possible library and technique and tool in the universe, which means it would take a lifetime to accomplish "hello world".
Obviously one should and must take advice without first-hand investigation, in programming as in every other walk of life. Learning VB6 well enough to make absolutely certain for myself that it sucks is not necessary and would not be productive, for example.
I'd agree though that just reading "somewhere" that something "isn't very good" is not a solid base for dismissal. Especially not when it's the FrameWork, which I think we all know is mostly of very high quality.
|
|
|
|
|
DotNetCoderJunior wrote: i once head it was not very good..
Sounds like a compelling reason to tie yourself to a third party library no-one has heard of, and therefore no-one can help you with. I've been mailing through .ENT code for years, never had a problem. Guess I checked it for myself instead of listening to what I overheard someone say in an elevator.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Christian Graus wrote: third party library no-one has heard of
Christian Graus wrote: .ENT
What library is that, I never heard of it
|
|
|
|
|
Hello people,
I read so many articles why not to use dynamic and how powerful it is, so it can lead to misusage and so on. But I found very few articles, that are really about practical usage, most of them are just examples of what is dynamic and quite simple usage.
I am curious to get some examples, not how it works, but where/when you really need dynamics and why?
Thanks!
|
|
|
|
|
I'm not up-to-date in C# 4.0, but it sounds like the devil to me.
Regards,
Rob Philpott.
|
|
|
|
|
|
@Richard: If you can't or don't want to answer my question, then it's easy - just don't.
I didn't ask you how to google, and if you read my question - I did NOT ask how it works or about simple examples, but about interesting solutions that somebody used about specific problem and has a valid reason to use dynamic.
|
|
|
|
|
I've used C# 4.0 for normal development since .NET 4.0 Beta 1 was released; and I haven't used dynamic a single time. I don't see any use for it except for talking to IronPython code.
There might some interesting other uses for dynamic in combination with custom IDynamicObject implementations; I would have to take a closer look at IDynamicObject.
In fact, the only C# 4.0 feature I use is covariance (and even that only for IEnumerable).
|
|
|
|
|
We have a couple of old COM components that are interacted with using late binding. We use configuration entries to determine which component to call because they have the same signatures, but they talk to different types of components, i.e. one communicates with certain hardware using TCP, while the other uses COM calls directly. The code that controls this is quite gnarly, and isn't fun to write because it requires lots of late binding work which is a complete PITA in .NET.
With dynamic, we can replace this code with a simple class that takes this pain away. So far, it's the only use I can find for using dynamic .
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hey guy,
When to use c# preset attributes in general, like
[MethodImpl(MethodImplOptions.Synchronized)] and is it possible to not use it at all??
Any help appreciated, thanks in advance.
|
|
|
|
|
Use them when you want to specify something that is specified by attributes, and don't use them when you are happy with the default value.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|