Ejemplo n.º 1
0
            public TypeData(Type type)
            {
                this.Component = type;

                this.RequiredBy = new List <Type>();
                {
                    foreach (Type cmp in DualityApp.GetAvailDualityTypes(typeof(Component)))
                    {
                        if (RequiresComponent(cmp, type))
                        {
                            this.RequiredBy.Add(cmp);
                        }
                    }
                }

                this.Requirements = new List <Type>();
                {
                    IEnumerable <RequiredComponentAttribute> attribs =
                        type.GetCustomAttributes(typeof(RequiredComponentAttribute), true).
                        Cast <RequiredComponentAttribute>();
                    foreach (RequiredComponentAttribute a in attribs)
                    {
                        Type reqType = a.RequiredComponentType;
                        if (reqType == type)
                        {
                            continue;                                          // Don't require itself
                        }
                        this.Requirements.AddRange(GetRequiredComponents(reqType).Where(t => !this.Requirements.Contains(t)));
                        this.Requirements.Add(reqType);
                    }
                }
            }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns the Resource file extension for a specific Resource Type.
        /// </summary>
        /// <param name="resType">The Resource Type to return the file extension from.</param>
        /// <returns>The specified Resource Type's file extension.</returns>
        //public static string GetFileExtByType(Type resType)
        //{
        //    if (resType == null || resType == typeof(Resource))
        //        return FileExt;
        //    else
        //        return "." + resType.Name + FileExt;
        //}
        /// <summary>
        /// Returns the Resource file extension for a specific Resource Type.
        /// </summary>
        /// <param name="resType">The Resource Type to return the file extension from.</param>
        /// <returns>The specified Resource Type's file extension.</returns>
        //public static string GetFileExtByType<T>() where T : Resource
        //{
        //    if (typeof(T) == typeof(Resource))
        //        return FileExt;
        //    else
        //        return "." + typeof(T).Name + FileExt;
        //}
        /// <summary>
        /// Returns the Resource Type that is associated with the specified file, based on its extension.
        /// </summary>
        /// <param name="filePath">Path to the file of whichs Resource Type will be returned</param>
        /// <returns>The Resource Type of the specified file</returns>
        public static Type GetTypeByFileName(string filePath)
        {
            // Early-out if we don't have a valid resource path
            if (string.IsNullOrEmpty(filePath) || ContentProvider.IsDefaultContentPath(filePath))
            {
                return(null);
            }

            // Determine the (double) extension of the resource path
            filePath = PathOp.GetFileNameWithoutExtension(filePath);
            string[] token = filePath.Split('.');
            if (token.Length < 2)
            {
                return(null);
            }

            // Extract the type extension and match it with the available resource types
            string   typeName     = token[token.Length - 1];
            TypeInfo matchingInfo =
                DualityApp.GetAvailDualityTypes(typeof(Resource))
                .FirstOrDefault(t => t.Name == typeName);

            if (matchingInfo == null)
            {
                return(null);
            }

            // Return the result
            return(matchingInfo.AsType());
        }
 /// <summary>
 /// Gathers all currently available <see cref="Component"/> types and stores them inside
 /// the provided collection. This will iterate over all relevant core and core plugin types
 /// that are currently known, but since users can load plugins at any time, this list
 /// should never assumed to be final.
 /// </summary>
 /// <param name="typeSet"></param>
 private static void GatherComponentTypes(HashSet <Type> typeSet)
 {
     foreach (TypeInfo typeInfo in DualityApp.GetAvailDualityTypes(typeof(Component)))
     {
         if (typeInfo.IsAbstract)
         {
             continue;
         }
         typeSet.Add(typeInfo.AsType());
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Returns the Resource Type that is associated with the specified file, based on its extension.
 /// </summary>
 /// <param name="filePath">Path to the file of whichs Resource Type will be returned</param>
 /// <returns>The Resource Type of the specified file</returns>
 public static Type GetTypeByFileName(string filePath)
 {
     if (string.IsNullOrEmpty(filePath) || ContentProvider.IsDefaultContentPath(filePath))
     {
         return(null);
     }
     filePath = System.IO.Path.GetFileNameWithoutExtension(filePath);
     string[] token = filePath.Split('.');
     if (token.Length < 2)
     {
         return(null);
     }
     return(DualityApp.GetAvailDualityTypes(typeof(Resource)).FirstOrDefault(t => t.Name == token[token.Length - 1]));
 }
Ejemplo n.º 5
0
 public void InitRequiredBy()
 {
     if (this.RequiredBy != null)
     {
         return;
     }
     this.RequiredBy = new List <Type>();
     foreach (Type cmp in DualityApp.GetAvailDualityTypes(typeof(Component)))
     {
         if (cmp == this.Component)
         {
             continue;                                            // Don't require itself
         }
         if (RequiresComponent(cmp, this.Component))
         {
             this.RequiredBy.Add(cmp);
         }
     }
 }