/// <summary> /// Deserializes the Frame to a .NET object. /// </summary> /// <typeparam name="T">The type of the object to deserialize to.</typeparam> /// <param name="frame">The Frame to deserialize.</param> /// <param name="reflection">Reflection information for the Object to deserialize</param> /// <returns>The deserialized object from the Frame.</returns> private static List <T> InternalDeserializeV2 <T>(PackageV2 frame, ReflectionType reflection) { //get group attribute PackageGroupAttribute PackageGroupAttribute = reflection.GetCustomAttribute <PackageGroupAttribute>(); if (PackageGroupAttribute == null) { throw new Exception(String.Format("Type {0} does not contain FrameGroup attribute!", reflection.Type.Name)); } //create collection List <T> collection = new List <T>(); //each objects foreach (PackageGroupItem group in frame.Groups) { //check group address for this type if (group.Address == PackageGroupAttribute.Address) { //intiailize object T result = PackageHelper.InternalDeserializeV2 <T>(group, reflection); //create objet to collection collection.Add(result); } } //return result return(collection); }
/// <summary> /// This function serializes object to frame group /// </summary> /// <typeparam name="T">Data type</typeparam> /// <param name="data">Data object</param> /// <param name="reflection">reflection info for this data type</param> /// <returns>Group collection</returns> private static List <PackageGroupItem> InternalSerializeV2ToGroup <T>(List <T> data, ReflectionType reflection) { //get group attribute PackageGroupAttribute PackageGroupAttribute = reflection.GetCustomAttribute <PackageGroupAttribute>(); //check group attribute if (PackageGroupAttribute != null) { //get collection List <PackageGroupItem> collection = new List <PackageGroupItem>(); //loop all object foreach (T obj in data) { //serialize object PackageGroupItem group = InternalSerializeV2ToGroup <T>(obj, reflection, PackageGroupAttribute); if (group != null) { collection.Add(group); } } //return groups return(collection); } //no data return(null); }
/// <summary> /// This function serializes object to frame group /// </summary> /// <typeparam name="T">Data type</typeparam> /// <param name="data">Data object</param> /// <param name="reflection">reflection info for this data type</param> /// <returns>Group | null</returns> private static PackageGroupItem InternalSerializeV2ToGroup <T>(T data, ReflectionType reflection) { //get group attribute PackageGroupAttribute PackageGroupAttribute = reflection.GetCustomAttribute <PackageGroupAttribute>(); //check group attribute if (PackageGroupAttribute != null) { //serialize data return(InternalSerializeV2ToGroup <T>(data, reflection, PackageGroupAttribute)); } //no data return(null); }
/// <summary> /// Vrati alebo vytvori a vrati kolekciu property pre pozadovany typ objektu /// </summary> /// <param name="type">Model type</param> /// <returns>ReflectionPropertyItemCollection</returns> public ReflectionPackageModelItem FindPropertyCollection(Type type) { //get group attribude PackageGroupAttribute attribute = InternalGetGroupAttribute(type); if (attribute != null) { if (!this.ContainsKey(attribute.Address)) { return(this.InternalCreateType(type)); } return(this[attribute.Address]); } return(null); }
/// <summary> /// Serializes the specified Object to Frame /// </summary> /// <typeparam name="T">The type of the object to serialize to.</typeparam> /// <param name="data">The object to serialize.</param> /// <param name="frame">Frame</param> /// <param name="reflection">Reflection information for the Object to deserialize</param> /// <returns>Frame | null</returns> private static PackageV2 InternalSerializeV2 <T>(List <T> data, PackageV2 frame, ReflectionType reflection) { //get group attribute PackageGroupAttribute PackageGroupAttribute = reflection.GetCustomAttribute <PackageGroupAttribute>(); //each object foreach (T obj in data) { //check attribute if (PackageGroupAttribute != null) { //serialize group PackageGroupItem group = InternalSerializeV2ToGroup <T>(obj, reflection, PackageGroupAttribute); //create group to frame frame.Add(group); } } //return result return(frame); }
/// <summary> /// This function serializes object to frame group /// </summary> /// <typeparam name="T">Data type</typeparam> /// <param name="data">Data object</param> /// <param name="reflection">reflection info for this data type</param> /// <param name="PackageGroupAttribute">Current group attribute</param> /// <returns>Group | null</returns> private static PackageGroupItem InternalSerializeV2ToGroup <T>(T data, ReflectionType reflection, PackageGroupAttribute PackageGroupAttribute) { //variables Object value = null; //create group PackageGroupItem group = new PackageGroupItem(PackageGroupAttribute.Address); //set property foreach (ReflectionProperty item in reflection.PropertyCollection.Values) { //check property type if (item.Property.CanRead) { //get current attribute PackageItemAttribute attribute = item.GetCustomAttribute <PackageItemAttribute>(); if (attribute != null) { try { value = item.Property.GetValue(data, null); if (value != null) { IPackageItem frameItem = Package.CreatePackageItem(attribute.Type, attribute.Address, value); if (frameItem != null) { group.Add(frameItem); } } } catch (Exception ex) { throw new Exception(String.Format("Error type: {0} -> {1} [{2}]", attribute.Type, item.Property.Name, value), ex); } } } } //return current group return(group); }