Beispiel #1
0
        private static void AssignmentManagedStruct(Structure structure, ref object staging_object)
        {
            Type s = staging_object.GetType();

            SR.FieldInfo[] sfi = s.GetFields();
            foreach (SR.FieldInfo fi in structure.simple_fields)
            {
                object field_value = fi.GetValue(structure._class_instance);
                String na          = fi.Name;
                String tys         = Campy.Utils.Utility.GetFriendlyTypeName(fi.FieldType);
                // Copy.
                SR.FieldInfo hostObjectField = fi;
                object       value           = field_value;
                // Never copy tile_statics...
                if (TypesUtility.IsCampyTileStaticType(fi.FieldType))
                {
                    continue;
                }
                var deviceObjectField = sfi.Where(f => f.Name == fi.Name).FirstOrDefault();
                if (deviceObjectField == null)
                {
                    throw new ArgumentException("Field not found.");
                }
                if (field_value != null)
                {
                    deviceObjectField.SetValue(staging_object, value);
                }
                else
                {
                    // In order to prevent a lot of segv's ...
                    // Create a default value based on field type?
                    if (TypesUtility.IsCampyArrayViewType(fi.FieldType))
                    {
                        deviceObjectField.SetValue(staging_object, Array_View <int> .Default_Value);
                    }
                    else if (TypesUtility.IsCampyArrayType(fi.FieldType))
                    {
                        deviceObjectField.SetValue(staging_object, Array <int> .Default_Value);
                    }
                    else if (TypesUtility.IsCampyAcceleratorType(fi.FieldType))
                    {
                        deviceObjectField.SetValue(staging_object, Accelerator.Default_Value);
                    }
                    else if (TypesUtility.IsCampyAcceleratorViewType(fi.FieldType))
                    {
                        deviceObjectField.SetValue(staging_object, Accelerator_View.Default_Value);
                    }
                    else if (TypesUtility.IsCampyIndexType(fi.FieldType))
                    {
                        deviceObjectField.SetValue(staging_object, Index.Default_Value);
                    }
                    else if (TypesUtility.IsCampyExtentType(fi.FieldType))
                    {
                        deviceObjectField.SetValue(staging_object, Extent.Default_Value);
                    }
                    else
                    {
                    }
                }
            }
            // Add in other structures.
            foreach (Structure child in structure.nested_structures)
            {
                SR.FieldInfo sn = sfi.Where(f => child.Name == f.Name).FirstOrDefault();
                if (sn == null)
                {
                    throw new ArgumentException("Field not found.");
                }
                object vsn = sn.GetValue(staging_object);
                if (vsn == null)
                {
                    throw new ArgumentException("Value not found.");
                }
                AssignmentManagedStruct(child, ref vsn);
            }
        }