void CreateSubContainerDefaultNodes()
        {
            var param    = CSParam as BehaviorTree_CustomServiceControlConstructionParams;
            var miAssist = new CustomMethodInfo();

            miAssist.MethodName  = "CustomService_" + ValidName;
            miAssist.DisplayName = "CustomService_" + NodeName;
            var eTime = new CustomMethodInfo.FunctionParam();

            eTime.ParamType = new VariableType(typeof(long), param.CSType);
            eTime.ParamName = "elapseTime";
            miAssist.InParams.Add(eTime);
            var context = new CustomMethodInfo.FunctionParam();

            context.ParamType = new VariableType(typeof(EngineNS.GamePlay.Actor.GCenterData), param.CSType);
            context.ParamName = "context";
            context.Attributes.Add(new EngineNS.Editor.Editor_MacrossMethodParamTypeAttribute(BTCenterDataWarpper.CenterDataType));
            miAssist.InParams.Add(context);
            var nodeType = typeof(CodeDomNode.MethodCustom);
            var csParam  = new CodeDomNode.MethodCustom.MethodCustomConstructParam()
            {
                CSType             = param.CSType,
                HostNodesContainer = mLinkedNodesContainer,
                ConstructParam     = "",
                IsShowProperty     = false,
                MethodInfo         = miAssist,
            };
            var node = mLinkedNodesContainer.AddOrigionNode(nodeType, csParam, 0, 100);

            node.IsDeleteable              = false;
            node.NodeNameAddShowNodeName   = false;
            mLinkedNodesContainer.HostNode = this;
        }
