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); } } } }
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); } }
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()); }
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); } } } }
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); }
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); }
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); }
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); } }
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); }
public bool IsClass(Type type) { return(XTypes.IsClass(type)); }
public bool IsDictionaryType(Type type) { return(XTypes.IsDictionaryType(type)); }
public bool IsAbstract(Type type) { return(XTypes.IsAbstract(type)); }
public bool IsEnum(Type type) { return(XTypes.IsEnum(type)); }
public bool AssignableToTypeName(Type type, string fullTypeName, bool searchInterfaces) { return(XTypes.AssignableToTypeName(type, fullTypeName, searchInterfaces)); }
public bool ImplementInterface(Type type, Type interfaceType) { return(XTypes.ImplementInterface(type, interfaceType)); }
private TypeId_I GetTypeId(Type type) { return(XTypes.GetTypeId(type)); }
public Assembly Assembly(Type type) { return(XTypes.Assembly(type)); }
public bool IsPrimitive(Type type) { return(XTypes.IsPrimitive(type)); }
public object GetApi <T>() { var typeId = XTypes.GetTypeId <T>(); return(typeId.Value == 0 ? null : GetApi(typeId)); }
public bool IsGenericType(Type type) { return(XTypes.IsGenericType(type)); }
public bool ContainsGenericParameters(Type type) { return(XTypes.ContainsGenericParameters(type)); }
public bool HasDefaultConstructor(Type type, bool nonPublic) { return(XTypes.HasDefaultConstructor(type, nonPublic)); }
public bool IsValueType(Type type) { return(XTypes.IsValueType(type)); }
public bool IsVisible(Type type) { return(XTypes.IsVisible(type)); }
public bool IsSealed(Type type) { return(XTypes.IsSealed(type)); }
public bool IsGenericTypeDefinition(Type type) { return(XTypes.IsGenericTypeDefinition(type)); }
public bool IsInterface(Type type) { return(XTypes.IsInterface(type)); }
public Type BaseType(Type type) { return(XTypes.BaseType(type)); }