Exemple #1
0
        public virtual System.Type GetElementType(System.Type p_type)
        {
            System.Type v_returnedType = null;
            if (p_type != null)
            {
                if (p_type.IsArray)
                {
                    v_returnedType = p_type.GetElementType();
                }
                else if (TypeExtension.IsSameOrSubClassOrImplementInterface(p_type, typeof(IArrayList)))
                {
                    v_returnedType = p_type;
                    string v_typeSafeName = v_returnedType != null ? v_returnedType.FullName : "";
                    while (v_returnedType != null && !v_typeSafeName.Contains("ArrayList`1"))
                    {
                        v_returnedType = v_returnedType.BaseType;
                        v_typeSafeName = v_returnedType != null ? v_returnedType.FullName : "";
                    }
                    try
                    {
                        v_returnedType = v_returnedType.GetGenericArguments()[0];
                    }
                    catch { v_returnedType = null; }
                }
                else
                {
                    System.Type[] v_interfaceTypes = p_type.GetInterfaces();
                    foreach (System.Type v_interfaceType in v_interfaceTypes)
                    {
                        string v_interfaceSafeName = v_interfaceType != null ? v_interfaceType.FullName : ""; //SerializableTypeCache.GetSafeTypedNameInAssembly(v_interfaceType);
                        if (v_interfaceSafeName.Contains("IList`1") ||
                            v_interfaceSafeName.Contains("ICollection`1") ||
                            v_interfaceSafeName.Contains("IEnumerable`1"))

                        {
                            try
                            {
                                v_returnedType = v_interfaceType.GetGenericArguments()[0];
                                break;
                            }
                            catch { }
                        }
                    }
                }
            }
            return(v_returnedType);
        }
