Example #1
0
        //void Unbind(Type type);
        private static StackObject *Unbind_Types(ILIntepreter intp, StackObject *esp, IList <object> mStack,
                                                 CLRMethod method, bool isNewObj)
        {
            var genericArguments = method.GenericArguments;

            if (method.ParameterCount != 1)
            {
                throw new EntryPointNotFoundException();
            }

            ILRuntime.Runtime.Enviorment.AppDomain domain = intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(esp, 3);

            ptr_of_this_method = ILIntepreter.Minus(esp, 1);
            Type type = (System.Type) typeof(System.Type).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, domain, mStack));

            intp.Free(ptr_of_this_method);

            var tService = XILUtil.GetCatLibServiceName(type);

            XCore.MainInstance.Services.Unbind(tService);

            return(esp);
        }
Example #2
0
        //IBindData BindBuiltInService<TBuiltInService, TService, TConcrete>() where TBuiltInService : IBuiltInService;
        private static StackObject *BindBuiltInService_TBuiltInService_TService_TConcrete(ILIntepreter intp, StackObject *esp, IList <object> mStack, CLRMethod method, bool isNewObj)
        {
            var genericArguments = method.GenericArguments;

            if (genericArguments == null || genericArguments.Length != 3 || method.ParameterCount != 0)
            {
                throw new EntryPointNotFoundException();
            }

            var tBuildInService = XILUtil.ITypeToService(genericArguments[0]);
            var tService        = XILUtil.ITypeToService(genericArguments[1]);
            var tType           = XILUtil.ITypeToClrType(genericArguments[2]);

            ILRuntime.Runtime.Enviorment.AppDomain __domain = intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(esp, 1);
            TinaX.Container.IServiceContainer instance_of_this_method = (TinaX.Container.IServiceContainer) typeof(TinaX.Container.IServiceContainer).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, mStack));
            intp.Free(ptr_of_this_method);

            var result_of_this_method = instance_of_this_method.Bind(tBuildInService, tType, true).SetAlias(tService);

            return(ILIntepreter.PushObject(esp, mStack, result_of_this_method));
        }
Example #3
0
        //bool TryGetBuildInService(Type type, out object service);
        private static StackObject *TryGetBuildInService_Type(ILIntepreter intp, StackObject *esp, IList <object> mStack,
                                                              CLRMethod method, bool isNewObj)
        {
            var genericArguments = method.GenericArguments;

            if (method.ParameterCount != 2)
            {
                throw new EntryPointNotFoundException();
            }

            var ptrOfThisMethod = ILIntepreter.Minus(esp, 1);

            ptrOfThisMethod = ILIntepreter.GetObjectAndResolveReference(ptrOfThisMethod);

            var service =
                (object)typeof(object).CheckCLRTypes(StackObject.ToObject(ptrOfThisMethod, intp.AppDomain, mStack));

            ptrOfThisMethod = ILIntepreter.Minus(esp, 2);
            ptrOfThisMethod = ILIntepreter.GetObjectAndResolveReference(ptrOfThisMethod);
            var _type =
                (Type)typeof(Type).CheckCLRTypes(StackObject.ToObject(ptrOfThisMethod, intp.AppDomain, mStack));
            var tService = XILUtil.GetCatLibServiceName(_type);

            intp.Free(ptrOfThisMethod);
            var result = XCore.MainInstance.Services.TryGetBuildInService(tService, out service);

            ptrOfThisMethod = ILIntepreter.Minus(esp, 1);
            XILUtil.SetValue(ptrOfThisMethod, mStack, intp.AppDomain, service);

            return(ILIntepreter.PushObject(ILIntepreter.Minus(esp, 1), mStack, result));
        }
Example #4
0
        //bool SingletonIf<TService, TConcrete>(out IBindData bindData);
        private static StackObject *SingletonIf_TService_TConcrete_IBindData(ILIntepreter intp, StackObject *esp, IList <object> mStack,
                                                                             CLRMethod method, bool isNewObj)
        {
            var genericArguments = method.GenericArguments;

            if (genericArguments == null || genericArguments.Length != 2 || method.ParameterCount != 1)
            {
                throw new EntryPointNotFoundException();
            }

            var tService = XILUtil.ITypeToService(genericArguments[0]);
            var tType    = XILUtil.ITypeToClrType(genericArguments[1]);

            var ptrOfThisMethod = ILIntepreter.Minus(esp, 1);

            ptrOfThisMethod = ILIntepreter.GetObjectAndResolveReference(ptrOfThisMethod);

            var bindData =
                (IBindData)typeof(IBindData).CheckCLRTypes(
                    StackObject.ToObject(ptrOfThisMethod, intp.AppDomain, mStack));

            intp.Free(ptrOfThisMethod);

            var result = XCore.MainInstance.Services.BindIf(tService, tType, true, out bindData);

            ptrOfThisMethod = ILIntepreter.Minus(esp, 1);
            XILUtil.SetValue(ptrOfThisMethod, mStack, intp.AppDomain, bindData);

            return(ILIntepreter.PushObject(ILIntepreter.Minus(esp, 1), mStack, result));
        }
