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 override SemanticArray CreateNewElement(SemanticModel_I model, Type type) { SemanticArray element = XNew.New <SemanticArray>(); return(element); }
public override SemanticPointer CreateNewElement(SemanticModel_I model, Type type) { SemanticPointer element = XNew.New <SemanticPointer>(); element.RuntimeMapping = type.TypeHandle; return(element); }
public TTypeElement CreateElement(SemanticModel_I semanticModel, System.Type type) { var element = CreateNewElement(semanticModel, type); element.RuntimeMapping = type.TypeHandle; element.TypeId = GetTypeId(type); OnCreateElement(semanticModel, element, type); return(element); }
private TTypeElement CreateAndAddElement(SemanticModel_I semanticModel, Type type, RuntimeTypeHandle typeHandle, Dictionary <long, TTypeElement> storage) { TTypeElement element = CreateElement(semanticModel, type); AddElement(semanticModel, typeHandle, storage, element); AddCustomElementsOnElementCreate(semanticModel, element, type); AddInterfacesOnElementCreate(semanticModel, element, type); return(element); }
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 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); }
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); }
private void AddInterface(SemanticModel_I semanticModel, SemanticType_I implementingTypeSymbol, Type interfaceType) { var interfaceElement = (SemanticInterface_I)semanticModel.GetOrCreateElement(interfaceType); if (implementingTypeSymbol != null) { if (implementingTypeSymbol.IsClass()) { if (!interfaceElement.ImplementingClasses.TryGetValue(implementingTypeSymbol.TypeId.Value, out SemanticClass_I classSymbol)) { classSymbol = (SemanticClass_I)implementingTypeSymbol; interfaceElement.ImplementingClasses.Add(classSymbol.TypeId.Value, classSymbol); } } if (!interfaceElement.ImplementingTypes.TryGetValue(implementingTypeSymbol.TypeId.Value, out SemanticType_I existingTypeSymbol)) { interfaceElement.ImplementingTypes.Add(implementingTypeSymbol.TypeId.Value, implementingTypeSymbol); } } }
//public static bool GetTypeHandle(this SemanticModel_I model, long id, out RuntimeTypeHandle typeHandle) //{ // return XSemanticMetadata.Api.Models.GetTypeHandle(model, id, out typeHandle); //} //public static bool GetTypeId(this SemanticModel_I model, RuntimeTypeHandle typeHandle, out TypeId_I id) //{ // return XSemanticMetadata.Api.Models.GetId(model, typeHandle, out id); //} public static SemanticType_I GetOrCreateElement(this SemanticModel_I model, Type type) { return(XSemanticMetadata.Api.Elements.GetOrCreateElement(model, type)); }
public override Dictionary <long, SemanticPointer> GetModelStorage(SemanticModel_I model) { return(model.Pointers); }
public override Dictionary <long, SemanticClass> GetModelStorage(SemanticModel_I model) { return(model.Classes); }
public override Dictionary <long, SemanticValueType> GetModelStorage(SemanticModel_I model) { return(model.ValueTypes); }
public SemanticClass_I GetOrCreateClass(SemanticModel_I model, Type type) { return(XSemanticMetadata.Api.Elements.Classes.GetOrCreateElement(model, type)); }
public void AddElement(SemanticModel_I semanticModel, RuntimeTypeHandle typeHandle, Dictionary <long, TTypeElement> storage, TTypeElement classElement) { storage.Add(classElement.TypeId.Value, classElement); semanticModel.Types.Add(classElement.TypeId.Value, classElement); }
public SemanticInterface_I GetOrCreateInterface(SemanticModel_I model, Type type) { return(XSemanticMetadata.Api.Elements.Interfaces.GetOrCreateElement(model, type)); }
public abstract void OnCreateElement(SemanticModel_I semanticModel, TTypeElement element, Type type);
public override Dictionary <long, SemanticEnum> GetModelStorage(SemanticModel_I model) { return(model.Enums); }
public abstract TTypeElement CreateNewElement(SemanticModel_I model, System.Type type);
public SemanticEnum_I GetOrCreateEnum(SemanticModel_I model, Type type) { return(XSemanticMetadata.Api.Elements.Enums.GetOrCreateElement(model, type)); }
public SemanticValueType_I GetOrCreateValueType(SemanticModel_I model, Type type) { return(XSemanticMetadata.Api.Elements.ValueTypes.GetOrCreateElement(model, type)); }
public SemanticPointer_I GetOrCreatePointer(SemanticModel_I model, Type type) { return(XSemanticMetadata.Api.Elements.Pointers.GetOrCreateElement(model, type)); }
public SemanticArray_I GetOrCreateArray(SemanticModel_I model, Type type) { return(XSemanticMetadata.Api.Elements.Arrays.GetOrCreateElement(model, type)); }
public SemanticDelegate_I GetOrCreateDelegate(SemanticModel_I model, Type type) { return(XSemanticMetadata.Api.Elements.Delegates.GetOrCreateElement(model, type)); }
public override void OnCreateElement(SemanticModel_I semanticModel, SemanticPointer element, Type type) { }
public override Dictionary <long, SemanticDelegate> GetModelStorage(SemanticModel_I model) { return(model.Delegates); }
public abstract Dictionary <long, TTypeElement> GetModelStorage(SemanticModel_I model);
public override void OnCreateElement(SemanticModel_I semanticModel, SemanticValueType element, Type type) { }