我正在編寫一個實用程序,將特定數據從後端SQL數據庫複製到客戶端計算機SQL Express數據庫。後端數據庫和客戶端數據庫是相同的。這些數據適用於沒有網絡的遠程站點的測量員。 我正在使用REST服務並在服務和代理上使用實體框架。我正在複製這個代碼的屬性值:在對象之間複製值
private void GatherFrom<TSelf, TSource>(TSelf self, TSource source)
{
PropertyInfo[] sourceAllProperties = source.GetType().GetProperties();
foreach (PropertyInfo sourceProperty in sourceAllProperties)
{
PropertyInfo selfProperty = self.GetType().GetProperty(sourceProperty.Name);
if (selfProperty.CanRead
&& (selfProperty.GetSetMethod(true) != null && !selfProperty.GetSetMethod(true).IsPrivate)
&& (selfProperty.GetSetMethod().Attributes & MethodAttributes.Static) == 0
&& selfProperty.PropertyType.IsAssignableFrom(sourceProperty.PropertyType))
{
var sourceValue = sourceProperty.GetValue(source);
selfProperty.SetValue(self, sourceValue);
}
}
}
這工作都很好。
但是當我申請新的數據:
Surveys newSurvey = new Surveys();
GatherFrom(newSurvey, survey);
localSurveys.Add(newSurvey);
我進入的問題,因爲我有曖昧類型的遠程和在同一個命名空間的本地。
任何想法如何分裂它?
使用完整的命名空間。 – Maarten