Example #5
0
        //bool TryGet<TService>(out TService service, params object[] userParams);
        private static StackObject *TryGet_TService_ArrObject(ILIntepreter intp, StackObject *esp, IList <object> mStack,
                                                              CLRMethod method, bool isNewObj)
        {
            var genericArguments = method.GenericArguments;

            if (genericArguments == null || genericArguments.Length != 1 || method.ParameterCount != 2)
            {
                throw new EntryPointNotFoundException();
            }

            var tService = XILUtil.ITypeToService(genericArguments[0]);

            var ptrOfThisMethod = ILIntepreter.Minus(esp, 1);

            ptrOfThisMethod = ILIntepreter.GetObjectAndResolveReference(ptrOfThisMethod);

            var userparams = (object[])typeof(object[]).CheckCLRTypes(
                StackObject.ToObject(ptrOfThisMethod, intp.AppDomain, mStack));

            ptrOfThisMethod = ILIntepreter.Minus(esp, 2);
            ptrOfThisMethod = ILIntepreter.GetObjectAndResolveReference(ptrOfThisMethod);
            var service =
                (object)typeof(ILTypeInstance).CheckCLRTypes(StackObject.ToObject(ptrOfThisMethod, intp.AppDomain, mStack));


            intp.Free(ptrOfThisMethod);

            var result = XCore.MainInstance.Services.TryGet(tService, out service, userparams);

            ptrOfThisMethod = ILIntepreter.Minus(esp, 2);
            XILUtil.SetValue(ptrOfThisMethod, mStack, intp.AppDomain, service);

            return(ILIntepreter.PushObject(ILIntepreter.Minus(esp, 1), mStack, result));
        }
Example #6
0
        //object Get(Type type, params object[] userParams);
        private static StackObject *Get_Type_ArrObject(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 3);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Object[] @userParams = (System.Object[]) typeof(System.Object[]).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            System.Type @type = (System.Type) typeof(System.Type).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 3);
            TinaX.Container.IServiceContainer instance_of_this_method = (TinaX.Container.IServiceContainer) typeof(TinaX.Container.IServiceContainer).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            string serviceName           = XILUtil.GetCatLibServiceName(@type);
            var    result_of_this_method = instance_of_this_method.Get(serviceName, @userParams);

            object obj_result_of_this_method = result_of_this_method;

            if (obj_result_of_this_method is CrossBindingAdaptorType)
            {
                return(ILIntepreter.PushObject(__ret, __mStack, ((CrossBindingAdaptorType)obj_result_of_this_method).ILInstance, true));
            }
            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method, true));
        }
Example #7
0
        public object CreateInstanceAndInject(Type type)
        {
            var ctors = type.GetConstructors(BindingFlags.Public | BindingFlags.Instance);

            //找到可注入的ctor
            foreach (var ctor in ctors)
            {
                var           ctor_params = ctor.GetParameters();
                List <object> param_objs  = new List <object>();
                bool          flag        = true;
                foreach (var param in ctor_params)
                {
                    if (m_XServices.TryGet(XILUtil.GetCatLibServiceName(param.ParameterType), out var _service))
                    {
                        param_objs.Add(_service);
                    }
                    else
                    {
                        flag = false;
                        break;
                    }
                }

                if (flag) //有可用的构造函数
                {
                    //this.CreateInstance(type, param_objs);
                    var result = ctor.Invoke(param_objs.ToArray());
                    this.InjectObject(result);
                    return(result);
                }
            }
            throw new XException("[TinaX.Core] Create instance failed: No valid constructors, Type:" + type.FullName);
        }
        static StackObject *BindSingletonService_TService_TConcrete(ILIntepreter intp, StackObject *esp, IList <object> mStack, CLRMethod method, bool isNewObj)
        {
            var genericArguments = method.GenericArguments;

            if (genericArguments == null || genericArguments.Length != 2 || method.ParameterCount != 0)
            {
                throw new EntryPointNotFoundException();
            }

            var tService = XILUtil.ITypeToService(genericArguments[0]);
            var tType    = XILUtil.ITypeToClrType(genericArguments[1]);

            ILRuntime.Runtime.Enviorment.AppDomain __domain = intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(esp, 1);
            TinaX.IXCore instance_of_this_method = (TinaX.IXCore) typeof(TinaX.IXCore).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, mStack));
            intp.Free(ptr_of_this_method);

            instance_of_this_method.Services.Bind(tService, tType, true);
            //instance_of_this_method.BindSingletonService<ILRuntime.Runtime.Intepreter.ILTypeInstance, ILRuntime.Runtime.Intepreter.ILTypeInstance>();

            return(__ret);
        }
