Example #1
0
 /// <summary>
 /// Trys to get the specified Type with the typeName, if the ExpressType does not exist false is returned
 /// </summary>
 /// <param name="typeName"></param>
 /// <param name="expressType"></param>
 /// <returns></returns>
 public bool TryGetExpressType(string typeName, out ExpressType expressType)
 {
     return(_typeNameToExpressTypeLookup.TryGetValue(typeName, out expressType) ||
            _persistNameToExpressTypeLookup.TryGetValue(typeName, out expressType));
 }
Example #2
0
        private ExpressMetaData(Module module)
        {
            Module = module;
            var typesToProcess =
                module.GetTypes().Where(
                    t =>
                    typeof(IPersist).IsAssignableFrom(t) && t != typeof(IPersist) && !t.IsEnum && !t.IsInterface &&//!t.IsAbstract &&
                    t.IsPublic && !typeof(IExpressHeaderType).IsAssignableFrom(t)).ToList();

            _typeIdToExpressTypeLookup      = new Dictionary <short, ExpressType>(typesToProcess.Count);
            _typeNameToExpressTypeLookup    = new Dictionary <string, ExpressType>(typesToProcess.Count);
            _persistNameToExpressTypeLookup = new Dictionary <string, ExpressType>(typesToProcess.Count);
            _typeToExpressTypeLookup        = new ExpressTypeDictionary();
            _interfaceToExpressTypesLookup  = new Dictionary <Type, List <ExpressType> >();

            try
            {
                // System.Diagnostics.Debug.Write(typesToProcess.Count());
                foreach (var typeToProcess in typesToProcess)
                {
                    // Debug.WriteLine(typeToProcess.ToString());
                    ExpressType expressTypeToProcess;
                    if (!_typeToExpressTypeLookup.TryGetValue(typeToProcess, out expressTypeToProcess))
                    {
                        expressTypeToProcess = new ExpressType(typeToProcess);
                    }

                    var typeLookup = typeToProcess.Name.ToUpperInvariant();
                    if (!_typeNameToExpressTypeLookup.ContainsKey(typeLookup))
                    {
                        _typeNameToExpressTypeLookup.Add(typeLookup, expressTypeToProcess);
                    }

                    if (typeof(IPersistEntity).IsAssignableFrom(typeToProcess))
                    {
                        _persistNameToExpressTypeLookup.Add(expressTypeToProcess.ExpressNameUpper, expressTypeToProcess);
                        _typeIdToExpressTypeLookup.Add(expressTypeToProcess.TypeId, expressTypeToProcess);
                    }

                    if (!_typeToExpressTypeLookup.ContainsKey(expressTypeToProcess.Type))
                    {
                        _typeToExpressTypeLookup.Add(expressTypeToProcess.Type, expressTypeToProcess);
                        AddParent(expressTypeToProcess);
                    }

                    // populate the dictionary lookup by interface
                    foreach (var interfaceFound in typeToProcess.GetInterfaces())
                    {
                        if (interfaceFound.Namespace != null && !interfaceFound.Namespace.StartsWith("Xbim"))
                        {
                            continue;
                        }
                        if (!_interfaceToExpressTypesLookup.ContainsKey(interfaceFound))
                        {
                            // add to dictionary
                            _interfaceToExpressTypesLookup.Add(interfaceFound, new List <ExpressType>());
                        }
                        _interfaceToExpressTypesLookup[interfaceFound].Add(expressTypeToProcess);
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error reading Entity Meta Data", e);
            }
        }