Ich versuche, Xamarin Forms (mit PCL-Projekt) zu verwenden. Mein Ziel ist es, eine App so zu gestalten, dass sie öffentlichen Dienst konsumiert (über Web-Services verfügbar). Ich versuche TODOASMX Example von Xamarin Website zu verwenden. Das Problem ist der Code:Xamarin bildet doppeltes Objekt (tiefe Kopie)
static TodoItem FromASMXServiceTodoItem (ASMXService.TodoItem item)
{
return new TodoItem {
ID = item.ID,
Name = item.Name,
Notes = item.Notes,
Done = item.Done
};
}
Umfang dieses Codes ist, Daten von ASMX Web-Service (ASMXService.TodoItem) an private domanin (TodoItem) zu kopieren. Die Typen sind identisch, unterscheiden sich jedoch im Namespace und im Typ.
In meinem Fall ist der Typ TodoItem mehr, mehr, komplizierter und ich muss eine tiefe Kopie verwenden. Jetzt versuche ich für tiefe Kopie diesen Code zu verwenden:
public static object CloneObject(object objSource)
{
//step : 1 Get the type of source object and create a new instance of that type
Type typeSource = objSource.GetType();
object objTarget = Activator.CreateInstance(typeSource);
//Step2 : Get all the properties of source object type
PropertyInfo[] propertyInfo = typeSource.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
//Step : 3 Assign all source property to taget object 's properties
foreach (PropertyInfo property in propertyInfo)
{
//Check whether property can be written to
if (property.CanWrite)
{
//Step : 4 check whether property type is value type, enum or string type
if (property.PropertyType.IsValueType || property.PropertyType.IsEnum || property.PropertyType.Equals(typeof(System.String)))
{
property.SetValue(objTarget, property.GetValue(objSource, null), null);
}
//else property type is object/complex types, so need to recursively call this method until the end of the tree is reached
else
{
object objPropertyValue = property.GetValue(objSource, null);
if (objPropertyValue == null)
{
property.SetValue(objTarget, null, null);
}
else
{
property.SetValue(objTarget, CloneObject(objPropertyValue), null);
}
}
}
}
return objTarget;
}
aber wenn Sie den Code der Fehler laufen:
System.MissingMethodException: Standard-Konstruktor nicht für Typ TodoASMX.Droid.MeginetOTA gefunden. excInfoByLang []
Nun ist die Art TodoASMX.Droid.MeginetOTA.excInfoByLang [] ist für mich nicht modifizierbar und ich kann nicht Standardkonstruktors auf diese Art hinzufügen. Dieser Typ wird durch den Import von öffentlichem WebService zurückgegeben.
Jede Problemumgehung (oder Lösung) wird geschätzt.
Vielen Dank im Voraus.
MP
Wie sieht der Konstruktor dieses Typs aus? –