public void Process() { while (reader.Read()) { if (reader.NodeType == XmlNodeType.EndElement && reader.Name == outerTag) { break; } if (reader.IsStartElement()) { if (!tagMap.ContainsKey(reader.Name)) { throw new ArgumentException("Unrecognized element " + reader.Name + " within " + outerTag + " tag"); } string tag = reader.Name; MethodMap method = tagMap[tag]; string[] values = new string[method.Parameters.Count]; while (reader.MoveToNextAttribute()) { if (method.Parameters.Get(reader.Name) == null) { throw new ArgumentException("Unrecognized attribute " + reader.Name + " to " + tag + " tag within " + outerTag + " tag"); } values[int.Parse(method.Parameters.Get(reader.Name))] = reader.ReadContentAsString(); } method.Method(tag, values); } } }
public void SetUp() { var executingAssemblyDefinition = CecilUtilsForTests.GetExecutingAssemblyDefinition(); _finder = new CecilDefinitionFinder(executingAssemblyDefinition); _subject = new MethodMap(_finder.FindType(GetType().FullName)); }
public static Pipe Map(MethodMap map) { return Map(map.OnGet, map.OnPut, map.OnPost, map.OnDelete, map.AutoHead, map.OnHead, map.AutoTrace, map.OnTrace, map.AutoOptions, map.OnOptions, map.AutoUnknownMethod, map.OnUnknownMethod); }
public void ResultIsIsolated_attribute_is_recognized() { var map = MethodMap.MapFor <MethodMapTests.TestModel>(); var signature = typeof(MethodMapTests.TestModel).GetMethod("GetCustomersCloned").ToString(); var operationInfo = map.GetOperationInfo(signature); Assert.True(operationInfo.OperationAttribute.Isolation.HasFlag(IsolationLevel.Output)); }
public MemenimSchema() { _schemaMap = new MethodMap <MemenimSchema>( this, new[] { typeof(string) }, typeof(bool)); Name = "memenim"; }
public ArrayValue getMethods(Env env) { ArrayValue array = new ArrayValueImpl(); MethodMap <AbstractFunction> map = _cls.getMethodMap(); for (AbstractFunction method : map.values()) { array.put(env.wrapJava(new ReflectionMethod(_cls.getName(), method))); } return(array); }
/// <summary> /// Creates an instance of the given <paramref name="type"/> using the supplied parameter information as input. /// This method will try to determine the least-cost route to constructing the instance, which /// implies mapping as many properties as possible to constructor parameters. Remaining properties /// on the source are mapped to properties on the created instance or ignored if none matches. /// TryCreateInstance is very liberal and attempts to convert values that are not otherwise /// considered compatible, such as between strings and enums or numbers, Guids and byte[], etc. /// </summary> /// <param name="type">The type of which an instance should be created.</param> /// <param name="parameterNames">The names of the supplied parameters.</param> /// <param name="parameterTypes">The types of the supplied parameters.</param> /// <param name="parameterValues">The values of the supplied parameters.</param> /// <returns>An instance of <paramref name="type"/>.</returns> public static object TryCreateInstance(this Type type, string[] parameterNames, Type[] parameterTypes, object[] parameterValues) { string[] names = parameterNames ?? Constants.EmptyStringArray; Type[] types = parameterTypes ?? Type.EmptyTypes; object[] values = parameterValues ?? Constants.EmptyObjectArray; if (names.Length != values.Length || names.Length != types.Length) { throw new ArgumentException("Mismatching name, type and value arrays (must be of identical length)."); } MethodMap map = MapFactory.PrepareInvoke(type, names, types, values); return(map.Invoke(values)); }
/// <summary> /// Creates an instance of the given <paramref name="type"/> using the public properties of the /// supplied <paramref name="sample"/> object as input. /// This method will try to determine the least-cost route to constructing the instance, which /// implies mapping as many properties as possible to constructor parameters. Remaining properties /// on the source are mapped to properties on the created instance or ignored if none matches. /// TryCreateInstance is very liberal and attempts to convert values that are not otherwise /// considered compatible, such as between strings and enums or numbers, Guids and byte[], etc. /// </summary> /// <returns>An instance of <paramref name="type"/>.</returns> public static object TryCreateInstance(this Type type, object sample) { Type sourceType = sample.GetType(); SourceInfo sourceInfo = sourceInfoCache.Get(sourceType); if (sourceInfo == null) { sourceInfo = SourceInfo.CreateFromType(sourceType); sourceInfoCache.Insert(sourceType, sourceInfo); } object[] paramValues = sourceInfo.GetParameterValues(sample); MethodMap map = MapFactory.PrepareInvoke(type, sourceInfo.ParamNames, sourceInfo.ParamTypes, paramValues); return(map.Invoke(paramValues)); }
/// <summary> /// Creates an instance of the given <paramref name="type"/> using the supplied parameter information as input. /// This method will try to determine the least-cost route to constructing the instance, which /// implies mapping as many properties as possible to constructor parameters. Remaining properties /// on the source are mapped to properties on the created instance or ignored if none matches. /// TryCreateInstance is very liberal and attempts to convert values that are not otherwise /// considered compatible, such as between strings and enums or numbers, Guids and byte[], etc. /// </summary> /// <param name="type">The type of which an instance should be created.</param> /// <param name="parameterNames">The names of the supplied parameters.</param> /// <param name="parameterTypes">The types of the supplied parameters.</param> /// <param name="parameterValues">The values of the supplied parameters.</param> /// <returns>An instance of <paramref name="type"/>.</returns> public static object TryCreateInstance(this Type type, string[] parameterNames, Type[] parameterTypes, object[] parameterValues) { var names = parameterNames ?? new string[0]; var types = parameterTypes ?? new Type[0]; var values = parameterValues ?? new object[0]; if (names.Length != values.Length || names.Length != types.Length) { throw new ArgumentException("Mismatching name, type and value arrays (must be of identical length)."); } MethodMap map = MapFactory.PrepareInvoke(type, names, types, values); return(map.Invoke(values)); }
/// <summary> /// Obtains a list of all methods with the given <paramref name="methodName"/> on the given /// <paramref name="obj" />, and invokes the best match for the supplied parameters. /// TryCallMethod is very liberal and attempts to convert values that are not otherwise /// considered compatible, such as between strings and enums or numbers, Guids and byte[16], etc. /// </summary> /// <param name="obj">The type of which an instance should be created.</param> /// <param name="methodName">The name of the overloaded methods.</param> /// <param name="mustUseAllParameters">Specifies whether all supplied parameters must be used in the /// invocation. Unless you know what you are doing you should pass true for this parameter.</param> /// <param name="parameterNames">The names of the supplied parameters.</param> /// <param name="parameterTypes">The types of the supplied parameters.</param> /// <param name="parameterValues">The values of the supplied parameters.</param> /// <returns>The result of the invocation.</returns> public static object TryCallMethod(this object obj, string methodName, bool mustUseAllParameters, string[] parameterNames, Type[] parameterTypes, object[] parameterValues) { bool isStatic = obj is Type; var type = isStatic ? obj as Type : obj.GetType(); var names = parameterNames ?? new string[0]; var types = parameterTypes ?? new Type[0]; var values = parameterValues ?? new object[0]; if (names.Length != values.Length || names.Length != types.Length) { throw new ArgumentException("Mismatching name, type and value arrays (must be of identical length)."); } MethodMap map = MapFactory.DetermineBestMethodMatch(type.Methods(methodName).Cast <MethodBase>(), mustUseAllParameters, names, types, values); return(isStatic ? map.Invoke(values) : map.Invoke(obj, values)); }
/// <summary> /// Obtains a list of all methods with the given <paramref name="methodName"/> on the given /// <paramref name="obj" />, and invokes the best match for the supplied parameters. /// TryCallMethod is very liberal and attempts to convert values that are not otherwise /// considered compatible, such as between strings and enums or numbers, Guids and byte[16], etc. /// </summary> /// <param name="obj">The type of which an instance should be created.</param> /// <param name="methodName">The name of the overloaded methods.</param> /// <param name="mustUseAllParameters">Specifies whether all supplied parameters must be used in the /// invocation. Unless you know what you are doing you should pass true for this parameter.</param> /// <param name="parameterNames">The names of the supplied parameters.</param> /// <param name="parameterTypes">The types of the supplied parameters.</param> /// <param name="parameterValues">The values of the supplied parameters.</param> /// <returns>The result of the invocation.</returns> internal static object TryCallMethod(this object obj, string methodName, bool mustUseAllParameters, string[] parameterNames, Type[] parameterTypes, object[] parameterValues) { Type type = obj as Type; bool isStatic = type != null; if (!isStatic) { type = obj.GetType(); } string[] names = parameterNames ?? Constants.EmptyStringArray; Type[] types = parameterTypes ?? Type.EmptyTypes; object[] values = parameterValues ?? Constants.EmptyObjectArray; if (names.Length != values.Length || names.Length != types.Length) { throw new ArgumentException("Mismatching name, type and value arrays (must be of identical length)."); } MethodMap map = MapFactory.DetermineBestMethodMatch(type.Methods(methodName).Cast <MethodBase>(), mustUseAllParameters, names, types, values); return(isStatic ? map.Invoke(values) : map.Invoke(obj, values)); }
private static void CreateMethodProxy(FieldInfo storageField, TypeBuilder typeBuilder, MethodMap map) { const MethodAttributes methodAttributes = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.Virtual; var methodBuilder = typeBuilder.DefineMethod(map.InterfaceMethod.Name, methodAttributes, CallingConventions.HasThis, map.InterfaceMethod.ReturnType, map.Parameters.ToArray()); var typeArgs = map.InterfaceMethod.GetGenericArguments(); if(typeArgs != null && typeArgs.Length > 0) { var typeNames = new List<string>(); for(var index = 0; index < typeArgs.Length; index++) { typeNames.Add(string.Format("T{0}", index)); } methodBuilder.DefineGenericParameters(typeNames.ToArray()); } var il = methodBuilder.GetILGenerator(); il.Emit(OpCodes.Ldarg_0); il.Emit(OpCodes.Ldfld, storageField); for(var i = 1; i <= map.Parameters.Length; i++) { il.Emit(OpCodes.Ldarg_S, i); } il.Emit(OpCodes.Callvirt, map.InstanceMethod); il.Emit(OpCodes.Ret); }
public void AddMethod(MethodMap method) { tagMap.Add(method.Name, method); }
public void Maps_are_cached() { var map = MethodMap.MapFor <TestModel>(); Assert.AreSame(_map, map); }
public void Init() { _map = MethodMap.MapFor <TestModel>(); }
public bool hasMethod(StringValue name) { MethodMap <AbstractFunction> map = _cls.getMethodMap(); return(map.containsKey(name)); }