Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

Commented Issue: Ambiguity when passing null to overloaded methods [72]

0
0
Hi, I'm having another issue with passing null to overloaded methods. Here's code sample.
```

public class SimpleObject
{
public string Name { get; set; }
public string GetName()
{
return null;
}
}

public static class LogWriter
{
public static void WriteLine(string message)
{
Console.WriteLine(message);
}

public static void WriteLine(Exception e)
{
if (e == null) Console.WriteLine(string.Empty);
else Console.WriteLine(string.Format("Exception: {0}\n{1}", e.Message, e.StackTrace));
}
}

```
Exposing "SimpleObject" and "LogWriter"
```
Engine.AddHostObject("SimpleObject", new SimpleObject());
Engine.AddHostType("Logger", typeof(LogWriter));
```
Then I will get error by scripting "Logger.WriteLine(SimpleObject.Name)" or "Logger.WriteLine(SimpleObject.GetName())".

The call is ambiguous between the following methods or properties:
'ConsoleApplication1.LogWriter.WriteLine(string)' and 'ConsoleApplication1.LogWr
iter.WriteLine(System.Exception)'

Is that missing converting the value of the property/return value of the method to property type/method return type? In this case, it should be (string)null.

Thank you!
Comments: Optional null result wrapping implemented in [Version 5.4.2](https://clearscript.codeplex.com/SourceControl/changeset/bfd06449d9e70818985d855319b7bc3a955313aa).

Viewing all articles
Browse latest Browse all 2297

Latest Images

Trending Articles





Latest Images