Example #9
0
        public void InjectObject(object target)
        {
            BindingFlags _bindFlag  = BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly;
            Type         actualType = target.GetActualType();

            foreach (var field in actualType.GetFields(_bindFlag))
            {
                string service_name = XILUtil.GetCatLibServiceName(field);

                var attr = field.GetCustomAttribute <InjectAttribute>(true);
                if (attr == null)
                {
                    continue;
                }
                if (m_XServices.TryGet(service_name, out var _service))
                {
                    field.SetValue(target, _service);
                    continue;
                }

                if (attr.Nullable)
                {
                    continue;
                }
                else
                {
                    throw new ServiceNotFoundException(field.FieldType); //抛异常
                }
            }

            foreach (var property in actualType.GetProperties(_bindFlag))
            {
                string service_name = XILUtil.GetCatLibServiceName(property);
                var    attr         = property.GetCustomAttribute <InjectAttribute>(true);
                if (attr == null)
                {
                    continue;
                }
                if (m_XServices.TryGet(service_name, out var _service))
                {
                    property.SetValue(target, _service);
                    continue;
                }

                if (attr.Nullable)
                {
                    continue;
                }
                else
                {
                    throw new ServiceNotFoundException(property.PropertyType); //抛异常
                }
            }
        }
Example #10
0
        internal static StackObject *Type2ServiceName_TService(ILIntepreter intp, StackObject *esp, IList <object> mStack,
                                                               CLRMethod method, bool isNewObj)
        {
            var genericArguments = method.GenericArguments;

            if (genericArguments == null || genericArguments.Length != 1 || method.ParameterCount != 0)
            {
                throw new EntryPointNotFoundException();
            }

            var tService = XILUtil.ITypeToService(genericArguments[0]);

            return(ILIntepreter.PushObject(esp, mStack, tService));
        }
Example #11
0
        internal static StackObject *Type2ServiceName_Type(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Type type = (System.Type) typeof(System.Type).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            var result_of_this_method = XILUtil.GetCatLibServiceName(type);

            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }
Example #12
0
        //void Unbind<TService>();
        private static StackObject *Unbind_TService(ILIntepreter intp, StackObject *esp, IList <object> mStack,
                                                    CLRMethod method, bool isNewObj)
        {
            var genericArguments = method.GenericArguments;

            if (genericArguments == null || genericArguments.Length != 1 || method.ParameterCount != 0)
            {
                throw new EntryPointNotFoundException();
            }

            var tService = XILUtil.ITypeToService(genericArguments[0]);

            XCore.MainInstance.Services.Unbind(tService);

            return(esp);
        }
Example #13
0
        //object Instance<TService>(object instance);
        internal static StackObject *Instance_TService_Object(ILIntepreter intp, StackObject *esp, IList <object> mStack, CLRMethod method, bool isNewObj)
        {
            var genericArguments = method.GenericArguments;

            if (genericArguments == null || genericArguments.Length != 1 || method.ParameterCount != 1)
            {
                throw new EntryPointNotFoundException();
            }

            var tService = XILUtil.ITypeToService(genericArguments[0]);

            var ptrOfThisMethod = ILIntepreter.Minus(esp, 1);

            ptrOfThisMethod = ILIntepreter.GetObjectAndResolveReference(ptrOfThisMethod);

            var instance =
                (object)typeof(object).CheckCLRTypes(
                    StackObject.ToObject(ptrOfThisMethod, intp.AppDomain, mStack));

            intp.Free(ptrOfThisMethod);

            return(ILIntepreter.PushObject(ILIntepreter.Minus(esp, 1), mStack, XCore.GetMainInstance().Services.Instance(tService, instance)));
        }