0
일부 날짜 속성이있는 복잡한 개체를 완전 복사하려고합니다. "값 ''을 (를) 올바른 날짜로 변환 할 수 없습니다. '오류가 발생합니다. 복사를 위해 아래 코드를 사용하고 있습니다. -C# 리플렉션 딥 복사본 집합 날짜 시간 값
private static object CloneProcedure(Object obj)
{
if (type.IsPrimitive || type.IsEnum || type == typeof(string))
{
return obj;
}
else if (type.IsClass || type.IsValueType)
{
object copiedObject = Activator.CreateInstance(obj.GetType());
// Get all PropertyInfo.
PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
foreach (PropertyInfo property in properties)
{
object propertyValue = property.GetValue(obj);
if (propertyValue != null && property.CanWrite && property.GetSetMethod() != null)
{
property.SetValue(copiedObject, CloneProcedure(propertyValue));
}
}
}
}
내가 누락 된 항목이 있습니까?
그것은 도움이 될 것이다. – Compufreak
@Compufreak 업데이트 됨 내 질문 –