Exemplo n.º 1
0
        private static T[] system_array_to_typed_array <T>(System.Array results_sa)
        {
            var results = new T[results_sa.Length];

            results_sa.CopyTo(results, 0);
            return(results);
        }
Exemplo n.º 2
0
        private static TResult[] get_results_array <TResult>(System.Array results_sa, int numitems)
        {
            if (results_sa.Length != numitems)
            {
                string msg = $"Expected {numitems} items from GetResults but only received {results_sa.Length}";
                throw new AutomationException(msg);
            }

            TResult[] results = new TResult[results_sa.Length];
            results_sa.CopyTo(results, 0);
            return(results);
        }
Exemplo n.º 3
0
        public static TResult[] _GetResults <TResult>(ShapeSheetSurface surface, short[] stream, IList <IVisio.VisUnitCodes> unitcodes, int numitems)
        {
            EnforceValidResultType(typeof(TResult));

            if (numitems < 1)
            {
                return(new TResult[0]);
            }

            var result_type         = typeof(TResult);
            var unitcodes_obj_array = get_unit_code_obj_array(unitcodes);
            var flags = get_VisGetSetArgs(result_type);

            System.Array results_sa = null;

            if (surface.Target.Master != null)
            {
                surface.Target.Master.GetResults(stream, (short)flags, unitcodes_obj_array, out results_sa);
            }
            else if (surface.Target.Page != null)
            {
                surface.Target.Page.GetResults(stream, (short)flags, unitcodes_obj_array, out results_sa);
            }
            else if (surface.Target.Shape != null)
            {
                surface.Target.Shape.GetResults(stream, (short)flags, unitcodes_obj_array, out results_sa);
            }
            else
            {
                throw new System.ArgumentException("Unhandled Target");
            }

            if (results_sa.Length != numitems)
            {
                string msg = string.Format("Expected {0} items from GetResults but only received {1}", numitems,
                                           results_sa.Length);
                throw new InternalAssertionException(msg);
            }

            var results = new TResult[results_sa.Length];

            results_sa.CopyTo(results, 0);
            return(results);
        }
Exemplo n.º 4
0
        private void ReadCacheInfos()
        {
            if (!target || !(target is MonoBehaviour))
            {
                return;
            }
            var referenceBehaiver = (target as MonoBehaviour).gameObject.GetComponent <ReferenceCatchBehaiver>();

            if (referenceBehaiver != null)
            {
                bool canDelete = true;
                referenceItems.Clear();
                var infoItems = referenceBehaiver.GetReferenceItems();
                if (infoItems != null)
                {
                    var flags = System.Reflection.BindingFlags.GetField |
                                System.Reflection.BindingFlags.Instance |
                                System.Reflection.BindingFlags.NonPublic;

                    System.Type referenceType  = null;
                    object      referenceValue = null;

                    var referenceField = target.GetType().BaseType.GetField("m_data", flags);

                    if (referenceField != null)
                    {
                        referenceValue = referenceField.GetValue(target);
                        referenceType  = referenceField.FieldType;
                    }

                    for (int i = 0; i < infoItems.Count; i++)
                    {
                        var       infoItem  = infoItems[i];
                        FieldInfo field     = null;
                        object    targetObj = null;
                        if (typeof(UnityEngine.Object).IsAssignableFrom(infoItem.type))
                        {
                            field     = target.GetType().GetField("m_" + infoItem.name, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.GetField);
                            targetObj = target;
                        }
                        else
                        {
                            field     = referenceType.GetField(infoItem.name, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.GetField);
                            targetObj = referenceValue;
                        }

                        if (field != null)
                        {
                            var refType = GetReferenceType(field.FieldType, infoItem.isArray);
                            try
                            {
                                #region SetValues
                                switch (refType)
                                {
                                case ReferenceItemType.Reference:
                                    field.SetValue(targetObj, infoItem.referenceTarget);
                                    break;

                                case ReferenceItemType.ConventAble:
                                    field.SetValue(targetObj, System.Convert.ChangeType(infoItem.value, infoItem.type));
                                    break;

                                case ReferenceItemType.Struct:
                                    field.SetValue(targetObj, JsonUtility.FromJson(infoItem.value, infoItem.type));
                                    break;

                                case ReferenceItemType.ReferenceArray:
                                {
                                    if (infoItem.referenceTargets != null)
                                    {
                                        System.Array referenceArray = infoItem.referenceTargets.ToArray();
                                        var          arrayType      = infoItem.type.MakeArrayType();
                                        var          array          = System.Activator.CreateInstance(arrayType, referenceArray.Length) as System.Array;
                                        referenceArray.CopyTo(array, 0);
                                        field.SetValue(targetObj, array);
                                    }
                                }
                                break;

                                case ReferenceItemType.ConventAbleArray:
                                {
                                    if (infoItem.values != null)
                                    {
                                        System.Array valuesArray = infoItem.values.Select(x => System.Convert.ChangeType(x, infoItem.type)).ToArray();
                                        var          arrayType   = infoItem.type.MakeArrayType();
                                        var          array       = System.Activator.CreateInstance(arrayType, valuesArray.Length) as System.Array;
                                        valuesArray.CopyTo(array, 0);
                                        field.SetValue(targetObj, array);
                                    }
                                }

                                break;

                                case ReferenceItemType.StructArray:
                                    if (infoItem.values != null)
                                    {
                                        System.Array valuesArray = infoItem.values.Select(x => JsonUtility.FromJson(x, infoItem.type)).ToArray();
                                        var          arrayType   = infoItem.type.MakeArrayType();
                                        var          array       = System.Activator.CreateInstance(arrayType, valuesArray.Length) as System.Array;
                                        valuesArray.CopyTo(array, 0);
                                        field.SetValue(targetObj, array);
                                    }
                                    break;

                                default:
                                    break;
                                }
                            }
                            catch (System.Exception e)
                            {
                                canDelete = false;
                                Debug.Log("类型转换失败:" + field.Name + " detail: " + e);
                            }
                            #endregion SetValues
                        }
                        else
                        {
                            canDelete = false;
                            Debug.Log("类型不存在:" + infoItem.name);
                        }
                    }

                    if (referenceField != null)
                    {
                        referenceField.SetValue(target, referenceValue);
                    }
                }
                if (canDelete)
                {
                    Object.DestroyImmediate(referenceBehaiver, true);
                }
            }
        }