CreateWithId

CSharp · Console

/Program.cs

using System;
using Faithlife.Reflection;

class Program
{
	static void Main()
	{
		var widget = CreateWithId<Widget>("xyzzy");
		Console.WriteLine(widget.Id);
	}

	static T CreateWithId<T>(string id)
	{
		var dtoInfo = DtoInfo.GetInfo<T>();
		var dto = dtoInfo.CreateNew();
		dtoInfo.GetProperty<string>("Id").SetValue(dto, id);
		return dto;
	}
}

class Widget
{
	public string Id { get; set; }
}
;