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

Created Unassigned: 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 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)".

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 to property type? In this case, it should be (string)null.

Thank you!

Viewing all articles
Browse latest Browse all 2297

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>