Exemplo n.º 2
0
 /// <summary>
 /// 执行方法
 /// </summary>
 /// <param name="info"></param>
 /// <returns></returns>
 public object ExecutinonMethod(CustomMethodInfo info)
 {
     try
     {
         object obj = null;
         if (info.ParamterInfos.Length == 0)
         {
             obj = info.Method.Invoke(info.Instance, null);
         }
         else
         {
             var args = new object[info.ParamterInfos.Length];
             for (int i = 0; i < info.ParamterInfos.Length; i++)
             {
                 var para = info.ParamterInfos[i];
                 var val  = _request.WebParameters[para.Name];
                 args[i] = ReflectionHelper.ChangeType(val, para.ParameterType);
             }
             obj = info.Method.Invoke(info.Instance, args);
         }
         return(obj);
     }
     catch (Exception ex)
     {
         return(new AjaxResult {
             state = 0, msg = ex.Message
         });
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Try to find a match from a set of methods
        /// </summary>
        /// <param name="methods"></param>
        /// <param name="previous"></param>
        /// <param name="argTypes"></param>
        private void BindToMethod(ICollection <MethodInfo> methods, MemberElement previous, Type[] argTypes)
        {
            var customInfoList = new List <CustomMethodInfo>();

            // Wrap the MethodInfo in our custom class
            foreach (var methodInfo in methods)
            {
                var customMethodInfo = new CustomMethodInfo(methodInfo);
                customInfoList.Add(customMethodInfo);
            }

            // Discard any methods that cannot qualify as overloads
            var infoArray = customInfoList.ToArray();

            customInfoList.Clear();

            foreach (var methodInfo in infoArray)
            {
                if (methodInfo.IsMatch(argTypes))
                {
                    customInfoList.Add(methodInfo);
                }
            }

            if (customInfoList.Count == 0)
            {
                // We have no methods that can qualify as overloads; throw exception
                ThrowFunctionNotFoundException(previous);
            }
            else
            {
                // At least one method matches our criteria; do our custom overload resolution
                ResolveOverloads(customInfoList.ToArray(), previous, argTypes);
            }
        }
Exemplo n.º 4
0
        public static CustomPropertyInfo Create(
            CustomType declaringType = null,
            string name = "UnspecifiedProperty",
            PropertyAttributes attributes = (PropertyAttributes)7,
            IEnumerable <ICustomAttributeData> customAttributes = null,
            CustomMethodInfo getMethod      = null,
            CustomMethodInfo setMethod      = null,
            ParameterInfo[] indexParameters = null)
        {
            declaringType    = declaringType ?? CustomTypeObjectMother.Create();
            customAttributes = customAttributes ?? new ICustomAttributeData[0];
            // Getter stays null.
            // Setters stays null, but if both are null then create a getter.
            if (getMethod == null && setMethod == null)
            {
                getMethod = CustomMethodInfoObjectMother.Create(returnParameter: CustomParameterInfoObjectMother.Create(position: -1, type: typeof(int)));
            }
            indexParameters = indexParameters ?? new ParameterInfo[0];

            return(new TestableCustomPropertyInfo(declaringType, name, attributes, getMethod, setMethod)
            {
                CustomAttributeDatas = customAttributes,
                IndexParameters = indexParameters
            });
        }
Exemplo n.º 5
0
        /// <summary>
        /// Find the best match from a set of overloaded methods
        /// </summary>
        /// <param name="customInfoArray"></param>
        /// <param name="previous"></param>
        /// <param name="argTypes"></param>
        private void ResolveOverloads(CustomMethodInfo[] customInfoArray, MemberElement previous, Type[] argTypes)
        {
            // Compute a score for each candidate
            foreach (var customMethodInfo in customInfoArray)
            {
                customMethodInfo.ComputeScore(argTypes);
            }

            // Sort array from best to worst matches
            Array.Sort(customInfoArray);

            // Discard any matches that aren't accessible
            customInfoArray = GetAccessibleInfos(customInfoArray);

            // No accessible methods left
            if (customInfoArray.Length == 0)
            {
                ThrowNoAccessibleMethodsException(previous);
            }

            // Handle case where we have more than one match with the same score
            DetectAmbiguousMatches(customInfoArray);

            // If we get here, then there is only one best match
            targetMethodInfo = customInfoArray[0];
        }
Exemplo n.º 6
0
        /// <summary>
        /// Try to find a match from a set of methods
        /// </summary>
        /// <param name="methods"></param>
        /// <param name="previous"></param>
        /// <param name="argTypes"></param>
        private void BindToMethod(ICollection <MethodInfo> methods, MemberElement previous, Type[] argTypes)
        {
            List <CustomMethodInfo> customInfos = new List <CustomMethodInfo>();

            // Wrap the MethodInfos in our custom class
            foreach (MethodInfo mi in methods)
            {
                CustomMethodInfo cmi = new CustomMethodInfo(mi);
                customInfos.Add(cmi);
            }

            // Discard any methods that cannot qualify as overloads
            CustomMethodInfo[] arr = customInfos.ToArray();
            customInfos.Clear();

            foreach (CustomMethodInfo cmi in arr)
            {
                if (cmi.IsMatch(argTypes, MyPrevious, MyContext) == true)
                {
                    customInfos.Add(cmi);
                }
            }

            if (customInfos.Count == 0)
            {
                // We have no methods that can qualify as overloads; throw exception
                this.ThrowFunctionNotFoundException(previous);
            }
            else
            {
                // At least one method matches our criteria; do our custom overload resolution
                this.ResolveOverloads(customInfos.ToArray(), previous, argTypes);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Find the best match from a set of overloaded methods
        /// </summary>
        /// <param name="infos"></param>
        /// <param name="previous"></param>
        /// <param name="argTypes"></param>
        private void ResolveOverloads(CustomMethodInfo[] infos, MemberElement previous, Type[] argTypes)
        {
            // Compute a score for each candidate
            foreach (CustomMethodInfo cmi in infos)
            {
                cmi.ComputeScore(argTypes);
            }

            // Sort array from best to worst matches
            Array.Sort <CustomMethodInfo>(infos);

            // Discard any matches that aren't accessible
            infos = this.GetAccessibleInfos(infos);

            // No accessible methods left
            if (infos.Length == 0)
            {
                this.ThrowNoAccessibleMethodsException(previous);
            }

            // Handle case where we have more than one match with the same score
            this.DetectAmbiguousMatches(infos);

            // If we get here, then there is only one best match
            _myTargetMethodInfo = infos[0];
        }
Exemplo n.º 8
0
            //public override void Write(EngineNS.IO.XndNode xndNode)
            //{
            //    var att = xndNode.AddAttrib("ConstructionParams");
            //    att.Version = 0;
            //    att.BeginWrite();
            //    att.Write(ConstructParam);
            //    att.WriteMetaObject(MethodInfo);
            //    att.EndWrite();
            //}
            public override void Read(EngineNS.IO.XndNode xndNode)
            {
                var att = xndNode.FindAttrib("ConstructionParams");

                if (att != null)
                {
                    att.BeginRead();
                    switch (att.Version)
                    {
                    case 0:
                        att.Read(out mConstructParam);
                        if (MethodInfo == null)
                        {
                            MethodInfo = new CustomMethodInfo();
                        }
                        att.ReadMetaObject(MethodInfo);
                        break;

                    case 1:
                        att.ReadMetaObject(this);
                        break;
                    }
                    att.EndRead();
                }
            }
Exemplo n.º 9
0
 public TestableCustomPropertyInfo(
     CustomType declaringType,
     string name,
     PropertyAttributes attributes,
     CustomMethodInfo getMethod,
     CustomMethodInfo setMethod)
     : base(declaringType, name, attributes, getMethod, setMethod)
 {
 }
Exemplo n.º 10
0
        public void SetUp()
        {
            _typeParameter           = MutableGenericParameterObjectMother.Create();
            _parameter               = CustomParameterInfoObjectMother.Create();
            _genericMethodDefinition = CustomMethodInfoObjectMother.Create(parameters: new[] { _parameter }, typeArguments: new[] { _typeParameter });
            _typeArgument            = CustomTypeObjectMother.Create();

            var info = new MethodInstantiationInfo(_genericMethodDefinition, new[] { _typeArgument });

            _instantiation = new MethodInstantiation(info);
        }
Exemplo n.º 11
0
        public CustomMethodInfo GetMethod()
        {
            var key = _pathInfo.MethodKey;
            CustomMethodInfo info = null;

            //从缓存中取
            if (MethodCache.Keys.Contains(key))
            {
                info = MethodCache[key];
                info.LastUpdateTime = DateTime.Now;
                info.Count++;
                MethodCache[key] = info;
            }
            else
            {
                //无缓存
                info = GetMethodFromPath();
                if (info == null)
                {
                    throw new AjaxException("没有找到方法:" + _pathInfo.MethodName);
                }
                if (!MethodCache.Keys.Contains(key))
                {
                    lock (LockObj)
                    {
                        if (!MethodCache.Keys.Contains(key))
                        {
                            MethodCache.Add(key, info);
                        }
                    }
                }
            }
            var action = info.AttrList.Find(t => t is AjaxAction) as AjaxAction;

            if (action == null)
            {
                throw new AjaxException("不能通过网络访问该方法");
            }
            _request = new HttpRequestInfo
            {
                Context           = _context,
                CurrentMethodInfo = info,
                WebParameters     = action.GetWebParameters(_context)
            };

            if (!CheckAttributs(info.AttrList))
            {
                info = null;
            }

            return(info);
        }
Exemplo n.º 12
0
        public void SetUp()
        {
            _declaringType  = CustomTypeObjectMother.Create();
            _type           = ReflectionObjectMother.GetSomeType();
            _valueParameter = CustomParameterInfoObjectMother.Create(type: _type);
            var indexParameterType = ReflectionObjectMother.GetSomeOtherType();

            _indexParameter = CustomParameterInfoObjectMother.Create(type: indexParameterType);
            _getMethod      = CustomMethodInfoObjectMother.Create(attributes: MethodAttributes.Public, parameters: new[] { _indexParameter }, returnParameter: _valueParameter);
            _setMethod      = CustomMethodInfoObjectMother.Create(attributes: MethodAttributes.Public, parameters: new[] { _indexParameter, _valueParameter });

            _readOnlyProperty  = CustomPropertyInfoObjectMother.Create(getMethod: _getMethod);
            _writeOnlyProperty = CustomPropertyInfoObjectMother.Create(setMethod: _setMethod);
        }
Exemplo n.º 13
0
        public void SetUp()
        {
            _declaringType   = CustomTypeObjectMother.Create();
            _name            = "abc";
            _attributes      = (MethodAttributes)7;
            _returnParameter = CustomParameterInfoObjectMother.Create();

            _customMethod = new TestableCustomMethodInfo(_declaringType, _name, _attributes, null, Type.EmptyTypes)
            {
                ReturnParameter_ = _returnParameter
            };

            _typeArgument = ReflectionObjectMother.GetSomeType();
            _genericMethodUnderlyingDefinition = ReflectionObjectMother.GetSomeGenericMethodDefinition();
            _genericMethod = CustomMethodInfoObjectMother.Create(
                genericMethodDefintion: _genericMethodUnderlyingDefinition, typeArguments: new[] { _typeArgument });

            _typeParameter           = ReflectionObjectMother.GetSomeGenericParameter();
            _genericMethodDefinition = CustomMethodInfoObjectMother.Create(typeArguments: new[] { _typeParameter });
        }
Exemplo n.º 14
0
        /// <summary>
        ///  Handle case where we have overloads with the same score
        /// </summary>
        /// <param name="infos"></param>
        private void DetectAmbiguousMatches(CustomMethodInfo[] infos)
        {
            List <CustomMethodInfo> sameScores = new List <CustomMethodInfo>();
            CustomMethodInfo        first      = infos[0];

            // Find all matches with the same score as the best match
            foreach (CustomMethodInfo cmi in infos)
            {
                if (((IEquatable <CustomMethodInfo>)cmi).Equals(first) == true)
                {
                    sameScores.Add(cmi);
                }
            }

            // More than one accessible match with the same score exists
            if (sameScores.Count > 1)
            {
                this.ThrowAmbiguousMethodCallException();
            }
        }
Exemplo n.º 15
0
        // 这里不做参数在PropertyGrid中的显示设置,防止类似Ref参数被无意设置
        void SetParameters(CustomMethodInfo methodInfo)
        {
            var param = CSParam as ReturnCustomConstructParam;

            //param.MethodInfo.OnAddedOutParam -= ReturnCustom_AddParam;
            //param.MethodInfo.OnAddedOutParam += ReturnCustom_AddParam;
            //param.MethodInfo.OnRemovedOutParam -= ReturnCustom_RemoveParam;
            //param.MethodInfo.OnRemovedOutParam += ReturnCustom_RemoveParam;
            //param.MethodInfo.AddOutParamOperation(this);

            param.MethodInfo.AddOutParamOperation(this);

            var cpInfos = new List <CodeGenerateSystem.Base.CustomPropertyInfo>(methodInfo.OutParams.Count);

            mParamsPanel?.Children.Clear();
            foreach (var methodParam in methodInfo.OutParams)
            {
                var paramType = methodParam.ParamType.GetActualType();
                if (Program.IsTypeValidInPropertyGridShow(paramType))
                {
                    var infoAssist = new MethodParamInfoAssist()
                    {
                        FieldDirection = System.CodeDom.FieldDirection.Out,
                        IsParamsArray  = false,
                        ParameterType  = paramType,
                        ParamName      = methodParam.ParamName,
                    };
                    var cpInfo = Program.GetFromParamInfo(infoAssist);
                    cpInfos.Add(cpInfo);
                }

                //ReturnCustom_AddParam(methodParam);
                var noUse = OnAddedOutParam(methodParam);
            }

            if (param.ShowPropertyType == ReturnCustomConstructParam.enShowPropertyType.ReturnValue)
            {
                CreateTemplateClass(cpInfos);
            }
        }
Exemplo n.º 16
0
        private CustomMethodInfo GetMethodFromPath()
        {
            var info = new CustomMethodInfo();

            try
            {
                info.Assembly = Assembly.Load(_pathInfo.Assembly);
                var type = info.Assembly.GetType(_pathInfo.TypeName, true, true);
                info.Instance       = Activator.CreateInstance(type);
                info.Method         = type.GetMethod(_pathInfo.MethodName, Flags);
                info.Count          = 1;
                info.AttrList       = ReflectionHelper.GetAttributes <AttrBase>(info.Method);
                info.ReturnType     = info.Method.ReturnType;
                info.ParamterInfos  = info.Method.GetParameters();
                info.LastUpdateTime = DateTime.Now;
            }
            catch
            {
                info = null;
            }
            return(info);
        }
Exemplo n.º 17
0
        // Try to find a match from a set of methods
		private void BindToMethod(ICollection<MethodInfo> methods, MemberElement previous, Type[] argTypes)
		{
			List<CustomMethodInfo> customInfos = new List<CustomMethodInfo>();

			// Wrap the MethodInfos in our custom class
			foreach (MethodInfo mi in methods) {
				CustomMethodInfo cmi = new CustomMethodInfo(mi);
				customInfos.Add(cmi);
			}

			// Discard any methods that cannot qualify as overloads
			CustomMethodInfo[] arr = customInfos.ToArray();
			customInfos.Clear();

			foreach (CustomMethodInfo cmi in arr) {
				if (cmi.IsMatch(argTypes) == true) {
					customInfos.Add(cmi);
				}
			}

			if (customInfos.Count == 0) {
				// We have no methods that can qualify as overloads; throw exception
				this.ThrowFunctionNotFoundException(previous);
			} else {
				// At least one method matches our criteria; do our custom overload resolution
				this.ResolveOverloads(customInfos.ToArray(), previous, argTypes);
			}
		}
Exemplo n.º 18
0
		private CustomMethodInfo[] GetAccessibleInfos(CustomMethodInfo[] infos)
		{
			List<CustomMethodInfo> accessible = new List<CustomMethodInfo>();

			foreach (CustomMethodInfo cmi in infos) {
				if (cmi.IsAccessible(this) == true) {
					accessible.Add(cmi);
				}
			}

			return accessible.ToArray();
		}
Exemplo n.º 19
0
        // Handle case where we have overloads with the same score
		private void DetectAmbiguousMatches(CustomMethodInfo[] infos)
		{
			List<CustomMethodInfo> sameScores = new List<CustomMethodInfo>();
			CustomMethodInfo first = infos[0];

			// Find all matches with the same score as the best match
			foreach (CustomMethodInfo cmi in infos) {
				if (((IEquatable<CustomMethodInfo>)cmi).Equals(first) == true) {
					sameScores.Add(cmi);
				}
			}

			// More than one accessible match with the same score exists
			if (sameScores.Count > 1) {
				this.ThrowAmbiguousMethodCallException();
			}
		}
Exemplo n.º 20
0
        // Find the best match from a set of overloaded methods
		private void ResolveOverloads(CustomMethodInfo[] infos, MemberElement previous, Type[] argTypes)
		{
			// Compute a score for each candidate
			foreach (CustomMethodInfo cmi in infos) {
				cmi.ComputeScore(argTypes);
			}

			// Sort array from best to worst matches
			Array.Sort<CustomMethodInfo>(infos);

			// Discard any matches that aren't accessible
			infos = this.GetAccessibleInfos(infos);

			// No accessible methods left
			if (infos.Length == 0) {
				this.ThrowNoAccessibleMethodsException(previous);
			}

			// Handle case where we have more than one match with the same score
			this.DetectAmbiguousMatches(infos);

			// If we get here, then there is only one best match
			MyTargetMethodInfo = infos[0];
		}