I try to use trial version of third party software written C#. While I try to use its API, I face up with a strange problem.
I am using visual studio 2015 and I found an interesting extended method signature in their API-SDK
public static class CallExtendedInfoEx
{
public static void AddToSIPMessage(this CallExtendedInfo info, msg);
}
The second parameter type is not exist.Never seen before in C#. I try to give a generic Object parameter as second parameter, and C# Compiler gives a strange error
Severity Code Description Project File Line
Error CS1503 Argument 2: cannot convert from 'object' to '.'
It works with "null"...No compiler error or run time error [ ignored i think ]
How those guys can able to write such a code in C#? Is It Posssible? Any idea?
Note : I suspect from a code obscurification problem...But still i do not understand what is going here
IL_0073: call void [CallExtendedInfoEx::AddToSIPMessage(class [VoIP.CallExtendedInfo,
class [VoIPSDK]''.'')
In the above function definition variable ' b' is the parameter and the value passed to the variable. 'b' is the argument. The precondition (requires) and postcondition (returns) of the function is given. We have not mentioned any types: (data types). This is called parameter without type.
If a function takes no parameters, the parameters may be left empty. The compiler will not perform any type checking on function calls in this case. A better approach is to include the keyword "void" within the parentheses, to explicitly state that the function takes no parameters.
The lesson brief states that “Functions can have zero, one or more parameters”.
In C, void no_args() declares a function that takes an unspecified (but not variable) number of parameters (and returns nothing). So all your calls are valid (according to the prototype) in C. In C, use void no_args(void) to declare a function that truly takes no parameters (and returns nothing).
Well, looking at the ILDASM output, it's rather obvious that the argument has a perfectly valid type. Sure, it's a type that you can't actually name in C#, but it's perfectly valid in CLR at large.
The fact that you can pass null
shouldn't be surprising - the argument is a reference type (or convertible from null
), so null
is a perfectly valid value. On the other hand, expecting passing an object
instance is entirely wrong - you can only pass more derived types as argument, not less. It's fine to pass string
(more specific) instead of object
(less specific), but not the other way around.
Most likely, this is either a method you shouldn't touch (i.e. not part of the public contract of the API/SDK), or you're expected to get instances of the argument from some other method - never using the explicit type anywhere.
This is not valid C# code. Some decompiler probably gave you that code, or the documentation where you copied this out of is faulty.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With