private State triggerCurrentStateEvent(Event triggerEvent) { Type eListenerType = typeof(EventListenerAttribute); Type eStateType = typeof(State); foreach (System.Reflection.MethodInfo m in currentState.GetType().GetMethods()) { if (m.GetCustomAttributes(eListenerType, false).Length > 0) { System.Reflection.ParameterInfo[] parameters = m.GetParameters(); if (parameters.Length == 1) { System.Reflection.ParameterInfo info = m.GetParameters()[0]; if (info.ParameterType == triggerEvent.GetType()) { if (m.ReturnType == eStateType) { return((State)m.Invoke(currentState, new object[] { triggerEvent })); } else { m.Invoke(currentState, new object[] { triggerEvent }); return(null); } } } } } return(null); }
/// <summary> /// Construtor padrão. /// </summary> /// <param name="parameter"></param> /// <param name="importDescription"></param> /// <param name="creationPolicy"></param> public ProviderParameterImportDefinition(System.Reflection.ParameterInfo parameter, ImportDescription importDescription, System.ComponentModel.Composition.CreationPolicy creationPolicy) : base(CompositionServices.GetContractNameFromImportDescription(parameter, importDescription), CompositionServices.GetTypeIdentityFromImportDescription(parameter, importDescription), CompositionServices.GetMetadataFromImportDescription(parameter, importDescription), System.ComponentModel.Composition.Primitives.ImportCardinality.ExactlyOne, importDescription.Recomposable, importDescription.Prerequisite, creationPolicy) { parameter.Require("parameter").NotNull(); importDescription.Require("importDescription").NotNull(); this.AllowDefault = importDescription.AllowDefault; this.Parameter = parameter; }
public override void SetUp() { base.SetUp(); parameterInfo = typeof(ReflectedParameter).GetMethod("AMethod")?.GetParameters()[0]; testing = type.of <ReflectedParameter>().GetMethod("AMethod").GetParameters()[0]; }
public ParameterInfo([NotNull] System.Reflection.ParameterInfo parameterInfo) { Guard.ArgumentNotNull(parameterInfo, nameof(parameterInfo)); _parameterInfo = parameterInfo; }
public static bool IsDefined(System.Reflection.ParameterInfo element, Type attributeType, bool inherit) { Contract.Requires(element != null); Contract.Requires(attributeType != null); return(default(bool)); }
public static Attribute[] GetCustomAttributes(System.Reflection.ParameterInfo element, Type attributeType, bool inherit) { Contract.Requires(element != null); Contract.Requires(attributeType != null); return(default(Attribute[])); }
internal CILParameterImpl( CILReflectionContextImpl ctx, Int32 anID, System.Reflection.ParameterInfo parameter ) : base(ctx, anID, CILElementKind.Parameter, () => new CustomAttributeDataEventArgs(ctx, parameter)) { var member = parameter.Member; var isCtor = member is System.Reflection.ConstructorInfo; InitFields( ref this.paramAttributes, ref this.position, ref this.name, ref this.method, ref this.parameterType, ref this.defaultValue, ref this.customModifiers, ref this.marshalInfo, new SettableValueForEnums <ParameterAttributes>((ParameterAttributes)parameter.Attributes), parameter.Position, new SettableValueForClasses <String>(parameter.Name), () => isCtor ? (CILMethodBase)ctx.Cache.GetOrAdd((System.Reflection.ConstructorInfo)member) : ctx.Cache.GetOrAdd((System.Reflection.MethodInfo)member), () => ctx.Cache.GetOrAdd(parameter.ParameterType), new SettableLazy <Object>(() => ctx.LaunchConstantValueLoadEvent(new ConstantValueLoadArgs(parameter))), ctx.LaunchEventAndCreateCustomModifiers(new CustomModifierEventLoadArgs(parameter)), new SettableLazy <MarshalingInfo>(() => MarshalingInfo.FromAttribute(parameter.GetCustomAttributes(true).OfType <System.Runtime.InteropServices.MarshalAsAttribute>().FirstOrDefault(), ctx)), true ); }
public static ParameterType From(System.Reflection.ParameterInfo parameter) { return(new ParameterType() { Name = parameter.ParameterType.Name, TypeName = parameter.ParameterType.FullName, Type = parameter.ParameterType }); }
static TypeCache() { TypeCache.Types = Types.Instance; var method = typeof(TypeCache).GetMethod(nameof(TypeCache.DummyUOW), System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); var pms = method.GetParameters(); UOW = pms[0]; UOW_ADMIN = pms[1]; }
public void Constructor_ForParameterInfoIsNull_Throws( ) { _parameterInfoString = null; Action action = () => CreateSut( ); action.Should( ) .Throw <ArgumentNullException> ( ) .WithParameter("parameterInfo"); }
public ParameterInfo([NotNull] System.Reflection.ParameterInfo parameterInfo) { Guard.ArgumentNotNull(parameterInfo, nameof(parameterInfo)); var parameterInfo1 = parameterInfo; CustomAttributes = parameterInfo1.CustomAttributes.Select(x => new CustomAttributeData(x)); ParameterType = parameterInfo1.ParameterType; }
public Parameter(System.Reflection.ParameterInfo paramInfo) { this.paramInfo = paramInfo; dataAttribute = Reflection.GetAttribute(paramInfo, typeof(NUnit.Framework.ParameterDataAttribute), false); if (dataAttribute == null) { throw new System.Exception("Missing ParameterData Attribute"); } methodInfo = dataAttribute.GetType().GetMethod("GetData"); }
/// <summary> /// 引数入力フィールド用のラベルを取得 /// </summary> private string GetParameterLabel(System.Reflection.ParameterInfo parameterInfo) { if (_isShowParameterTypeFullName) { return(parameterInfo.Name + " : " + parameterInfo.ParameterType.ToString()); } else { return(parameterInfo.Name + " : " + parameterInfo.ParameterType.Name); } }
public static string GetName(this System.Reflection.ParameterInfo paramInfo) { if (paramInfo.Name == "asm") { return("assembly"); } if (paramInfo.Name == "or") { return("objOr"); } return(paramInfo.Name); }
public override bool CanSupplyValue(System.Reflection.ParameterInfo pi, IComponentContext context, out Func <object> valueProvider) { object value; if (config.TryConvert(pi.Name, out value, pi.ParameterType)) { valueProvider = () => value; return(true); } valueProvider = null; return(false); }
public ParameterBuilder(System.Reflection.ParameterInfo parameterinfo) { Parameter = new(); Parameter.Name = parameterinfo.Name; Parameter.Type = parameterinfo.ParameterType; foreach (System.Reflection.CustomAttributeData attribute in parameterinfo.CustomAttributes) { if (attribute.AttributeType == typeof(RemainderAttribute)) { Parameter.IsRemainder = true; } } }
protected void OnInvoke(object state) { object[] data = (object[])state; SubscribeEventArgs <Message> routemsg = (SubscribeEventArgs <Message>)data[0]; Message message = (Message)data[1]; Result result = (Result)data[2]; try { ControllerContext context = new ControllerContext(); Controller.Context = context; if (message.Body != null && (mToObjectMethod == null || mSelectTokenMethod == null)) { mToObjectMethod = message.Body.GetType().GetMethod(ToObjectMethodName, new Type[] { typeof(Type) }); mSelectTokenMethod = message.Body.GetType().GetMethod(SelectTokenMethodName, new Type[] { typeof(String) }); } object[] objs = new Object[Parameters.Count]; if (Parameters.Count == 1 && Parameters[0].ParameterType.IsClass) { objs[0] = mToObjectMethod.Invoke(message.Body, new object[] { Parameters[0].ParameterType }); } else { for (int i = 0; i < Parameters.Count; i++) { System.Reflection.ParameterInfo p = Parameters[i]; object pobject = mSelectTokenMethod.Invoke(message.Body, new object[] { p.Name }); if (pobject != null) { objs[i] = mToObjectMethod.Invoke(pobject, new object[] { p.ParameterType }); } else { objs[i] = GetTypeDefault(p.ParameterType); } } } result.Data = Method.Invoke(Controller, objs); result.Headers = context.ResultHeaders; } catch (Exception e_) { result.ErrorCode = 500; result.Error = e_.Message; result.ErrorStackTrace = e_.StackTrace; } finally { routemsg.Reply(result); } }
/** * @brief build dictionary of internal functions from an interface. * @param iface = interface with function definitions * @param inclSig = true: catalog by name with arg sig, eg, llSay(integer,string) * false: catalog by simple name only, eg, state_entry * @returns dictionary of function definition tokens */ public InternalFuncDict(Type iface, bool inclSig) : base(false) { // Loop through list of all methods declared in the interface. System.Reflection.MethodInfo[] ifaceMethods = iface.GetMethods(); foreach (System.Reflection.MethodInfo ifaceMethod in ifaceMethods) { string key = ifaceMethod.Name; // Only do ones that begin with lower-case letters... // as any others can't be referenced by scripts if ((key[0] < 'a') || (key[0] > 'z')) { continue; } try { // Create a corresponding TokenDeclVar struct. System.Reflection.ParameterInfo[] parameters = ifaceMethod.GetParameters(); TokenArgDecl argDecl = new TokenArgDecl(null); for (int i = 0; i < parameters.Length; i++) { System.Reflection.ParameterInfo param = parameters[i]; TokenType type = TokenType.FromSysType(null, param.ParameterType); TokenName name = new TokenName(null, param.Name); argDecl.AddArg(type, name); } TokenDeclVar declFunc = new TokenDeclVar(null, null, null); declFunc.name = new TokenName(null, key); declFunc.retType = TokenType.FromSysType(null, ifaceMethod.ReturnType); declFunc.argDecl = argDecl; // Add the TokenDeclVar struct to the dictionary. this.AddEntry(declFunc); } catch (Exception except) { string msg = except.ToString(); int i = msg.IndexOf("\n"); if (i > 0) { msg = msg.Substring(0, i); } Console.WriteLine("InternalFuncDict*: {0}: {1}", key, msg); ///??? IGNORE ANY THAT FAIL - LIKE UNRECOGNIZED TYPE ???/// } } }
public static bool MatchPattern(this System.Reflection.ParameterInfo parameter, Type customAttribute, string attributeName) { if (parameter == null) { return(false); } var hasCA = parameter.GetCustomAttributes(customAttribute, false).Any(); if (hasCA) { return(true); } return(!string.IsNullOrEmpty(attributeName) && parameter.Name.ToLower().Equals(attributeName.ToLower())); }
/// <summary> /// Register this event /// </summary> /// <param name="method">The method that will be called when the event is executed</param> /// <param name="priority">The priority of the call</param> public static void Register(OnCall method, Priority priority) { Registered r = new Registered(); System.Reflection.ParameterInfo p = method.Method.GetParameters()[0]; if (p.GetType() == typeof(PlayerConnectEvent)) { r.e = new PlayerConnectEvent(); } else { throw new Exception("Invalid method"); } r.method = method; r.priority = priority; r.GiveMuffinToDerpy(); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if ("ParamName".Equals(parameter)) { return((value as System.Reflection.ParameterInfo).ParameterType.Name); } else if ("ParamReadOnly".Equals(parameter)) { //如果是ref参数,则禁用textbox return((value as System.Reflection.ParameterInfo).IsRetval); } else if ("ParamEnable".Equals(parameter)) { System.Reflection.ParameterInfo param = value as System.Reflection.ParameterInfo; return(param.ParameterType == typeof(int) || param.ParameterType == typeof(float) || param.ParameterType == typeof(bool) || param.ParameterType == typeof(string)); } return(value); }
private static object GetParameterValue(System.Web.HttpContextBase context, System.Reflection.ParameterInfo pi) { if (pi.Name == "body") { return(context.GetOrDeserializeRequestStreamJson(pi.ParameterType)); } if (pi.Name == "context") { return(context); } var queryValue = context.Request[pi.Name]; if (string.IsNullOrEmpty(queryValue)) { return(null); } return(Utility.Convert(queryValue, pi.ParameterType)); }
protected int HandleQtMetacall(int index, QMetaObject.Call call, void **arguments) { if (index < 0 || call != QMetaObject.Call.InvokeMetaMethod) { return(index); } Handler handler = this.slots[index]; System.Reflection.ParameterInfo[] @params = handler.Delegate.Method.GetParameters(); object[] parameters = new object[@params.Length]; for (int i = 0; i < @params.Length; i++) { System.Reflection.ParameterInfo parameter = @params[i]; var arg = new IntPtr(arguments[1 + i]); object value; if (parameter.ParameterType.IsValueType) { value = Marshal.PtrToStructure(arg, parameter.ParameterType); } else { if (parameter.ParameterType.IsAssignableFrom(typeof(string))) { var metaMethod = this.Sender.MetaObject.Method(handler.SignalId); if (metaMethod.ParameterType(i) == (int)QMetaType.Type.QString) { value = Marshal.PtrToStringUni(new IntPtr(new QString(arg).Utf16)); } else { value = Marshal.PtrToStringUni(arg); } } else { value = Activator.CreateInstance(parameter.ParameterType, arg); } } parameters[i] = value; } handler.Delegate.DynamicInvoke(parameters); return(-1); }
public ParameterBinder(System.Reflection.ParameterInfo pi) { Info = pi; BindAttribute[] bas = Functions.GetParemeterAttributes <BindAttribute>(pi, false); if (bas.Length > 0) { Binder = bas[0]; } ViewStateAttribute[] vsa = Functions.GetParemeterAttributes <ViewStateAttribute>(pi, false); if (vsa.Length > 0) { ViewState = vsa[0]; } foreach (ValidaterAttribute va in Functions.GetParemeterAttributes <ValidaterAttribute>(pi, false)) { Validaters.Add(va); } mIsOut = Functions.GetParemeterAttributes <OutputAttribute>(pi, false).Length > 0; }
//HACK:缺少参数自动用null填充 private object ParseArgument(System.Reflection.ParameterInfo p, ServiceCall call) { var arg = call.ArgumentCollection.FirstOrDefault(o => o.Key.Equals(p.Name, StringComparison.InvariantCultureIgnoreCase)); if (arg == null) { throw new ServiceException(string.Format("缺少参数{0}", p.Name), ExceptionCode.ArgumentError); } //HACK:此处针对string的json序列化优化处理,以避免http调用情况下的字符串参数兼容问题和意外不合法反序列化 if (p.ParameterType == typeof(string)) { if (string.IsNullOrEmpty(arg.Value) && this.InternalDebug("返回空字符串")) { return(arg.Value); } if (arg.Value.Equals("null", StringComparison.InvariantCultureIgnoreCase) && this.InternalDebug("遇到null,返回空")) { return(null); } if (!arg.Value.StartsWith("\"") && this.InternalDebug("返回非\"开头,返回原始字符串")) { return(arg.Value); } } try { return(this._serializer.Deserialize(p.ParameterType, arg.Value)); } catch (Exception e) { //HACK:例外处理 string类型反序列化失败时,直接返回该字符串 //if (p.ParameterType == typeof(string)) // return arg.Value; throw new ServiceException(string.Format("参数{0}格式不正确:{1}" , p.Name , e.Message) , ExceptionCode.ArgumentError , e); } }
protected int HandleQtMetacall(int index, QMetaObject.Call call, void **arguments) { if (index < 0 || call != QMetaObject.Call.InvokeMetaMethod) { return(index); } Handler handler = this.slots[index]; System.Reflection.ParameterInfo[] @params = handler.Delegate.Method.GetParameters(); object[] parameters = new object[@params.Length]; for (int i = 0; i < @params.Length; i++) { System.Reflection.ParameterInfo parameter = @params[i]; var arg = new IntPtr(arguments[1 + i]); parameters[i] = GetParameterValue(handler, i, parameter, arg); } handler.Delegate.DynamicInvoke(parameters); return(-1); }
void Probe(System.Type type, System.Reflection.BindingFlags bindingFlags = System.Reflection.BindingFlags.Public) { if (object.ReferenceEquals(type, NilType)) { return; } System.Exception any; System.Reflection.ConstructorInfo[] constructors = type.GetConstructors(bindingFlags); int register; if (Media.Common.Extensions.Array.ArrayExtensions.IsNullOrEmpty(constructors, out register) || register <= 0) { return; } System.Reflection.ParameterInfo[][] parameters = new System.Reflection.ParameterInfo[register][]; register = -1; foreach (System.Reflection.ConstructorInfo constructor in constructors) { //Todo, range check elimination parameters[++register] = constructor.GetParameters(); } //There is no parameter info... if (register < 0) { return; } var probe = new System.Tuple <System.Reflection.ConstructorInfo[], System.Reflection.ParameterInfo[][]>(constructors, parameters); if (Media.Common.Extensions.Generic.Dictionary.DictionaryExtensions.TryAdd(m_SupportedTypes, ref type, ref probe, out any).Equals(false)) { //The type was already probed } }
internal static string GetOptionalParameter(System.Reflection.ParameterInfo par, Language lang) { if (!isTypeSuffixesInitialized) { InitializeTypeSuffixes(); } string optionalParamString = " = "; if (par.DefaultValue.GetType().IsEnum) { optionalParamString += par.DefaultValue.GetType().Name + "."; } optionalParamString += par.DefaultValue.ToString(); if (TypeHasSuffix(par.ParameterType)) { optionalParamString += GetTypeSuffix(par.ParameterType, lang); } return(optionalParamString); }
public void TestInitialize( ) { var methodInfo = typeof(ParameterInfoTests).GetMethod(MethodNameWithString, new [] { typeof(string) }); if (methodInfo == null) { var message = string.Format(CultureInfo.InvariantCulture, $"Can't find method {MethodNameWithString}"); throw new Exception(message); } var infos = methodInfo.GetParameters( ); _parameterInfoString = infos.First( ); }
static bool convertType(ref object value, Type type, object inValue) { bool bIsListType = isListType(type); if (bIsListType && type.IsArray) { IListNonGeneric iInValue = (IListNonGeneric)inValue; Array arr = Array.CreateInstance(type.GetElementType(), iInValue.Count); for (int done = 0; done < iInValue.Count; done++) { arr.SetValue(iInValue[done], done); } value = arr; return(true); } if (bIsListType) { value = Json2Object.newInstance(type); object[] arrInValue = (object[])inValue; MethodInfo mi = type.GetMethod("Add"); for (int done = 0; done < arrInValue.Length; done++) { object indexValue = arrInValue[done]; ParameterInfo pi = mi.GetParameters()[0]; if (indexValue != null && !pi.ParameterType.IsAssignableFrom(indexValue.GetType())) { indexValue = Convert.ChangeType(indexValue, pi.ParameterType); } mi.Invoke(value, new Object[] { indexValue }); } return(true); } return(false); }
internal ParameterInfoImpl(System.Reflection.ParameterInfo parameter) { Debug.Assert(parameter != null); this.Parameter = parameter; }
public compiled_parameter(System.Reflection.ParameterInfo param) : base(param.Name,compiled_type_node.get_type_node(param.ParameterType)) { _par=param; }