It’s not entirely accurate what to call this question, so I hope the title will work.
The question is, can I use something similar to implicit type syntax when calling a method. For example, this is the syntax of an implicit type, which I mean:
var x = new Y(){Foo = "Bar", Id = 1};
And I want to do something like this:
var x = myInstance.CreateItem(){Foo = "Bar", Id = 1};
Is there anything in C # that supports something like this? I do not want to do:
x.Foo = "Bar";
x.Id = 1;
...
Note that CreateItem returns a dynamic type. The CreateItem method and its class cannot be changed.
I would agree to something like statement C in VB.
Thanks in advance.
UPDATE: Attempting to solve Mark Brackett gave this code:
TaskItem item = outlook.CreateItem(OlItemType.olTaskItem)._((Action<dynamic>)(i =>
{
i.Subject = "New Task";
i.StartDate = DateTime.Now;
i.DueDate = DateTime.Now.AddDays(1);
i.ReminderSet = false;
i.Categories = "@Work";
i.Sensitivity = OlSensitivity.olPrivate;
i.Display = true;
}));
...
public static class Extension
{
public static T _<T>(this T o, System.Action<dynamic> initialize) where T : class
{
initialize(o);
return o;
}
}
, System._ComObject, : System._ComObject ' ' _ '.