It seems normal to me that the serialization code will work on the actual type of the object, and not on the type passed as a parameter (it is even more likely that the function accepts a parameter of type object , and is not a general function of SerializeObject<T>(T obj) ).
If you want your object to be sliced, I'm afraid you will have to cut it yourself by creating an object that implements the interface and only copying its elements.
public class ProjectInfo : IProjectInfo { public string ProjectName { get; set; } public string ProjectTitle { get; set; } public string ProjectDescription { get; set; } public string ProjectAuthor { get; set; } public string ProjectCopyright { get; set; } public string ProjectTrademark { get; set; } public string ProjectCreationDate { get; set; } public string ProjectVersion { get; set; } public string ProjectFileName { get; private set; } public string ProjectFilePath { get; private set; } public string FullProjectPath { get; private set; } public ProjectInfo(IProjectInfo src) { this.ProjectName = src.ProjectName; this.ProjectTitle = src.ProjectTitle; this.ProjectDescription = src.ProjectDescription; this.ProjectAuthor = src.ProjectAuthor; this.ProjectCopyright = src.ProjectCopyright; this.ProjectTrademark = src.ProjectTrademark; this.ProjectCreationDate = src.ProjectCreationDate; this.ProjectVersion = src.ProjectVersion; this.ProjectFileName = src.ProjectFileName; this.ProjectFilePath = src.ProjectFilePath; this.FullProjectPath = src.FullProjectPath; } }
And then you can use it as follows:
frmProjectForm f = new frmProjectForm(); f.ShowDialog(this); ... ... IProjectInfo getProjectInfoMembersOnly = new ProjectInfo(f);
source share