GetAllDerivedTypes() public static method

Get all derived non-abstract types of specified base type from all loaded assemblies.
public static GetAllDerivedTypes ( this baseType, bool>.Func addtionalFilter = null ) : List
baseType this
addtionalFilter bool>.Func addtional filter.
return List
Esempio n. 1
0
        private object GetVariable <T>(T value, string varNameInShader)
        {
            Type t = value.GetType();
            Type varType;

            if (variableDict == null)
            {
                variableDict = new Dictionary <Type, Type>();
                var types = AssemblyHelper.GetAllDerivedTypes(
                    typeof(UniformSingleVariableBase), x => !x.IsAbstract);
                foreach (var item in types)
                {
                    try
                    {
                        // example: variableDict.Add(typeof(int), typeof(UniformInt32));
                        variableDict.Add(item.GetProperty("Value").PropertyType, item);
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            if (variableDict.TryGetValue(t, out varType))
            {
                return(Activator.CreateInstance(varType, varNameInShader));
            }
            else
            {
                throw new Exception(string.Format(
                                        "UniformVariable type [{0}] doesn't exists or not included in the variableDict!",
                                        t));
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="value"></param>
        /// <param name="varNameInShader"></param>
        /// <returns></returns>
        private object GetVariableArray(Array value, string varNameInShader)
        {
            Type t = value.GetType().GetElementType();
            Type varType;

            if (variableArrayDict == null)
            {
                variableArrayDict = new Dictionary <Type, Type>();
                var types = AssemblyHelper.GetAllDerivedTypes(
                    typeof(UniformArrayVariableBase), x => !x.IsAbstract);
                foreach (var item in types)
                {
                    try
                    {
                        // example: variableArrayDict.Add(typeof(float), typeof(UniformFloatArray));
                        variableArrayDict.Add(item.BaseType.GetGenericArguments()[0], item);
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            if (variableArrayDict.TryGetValue(t, out varType))
            {
                return(Activator.CreateInstance(varType, varNameInShader, value.Length));
            }
            else
            {
                throw new Exception(string.Format(
                                        "UniformVariable type [{0}] doesn't exists or not included in the variableDict!",
                                        t));
            }
        }