Exemple #1
0
        public SemanticType_I GetOrCreateElement(SemanticModel_I model, Type type)
        {
            //SemanticType_I typeSymbol;

            if (XTypes.IsClass(type))
            {
                // Get the long id associated with the type handle; by having this abstraction the semantic model can be built without having to
                // rely on runtime types.  Runtime types though can still be mapped to the semantic model.
                return(Classes.GetOrCreateElement(model, type));
            }
            else if (XTypes.IsInterface(type))
            {
                // Get the long id associated with the type handle; by having this abstraction the semantic model can be built without having to
                // rely on runtime types.  Runtime types though can still be mapped to the semantic model.
                return(Interfaces.GetOrCreateElement(model, type));
            }
            else if (XTypes.IsEnum(type))
            {
                // Get the long id associated with the type handle; by having this abstraction the semantic model can be built without having to
                // rely on runtime types.  Runtime types though can still be mapped to the semantic model.
                return(Enums.GetOrCreateElement(model, type));
            }
            else if (XTypes.IsValueType(type))
            {
                // Get the long id associated with the type handle; by having this abstraction the semantic model can be built without having to
                // rely on runtime types.  Runtime types though can still be mapped to the semantic model.
                return(ValueTypes.GetOrCreateElement(model, type));
            }
            else if (XTypes.IsDelegate(type))
            {
                // Get the long id associated with the type handle; by having this abstraction the semantic model can be built without having to
                // rely on runtime types.  Runtime types though can still be mapped to the semantic model.
                return(Delegates.GetOrCreateElement(model, type));
            }
            else if (XTypes.IsArray(type))
            {
                // Get the long id associated with the type handle; by having this abstraction the semantic model can be built without having to
                // rely on runtime types.  Runtime types though can still be mapped to the semantic model.
                return(Arrays.GetOrCreateElement(model, type));
            }
            else if (XTypes.IsPointer(type))
            {
                // Get the long id associated with the type handle; by having this abstraction the semantic model can be built without having to
                // rely on runtime types.  Runtime types though can still be mapped to the semantic model.
                return(Pointers.GetOrCreateElement(model, type));
            }
            else
            {
                XLog.LogWarning(new CannotMatchQualifiedNameToClassLogMessage()
                {
                    Message = new Message()
                    {
                        Value = $"Could not match type '{type.AssemblyQualifiedName}' to an class, interface, enum, struct, delegate, array or pointer.  Could not add it to the semantic model on scan."
                    }
                });

                return(null);
            }
        }
Exemple #2
0
        private void AddInterfacesOnElementCreate(SemanticModel_I semanticModel, TTypeElement element, Type type)
        {
            if (XTypes.IsClass(type) || XTypes.IsInterface(type))
            {
                Type[] interfaces = type.GetInterfaces();

                List <Type> interfaceQueue = new List <Type>();

                interfaceQueue.AddRange(interfaces);

                if (type.Name == "UserSqlDataLayer")
                {
                }

                //for (var baseType = type.BaseType; baseType != null; baseType = baseType?.BaseType)
                //{
                //    if (baseType == null) continue;

                //    interfaces = baseType.GetInterfaces();

                //    interfaceQueue.AddRange(interfaces);
                //}

                Dictionary <RuntimeTypeHandle, Type> seenTypes = new Dictionary <RuntimeTypeHandle, Type>();

                while (interfaceQueue.Count > 0)
                {
                    var activeInterfaces = interfaceQueue.ToArray();

                    interfaceQueue.Clear();

                    // ReSharper disable once ForCanBeConvertedToForeach
                    for (var i = 0; i < activeInterfaces.Length; i++)
                    {
                        var interfaceType = activeInterfaces[i];

                        if (seenTypes.ContainsKey(interfaceType.TypeHandle))
                        {
                            continue;
                        }

                        seenTypes.Add(interfaceType.TypeHandle, interfaceType);

                        AddInterface(semanticModel, element, interfaceType);

                        if (interfaceType.IsGenericType)
                        {
                            var interfaceGenericTypeDefinition = interfaceType.GetGenericTypeDefinition();

                            AddInterface(semanticModel, element, interfaceGenericTypeDefinition);
                        }

                        interfaces = type.GetInterfaces();

                        interfaceQueue.AddRange(interfaces);
                    }
                }
            }
        }
Exemple #3
0
 public bool IsInterface(Type type)
 {
     return(XTypes.IsInterface(type));
 }