Ejemplo n.º 1
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);
                    }
                }
            }
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
0
        public List <SemanticClass_I> GetImplementingClasses(SemanticModel_I model, Type type)
        {
            //TypalContextHost_I context = _.ContextAs<TypalContextHost_I>();

            var typeId = XTypes.GetTypeId(type);

            if (!model.Interfaces.TryGetValue(typeId.Value, out SemanticInterface symbol))
            {
                return(new List <SemanticClass_I>());
            }

            return(symbol.ImplementingClasses.Values.ToList());
        }
Ejemplo n.º 4
0
Archivo: ApiApi.cs Proyecto: E01D/Base
        public void LoadApis(System.Type interfaceType, Dictionary <long, object> dictionary)
        {
            TypalGlobalContext_I typal = XContextual.GetGlobal <TypalGlobalContext_I>();

            var y = XSemanticMetadata.Api.Elements.GetImplementingClasses(typal.Library.SemanticModel, interfaceType);

            foreach (var z in y)
            {
                var handle = XTypes.GetTypeHandle(z.TypeId);

                var type = System.Type.GetTypeFromHandle(handle);

                if (type.IsAbstract)
                {
                    continue;
                }

                if (type.ContainsGenericParameters)
                {
                    continue;
                }

                var implementedInterfaces = type.GetInterfaces();

                for (int i = 0; i < implementedInterfaces.Length; i++)
                {
                    //var implementedInterface = implementedInterfaces[i];

                    //if (!implementedInterface.IsGenericType) continue;

                    //var genericTypeDefinition = implementedInterface.GetGenericTypeDefinition();

                    //if (genericTypeDefinition != interfaceType) continue;

                    var instance = XNew.New(type);

                    //var arguments = implementedInterface.GenericTypeArguments;

                    //if (arguments.Length != 1) continue;

                    //XTypal.Api.Types.

                    if (!dictionary.ContainsKey(z.TypeId.Value))
                    {
                        dictionary.Add(z.TypeId.Value, instance);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public DataLayerApi_I GetApiForModel <T>()
        {
            var context = XContextual.GetGlobal <DataGlobalContext_I>();

            DataLayerApi_I api = null;

            var modelTypeId = XTypes.GetTypeId(typeof(T));

            if (context.DataApisByModelType.TryGetValue(modelTypeId.Value, out object apiObject))
            {
                api = (DataLayerApi_I)apiObject;
            }

            return(api);
        }
Ejemplo n.º 6
0
        public TTypeElement GetOrCreateElement(SemanticModel_I semanticModel, System.Type type)
        {
            TTypeElement typeElement;

            var storage = GetModelStorage(semanticModel);

            var typeHandle = type.TypeHandle;

            var typeId = XTypes.GetTypeId(type);

            if (!storage.TryGetValue(typeId.Value, out typeElement))
            {
                typeElement = CreateAndAddElement(semanticModel, type, typeHandle, storage);
            }

            return(typeElement);
        }
Ejemplo n.º 7
0
        public void LoadApis()
        {
            var context = XContextual.GetGlobal <DataGlobalContext_I>();

            var dictionary = context.DataApis;

            XApis.Api.LoadApis(typeof(DataLayerApi_I), dictionary);

            foreach (var keyPair in dictionary)
            {
                var value = keyPair.Value;

                var type = value.GetType();

                var interfaces = type.GetInterfaces();

                var apiType = typeof(BasicLayerApi_I <>);

                for (int i = 0; i < interfaces.Length; i++)
                {
                    var interface1 = interfaces[i];

                    if (!interface1.IsGenericType)
                    {
                        continue;
                    }

                    if (interface1.GetGenericTypeDefinition() == apiType)
                    {
                        var args = interface1.GenericTypeArguments;

                        var modelType = args[0];

                        var modelTypeId = XTypes.GetTypeId(modelType);

                        context.DataApisByModelType.Add(modelTypeId.Value, keyPair.Value);
                    }
                }
            }

            //XApis.LoadAttributedApis(typeof(DataApiAttribute), dictionary);
        }
Ejemplo n.º 8
0
        private void AddCustomElementsOnElementCreate(SemanticModel_I semanticModel, TTypeElement element, Type type)
        {
            // put all of this into semantic model code base.
            object[] categorizedAttributes = XTypes.GetCustomAttributes(type);

            for (int i = 0; i < categorizedAttributes.Length; i++)
            {
                var categorizedAttribute = categorizedAttributes[i];

                var attributeType = categorizedAttribute.GetType();

                var attributeClass = (SemanticAttributeClass)semanticModel.GetOrCreateElement(attributeType);

                if (!attributeClass.ImplementingTypes.ContainsKey(element.TypeId.Value))
                {
                    attributeClass.ImplementingTypes.Add(element.TypeId.Value, element);
                }

                if (element.IsClass())
                {
                    if (!attributeClass.ImplementingClasses.ContainsKey(element.TypeId.Value))
                    {
                        attributeClass.ImplementingClasses.Add(element.TypeId.Value, (SemanticClass_I)element);
                    }
                }

                if (element.IsInterface())
                {
                    if (!attributeClass.ImplementingInterfaces.ContainsKey(element.TypeId.Value))
                    {
                        attributeClass.ImplementingInterfaces.Add(element.TypeId.Value, (SemanticInterface_I)element);
                    }
                }

                SemanticAttributeTypeMapping mapping = XNew.New <SemanticAttributeTypeMapping>();
                mapping.ImplementingType = element;
                mapping.AttributeClass   = attributeClass;
                mapping.Instance         = categorizedAttribute;

                attributeClass.Instances.Add(mapping);
            }
        }
Ejemplo n.º 9
0
        public override SemanticClass CreateNewElement(SemanticModel_I model, Type type)
        {
            SemanticClass element;

            // if it is an attribute then we want to create an attribute class, that can hold more information about what types implement the attribute.
            if (XTypes.IsAttribute(type))
            {
                // already know it does not exist in the model as it is being called from a get or create statement (at initial version)
                SemanticAttributeClass attributeClass = XNew.New <SemanticAttributeClass>();

                element = attributeClass;
            }
            else
            {
                element = XNew.New <SemanticClass>();
            }

            element.RuntimeMapping = type.TypeHandle;

            return(element);
        }
Ejemplo n.º 10
0
 public bool IsClass(Type type)
 {
     return(XTypes.IsClass(type));
 }
Ejemplo n.º 11
0
 public bool IsDictionaryType(Type type)
 {
     return(XTypes.IsDictionaryType(type));
 }
Ejemplo n.º 12
0
 public bool IsAbstract(Type type)
 {
     return(XTypes.IsAbstract(type));
 }
Ejemplo n.º 13
0
 public bool IsEnum(Type type)
 {
     return(XTypes.IsEnum(type));
 }
Ejemplo n.º 14
0
 public bool AssignableToTypeName(Type type, string fullTypeName, bool searchInterfaces)
 {
     return(XTypes.AssignableToTypeName(type, fullTypeName, searchInterfaces));
 }
Ejemplo n.º 15
0
 public bool ImplementInterface(Type type, Type interfaceType)
 {
     return(XTypes.ImplementInterface(type, interfaceType));
 }
Ejemplo n.º 16
0
 private TypeId_I GetTypeId(Type type)
 {
     return(XTypes.GetTypeId(type));
 }
Ejemplo n.º 17
0
 public Assembly Assembly(Type type)
 {
     return(XTypes.Assembly(type));
 }
Ejemplo n.º 18
0
 public bool IsPrimitive(Type type)
 {
     return(XTypes.IsPrimitive(type));
 }
Ejemplo n.º 19
0
        public object GetApi <T>()
        {
            var typeId = XTypes.GetTypeId <T>();

            return(typeId.Value == 0 ? null : GetApi(typeId));
        }
Ejemplo n.º 20
0
 public bool IsGenericType(Type type)
 {
     return(XTypes.IsGenericType(type));
 }
Ejemplo n.º 21
0
 public bool ContainsGenericParameters(Type type)
 {
     return(XTypes.ContainsGenericParameters(type));
 }
Ejemplo n.º 22
0
 public bool HasDefaultConstructor(Type type, bool nonPublic)
 {
     return(XTypes.HasDefaultConstructor(type, nonPublic));
 }
Ejemplo n.º 23
0
 public bool IsValueType(Type type)
 {
     return(XTypes.IsValueType(type));
 }
Ejemplo n.º 24
0
 public bool IsVisible(Type type)
 {
     return(XTypes.IsVisible(type));
 }
Ejemplo n.º 25
0
 public bool IsSealed(Type type)
 {
     return(XTypes.IsSealed(type));
 }
Ejemplo n.º 26
0
 public bool IsGenericTypeDefinition(Type type)
 {
     return(XTypes.IsGenericTypeDefinition(type));
 }
Ejemplo n.º 27
0
 public bool IsInterface(Type type)
 {
     return(XTypes.IsInterface(type));
 }
Ejemplo n.º 28
0
 public Type BaseType(Type type)
 {
     return(XTypes.BaseType(type));
 }