나는이 또한 사용자 정의 유형을 사용 UserAreaType1
는 사용자 정의 유형을 직렬화 할 수 없습니다
[XmlType]
public class OrganizationChartUserArea :UserAreaType1
{
[XmlElement]
public HcrChoiceSet DefaultChoicesSet { get; set; }
[XmlElement]
public HcrChoiceSet CurrentChoicesSet { get; set; }
}
에서 상속 유형 OrganizationChartUserArea
을 정의 ProcessOrganizationChartDataAreaType
인사-xml 유형의 UserArea
을 확장하기 위해 노력하고있어 HcrChoiceSet
[XmlType]
public class HcrChoiceSet
{
[XmlElement]
public FreeFormEffectivePeriodType OngoingMeasurementPeriod { get; set; }
[XmlElement]
public FreeFormEffectivePeriodType OngoingStabilityPeriod { get; set; }
[XmlElement]
public FreeFormEffectivePeriodType OngoingAdministrationPeriod { get; set; }
}
나는이 확장 된 클래스의 인스턴스를 searlize 할 때
[TestMethod]
public void SerializeOrganizationChart()
{
var organizationSerializer = new XmlSerializer(typeof(ProcessOrganizationChartType));
var organizationWriter = new XmlTextWriter("C:\\ProcessOrganizationChart.xml", new UTF8Encoding());
var namespaces = new XmlSerializerNamespaces();
namespaces.Add("", "http://www.hr-xml.org/3");
namespaces.Add("oa", "http://www.openapplications.org/oagis/9");
namespaces.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
namespaces.Add("schemaLocation", "http://www.hr-xml.org/3 ../Developer/BODs/ProcessOrganizationChart.xsd");
organizationSerializer.Serialize(organizationWriter, processOrganizationChart, namespaces);
Assert.Inconclusive("This is not a true unit test.");
}
System.InvalidOperationException :
나는
?시험 방법 SomeNamespace.Tests.OrganizationChartTest.SerializeOrganizationChart 가 예외를 던진 말 오류가 XML 문서를 생성하는 동안 오류 가 발생했습니다. ---> System.InvalidOperationException : SomeNamespace.Tests.OrganizationChartUserArea 형식이 이 아닙니다. XmlInclude 또는 SoapInclude 특성을 사용하여 정적으로 알 수없는 형식을 지정합니다.
는 는어떻게이 문제를 해결할 수
[TestInitialize]
public void InitTest()
{
processOrganizationChart = new ProcessOrganizationChartType
{
ApplicationArea = new ApplicationAreaType
{
CreationDateTime = DateTime.Now.ToString("yyyy-MM-dd"),
BODID = new IdentifierType1 {Value = Guid.NewGuid().ToString()},
},
DataArea = new ProcessOrganizationChartDataAreaType
{
Process = new ProcessType
{
ActionCriteria = new[]
{
new ActionCriteriaType
{
ActionExpression = new[]
{
new ActionExpressionType
{
actionCode = "Add",
Value =
"/ProcessOrganizationChart/DataArea/OrganizationChart"
}
}
}
}
},
OrganizationChart = new[]
{
new OrganizationChartType
{
OrganizationUnit = new[]
{
new OrgChartOrganizationUnitType
{
validFrom = "2013-01-01",
OrganizationUnitID = new IdentifierType2
{
Value = "901"
},
ParentOrganizationUnit = new ParentOrganizationUnitType
{
OrganizationUnitID = new IdentifierType2
{
Value = "900"
}
},
RelatedOrganizationUnit = new[]
{
new RelatedOrganizationUnitType
{
OrganizationUnitID = new IdentifierType2
{
Value = "900"
}
}
},
OrganizationUnitName = new OrganizationNameType
{
languageID = "en-US",
Value = "SomeCompany"
},
TypeCode = new[]
{
new CodeType1
{
listID = "ClientStatus",
Value = "Active"
},
new CodeType1
{
listID = "ALEIndicator",
Value = "True"
},
new CodeType1
{
listID = "EducationIndicator",
Value = "False"
},
new CodeType1
{
listID = "MedicalBenefitsOffered",
Value = "False",
},
new CodeType1
{
listID = "MedicalBenefitsStatusDate",
Value = "2013-01-01"
}
}
,
UserArea = new OrganizationChartUserArea
{
DefaultChoicesSet = new HcrChoiceSet
{
OngoingAdministrationPeriod
= new FreeFormEffectivePeriodType
{
StartDate = new FreeFormDateType
{
FormattedDateTime =
"2015-01-01"
},
EndDate = new FreeFormDateType
{
FormattedDateTime =
"2015-01-31"
},
Duration = "P1M"
},
OngoingMeasurementPeriod =
new FreeFormEffectivePeriodType
{
StartDate = new FreeFormDateType
{
FormattedDateTime =
"2014-01-01"
},
EndDate = new FreeFormDateType
{
FormattedDateTime =
"2014-12-31"
},
Duration = "P12M"
},
OngoingStabilityPeriod =
new FreeFormEffectivePeriodType
{
StartDate = new FreeFormDateType
{
FormattedDateTime =
"2015-01-01"
},
EndDate = new FreeFormDateType
{
FormattedDateTime =
"2015-12-31"
},
Duration = "P12M"
}
},
CurrentChoicesSet = new HcrChoiceSet
{
OngoingAdministrationPeriod
= new FreeFormEffectivePeriodType
{
StartDate = new FreeFormDateType
{
FormattedDateTime =
"2015-01-01"
},
EndDate = new FreeFormDateType
{
FormattedDateTime =
"2015-01-31"
}
},
OngoingMeasurementPeriod =
new FreeFormEffectivePeriodType
{
StartDate = new FreeFormDateType
{
FormattedDateTime =
"2014-01-01"
},
EndDate = new FreeFormDateType
{
FormattedDateTime =
"2014-12-31"
}
},
OngoingStabilityPeriod =
new FreeFormEffectivePeriodType
{
StartDate = new FreeFormDateType
{
FormattedDateTime =
"2015-01-01"
},
EndDate = new FreeFormDateType
{
FormattedDateTime =
"2015-12-31"
}
}
}
}
}
}
}
}
}
};
}
OrgChartUnitType
namespace HrXml.v3_2_1.Types.HrXml
{
[Serializable]
[DebuggerStepThrough]
[DesignerCategory("code")]
[GeneratedCode("xsd", "4.0.30319.17929")]
[XmlRoot("OrganizationUnit", Namespace = "http://www.hr-xml.org/3", IsNullable = false)]
[XmlType(Namespace = "http://www.hr-xml.org/3")]
public class OrgChartOrganizationUnitType
{
public OrgChartOrganizationUnitType();
[XmlElement("AdditionalItem")]
public AdditionalItemType[] AdditionalItem { get; set; }
[XmlElement("MemberPosition")]
public MemberPositionType[] MemberPosition { get; set; }
public CodeType1 OrganizationLevelCode { get; set; }
public IdentifierType2 OrganizationUnitID { get; set; }
public TextType1 OrganizationUnitName { get; set; }
public ParentOrganizationUnitType ParentOrganizationUnit { get; set; }
[XmlElement("RelatedOrganizationUnit")]
public RelatedOrganizationUnitType[] RelatedOrganizationUnit { get; set; }
[XmlIgnore]
public AdditionalItemType SingleAdditionalItem { get; set; }
[XmlIgnore]
public MemberPositionType SingleMemberPosition { get; set; }
[XmlIgnore]
public RelatedOrganizationUnitType SingleRelatedOrganizationUnit { get; set; }
[XmlIgnore]
public CodeType1 SingleTypeCode { get; set; }
[XmlElement("TypeCode")]
public CodeType1[] TypeCode { get; set; }
public UserAreaType1 UserArea { get; set; }
[XmlAttribute]
public string validFrom { get; set; }
[XmlAttribute]
public string validTo { get; set; }
}
}
당신의 기본 클래스
당신이 직렬화하는 데 사용하는 코드를 게시 할 수 (예를 들어 당신은 몇 가지 기본 유형을 역 직렬화은'XmlSerializer'? 대부분의 경우를/직렬화 사용하고 있지만, 같은 당신이 기대 알려진 모든 서브 클래스를 (포함해야하는지 은'OrganizationChartUserArea') 편집 : 실제로 당신이 직렬화하는 상위 클래스의 속성 인 경우 OrganizationChartUserArea'가 직접 직렬화 된 객체/역 직렬화 아닌'경우에도, 어쩌면뿐만 아니라 해당 게시물 –
을 @. ChrisSinclair 내가 ProcessOrganizationChartType 직렬화 문제를 가지고하지 –
@ChrisSinclair 이상을 추가 한 자사 내 새로운 유형을 사용하여 확장하려고 할 때 ProcessOrganizationChartType은 HR-XML로 정의 된 경우에만 당신이 그것을 볼 수 있습니다 여기에 HTTP :. //neptune.pilotfish-net .com/HRXML/index.html? page = http : //neptune.pilotfish-net.com/HRXML/model/Format.ProcessOrganizationChart.DataArea.html –