Exemple #2
0
 private bool AssemblyContainsFilteredType(Assembly p_assembly, SerializableType p_filterType, bool p_acceptGenericDefinition, bool p_acceptAbstractDefinition)
 {
     if (p_filterType == null || p_filterType.CastedType == null)
     {
         return(true);
     }
     if (p_assembly != null)
     {
         string v_safeTypeNameInAssembly = GetSafeTypedNameInAssembly(p_filterType);
         foreach (System.Type v_type in p_assembly.GetTypes())
         {
             if (v_type != null &&
                 p_filterType != null &&
                 (TypeExtension.IsSameOrSubClassOrImplementInterface(v_type, p_filterType.CastedType) ||
                  v_type.FullName.Contains(v_safeTypeNameInAssembly)) &&
                 (p_acceptGenericDefinition || !v_type.IsGenericTypeDefinition) &&
                 (p_acceptAbstractDefinition || !v_type.IsAbstract))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemple #3
0
        protected virtual void BuildCache()
        {
            System.Type v_safeFilterType         = m_filterType == null ? (m_acceptAbstract ? typeof(object) : null) : m_filterType;
            string      v_safeTypeNameInAssembly = GetSafeTypedNameInAssembly(v_safeFilterType);
            ArrayDict <Assembly, System.Type[]> v_assemblyTypesDict = AssemblyUtils.GetAssemblyTypesDict(false);
            List <Assembly> v_assemblies = new List <Assembly>();

            m_currentAssembly = m_currentType == null || m_currentType.CastedType == null ? null : m_currentType.CastedType.Assembly;

            //Filter Assemblies
            foreach (KVPair <Assembly, System.Type[]> v_pair in v_assemblyTypesDict)
            {
                if (v_pair != null && v_pair.Key != null)
                {
                    if (AssemblyContainsFilteredType(v_pair.Key, m_filterType, m_acceptGeneric, m_acceptAbstract))
                    {
                        v_assemblies.Add(v_pair.Key);
                    }
                    try
                    {
                        if (m_currentAssembly == null && m_currentType != null && ((SerializableType)m_currentType).StringType.Contains(v_pair.Key.FullName))
                        {
                            m_currentAssembly = v_pair.Key;
                        }
                    }
                    catch { }
                }
            }
            if (m_acceptNull)
            {
                v_assemblies.Insert(0, null);
            }

            if (m_currentAssembly == null && !m_acceptNull)
            {
                m_currentAssembly = v_safeFilterType.Assembly;
            }

            //Draw Popup Select Assembly
            m_possibleAssemblies       = v_assemblies.ToArray();
            m_possibleAssembliesString = v_assemblies.GetStringList().ToArray();
            m_selectedAssemblyIndex    = v_assemblies.Contains(m_currentAssembly) ? v_assemblies.IndexOf(m_currentAssembly) : -1;

            //Pick All Types if dont use Assembly Filter
            List <System.Type> v_assemblyTypes = new List <System.Type>();

            foreach (var v_assembly in v_assemblies)
            {
                try
                {
                    var v_types = v_assemblyTypesDict.GetValueWithKey(v_assembly);
                    if (v_types != null)
                    {
                        foreach (System.Type v_type in v_types)
                        {
                            if (v_type != null &&
                                (!v_type.IsGenericTypeDefinition || m_acceptGeneric) &&
                                (!v_type.IsAbstract || m_acceptAbstract) &&
                                (m_filterType == null ||
                                 TypeExtension.IsSameOrSubClassOrImplementInterface(v_type, m_filterType) ||
                                 v_type.FullName.Contains(v_safeTypeNameInAssembly)))
                            {
                                v_assemblyTypes.Add(v_type);
                            }
                        }
                    }
                }
                catch { }
            }

            if (m_acceptNull)
            {
                v_assemblyTypes.Insert(0, null);
            }
            m_possibleTypesInAllAssemblies       = v_assemblyTypes.ToArray();
            m_possibleTypesInAllAssembliesString = v_assemblyTypes.GetStringList().ToArray();
            if (m_currentType == null && !m_acceptNull)
            {
                m_selectedTypeIndexInAllAssemblies = v_assemblyTypes.Contains(v_safeFilterType) ? v_assemblyTypes.IndexOf(v_safeFilterType) : -1;
            }
            else
            {
                m_selectedTypeIndexInAllAssemblies = v_assemblyTypes.Contains(m_currentType) ? v_assemblyTypes.IndexOf(m_currentType) : -1;
            }


            //Filter Types in Assembly Current Assembly
            v_assemblyTypes.Clear();
            if (m_currentAssembly != null)
            {
                try
                {
                    var v_types = v_assemblyTypesDict.GetValueWithKey(m_currentAssembly);
                    if (v_types != null)
                    {
                        foreach (System.Type v_type in v_types)
                        {
                            if (v_type != null &&
                                (!v_type.IsGenericTypeDefinition || m_acceptGeneric) &&
                                (!v_type.IsAbstract || m_acceptAbstract) &&
                                (m_filterType == null ||
                                 TypeExtension.IsSameOrSubClassOrImplementInterface(v_type, m_filterType) ||
                                 v_type.FullName.Contains(v_safeTypeNameInAssembly)))
                            {
                                v_assemblyTypes.Add(v_type);
                            }
                        }
                    }
                }
                catch { }
            }
            if (m_acceptNull)
            {
                v_assemblyTypes.Insert(0, null);
            }
            m_possibleTypesInCurrentAssembly       = v_assemblyTypes.ToArray();
            m_possibleTypesInCurrentAssemblyString = v_assemblyTypes.GetStringList().ToArray();
            if (m_currentType == null && !m_acceptNull)
            {
                m_selectedTypeIndexInCurrentAssembly = v_assemblyTypes.Contains(v_safeFilterType) ? v_assemblyTypes.IndexOf(v_safeFilterType) : -1;
            }
            else
            {
                m_selectedTypeIndexInCurrentAssembly = v_assemblyTypes.Contains(m_currentType) ? v_assemblyTypes.IndexOf(m_currentType) : -1;
            }
        }