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

Edited 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 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!

Viewing all articles
Browse latest Browse all 2297

Latest Images

Trending Articles





Latest Images