예제 #1
0
파일: TypeBaseApi.cs 프로젝트: E01D/Base
        private SemanticAttribute CreateAttribute(object categorizedAttribute, TTypeElement element)
        {
            SemanticAttribute attribute = XNew.New <SemanticAttribute>();

            attribute.RuntimeMapping = categorizedAttribute;

            return(attribute);
        }
예제 #2
0
        public override SemanticPointer CreateNewElement(SemanticModel_I model, Type type)
        {
            SemanticPointer element = XNew.New <SemanticPointer>();

            element.RuntimeMapping = type.TypeHandle;

            return(element);
        }
예제 #3
0
파일: ArrayApi.cs 프로젝트: E01D/Base
        public override SemanticArray CreateNewElement(SemanticModel_I model, Type type)
        {
            SemanticArray element = XNew.New <SemanticArray>();



            return(element);
        }
예제 #4
0
        public bool IssueId <T>(IdContext_I context, out T id)
            where T : Identifier_I
        {
            lock (context.SyncRoot)
            {
                id = XNew.New <T>();

                return(IssueId <T>(context, id));
            }
        }
예제 #5
0
파일: ApiApi.cs 프로젝트: 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);
                    }
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Gets an instance of an object of the type TPhenotype.  If one is not present, it creates one of type TGenotype.
        /// </summary>
        /// <typeparam name="TPhenotype"></typeparam>
        /// <typeparam name="TGenotype"></typeparam>
        /// <param name="container"></param>
        /// <returns></returns>
        public TPhenotype Get <TPhenotype, TGenotype>(BasicIocContainer_I container)
            where TGenotype : TPhenotype
        {
            lock (container.SyncRoot)
            {
                if (Get(container, out TPhenotype result))
                {
                    return(result);
                }

                var objectToAdd = XNew.New <TGenotype>();

                Add(container, typeof(TPhenotype), objectToAdd);

                return(objectToAdd);
            }
        }
예제 #7
0
파일: TypeBaseApi.cs 프로젝트: E01D/Base
        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);
            }
        }
예제 #8
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);
        }
예제 #9
0
        public bool Get <TPhenotype, TGenotype>(BasicIocContainer_I container, out TPhenotype phenotype)
            where TGenotype : TPhenotype
        {
            lock (container.SyncRoot)
            {
                if (Get(container, out TPhenotype result))
                {
                    phenotype = result;

                    return(true);
                }

                var objectToAdd = XNew.New <TGenotype>();

                Add(container, typeof(TPhenotype), objectToAdd);

                phenotype = objectToAdd;

                return(true);
            }
        }