Exemple #1
0
        /// <summary>
        /// Attempts to find a fiendly description. If found, returns it.
        /// </summary>
        /// <param name="rType">Type whose friendly name we want</param>
        /// <returns>String that is the friendly name for class name</returns>
        public static string GetDescription(Type rType)
        {
            string lTypeName = "";

            MotionDescriptionAttribute lAttribute = ReflectionHelper.GetAttribute <MotionDescriptionAttribute>(rType);

            if (lAttribute != null)
            {
                lTypeName = lAttribute.Value;
            }

            return(lTypeName);
        }
        /// <summary>
        /// Gathers the master list of items and categories
        /// </summary>
        /// <param name="rItems">MotionSelectItems that represent the motion types</param>
        /// <param name="rTags">Tag strings</param>
        /// <returns></returns>
        public static int GetMasterMotionTypes(List <MotionSelectType> rTypes)
        {
            Type lBaseType = typeof(MotionControllerMotion);

            rTypes.Clear();
            //rTypeTags.Clear();

            // CDL 06/28/2018 - this only scans the "ootii" assembly
            //// Generate the list of motions to display
            //Assembly lAssembly = Assembly.GetAssembly(lBaseType);
            //Type[] lMotionTypes = lAssembly.GetTypes().OrderBy(x => x.Name).ToArray<Type>();
            //for (int i = 0; i < lMotionTypes.Length; i++)
            //{
            //    Type lType = lMotionTypes[i];
            //    if (lType.IsAbstract) { continue; }
            //    if (!lBaseType.IsAssignableFrom(lType)) { continue; }

            //    string lName = MotionNameAttribute.GetName(lType);
            //    if (lName == null || lName.Length == 0) { lName = BaseNameAttribute.GetName(lType); }

            //    string lDescription = MotionDescriptionAttribute.GetDescription(lType);
            //    if (lDescription == null || lDescription.Length == 0) { lDescription = BaseDescriptionAttribute.GetDescription(lType); }

            //    string lTypeTags = MotionTypeTagsAttribute.GetTypeTags(lType);

            //    MotionSelectType lItem = new MotionSelectType();
            //    lItem.Type = lType;
            //    lItem.Path = lType.Name + ".cs";

            //    //string[] lFolders = System.IO.Directory.GetFiles(Application.dataPath, lItem.Path, System.IO.SearchOption.AllDirectories);
            //    //if (lFolders.Length > 0) { lItem.Path = lFolders[0]; }

            //    lItem.Name = lName;
            //    lItem.Description = lDescription;
            //    lItem.TypeTags = lTypeTags;
            //    lItem.TypeTagArray = lTypeTags.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            //    rTypes.Add(lItem);

            //    //// Create the type tags
            //    //if (lItem.TypeTagArray != null)
            //    //{
            //    //    for (int j = 0; j < lItem.TypeTagArray.Length; j++)
            //    //    {
            //    //        bool lIsFound = false;
            //    //        for (int k = 0; k < rTypeTags.Count; k++)
            //    //        {
            //    //            if (string.Compare(rTypeTags[k].Tag, lItem.TypeTagArray[j], true) == 0)
            //    //            {
            //    //                lIsFound = true;
            //    //                break;
            //    //            }
            //    //        }

            //    //        if (!lIsFound)
            //    //        {
            //    //            MotionSelectTypeTag lTypeTag = new MotionSelectTypeTag();
            //    //            lTypeTag.Tag = lItem.TypeTagArray[j];

            //    //            rTypeTags.Add(lTypeTag);
            //    //        }
            //    //    }
            //    //}
            //}

            // CDL 06 / 28 / 2018 - scan all assemblies for Motions
            List <Type> lFoundTypes = AssemblyHelper.FoundTypes;

            // Generate the list of Motions to display
            for (int i = 0; i < lFoundTypes.Count; i++)
            {
                Type lType = lFoundTypes[i];
                if (lType.IsAbstract)
                {
                    continue;
                }
                if (!lBaseType.IsAssignableFrom(lType))
                {
                    continue;
                }

                string lName = MotionNameAttribute.GetName(lType);
                if (lName == null || lName.Length == 0)
                {
                    lName = BaseNameAttribute.GetName(lType);
                }

                string lDescription = MotionDescriptionAttribute.GetDescription(lType);
                if (lDescription == null || lDescription.Length == 0)
                {
                    lDescription = BaseDescriptionAttribute.GetDescription(lType);
                }

                string lTypeTags = MotionTypeTagsAttribute.GetTypeTags(lType);

                MotionSelectType lItem = new MotionSelectType();
                lItem.Type = lType;
                lItem.Path = lType.Name + ".cs";

                //string[] lFolders = System.IO.Directory.GetFiles(Application.dataPath, lItem.Path, System.IO.SearchOption.AllDirectories);
                //if (lFolders.Length > 0) { lItem.Path = lFolders[0]; }

                lItem.Name         = lName;
                lItem.Description  = lDescription;
                lItem.TypeTags     = lTypeTags;
                lItem.TypeTagArray = lTypeTags.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                rTypes.Add(lItem);

                //// Create the type tags
                //if (lItem.TypeTagArray != null)
                //{
                //    for (int j = 0; j < lItem.TypeTagArray.Length; j++)
                //    {
                //        bool lIsFound = false;
                //        for (int k = 0; k < rTypeTags.Count; k++)
                //        {
                //            if (string.Compare(rTypeTags[k].Tag, lItem.TypeTagArray[j], true) == 0)
                //            {
                //                lIsFound = true;
                //                break;
                //            }
                //        }

                //        if (!lIsFound)
                //        {
                //            MotionSelectTypeTag lTypeTag = new MotionSelectTypeTag();
                //            lTypeTag.Tag = lItem.TypeTagArray[j];

                //            rTypeTags.Add(lTypeTag);
                //        }
                //    }
                //}
            }

            return(rTypes.Count);
        }