protected virtual string FormatMethod(MethodBase method) { var sb = new StringBuilder(); if (method.DeclaringType != null) { sb.Append(method.DeclaringType.FullName); sb.Append("."); } sb.Append(method.Name); if (method.IsGenericMethod) { sb.Append("<"); sb.Append(string.Join(", ", method.GetGenericArguments().Select(t => t.Name))); sb.Append(">"); } sb.Append("("); var f = false; foreach (var p in method.GetParameters()) { if (f) sb.Append(", "); else f = true; sb.Append(p.ParameterType.Name); sb.Append(' '); sb.Append(p.Name); } sb.Append(")"); return sb.ToString(); }
public ReflectedMethod(Identifier name, MethodBase method, Type targetType) : base(name, null, method, targetType) { DeclaringName = method.DeclaringType != targetType ? IdentifierFor.Method(method, method.DeclaringType) : name; }
public ExpansionContext SpinOff(MethodBase callee) { Stack.Contains(callee).AssertFalse(); var new_stack = new Stack<MethodBase>(); callee.Concat(Stack).Reverse().ForEach(new_stack.Push); return new ExpansionContext(new_stack, Scope, Names, Env){Parent = this}; }
private static string GetMethodBaseSignaturePrefix(MethodBase methodBase) { var stringBuilder = new StringBuilder(); if (methodBase.IsPrivate) { stringBuilder.Append("private "); } else if (methodBase.IsPublic) { stringBuilder.Append("public "); } if (methodBase.IsAbstract) { stringBuilder.Append("abstract "); } if (methodBase.IsStatic) { stringBuilder.Append("static "); } if (methodBase.IsVirtual) { stringBuilder.Append("virtual "); } return stringBuilder.ToString(); }
private static void CheckActionMethodNamesAreNotReserved(MethodBase method) { if (method.Name.ToLower() == "help") { throw new NConsolerException("Method name \"{0}\" is reserved. Please, choose another name", method.Name); } }
// Validate the attribute usage. public override bool CompileTimeValidate( MethodBase method ) { // Don't apply to constructors. if ( method is ConstructorInfo ) { Message.Write( SeverityType.Error, "CX0001", "Cannot cache constructors." ); return false; } MethodInfo methodInfo = (MethodInfo) method; // Don't apply to void methods. if ( methodInfo.ReturnType.Name == "Void" ) { Message.Write( SeverityType.Error, "CX0002", "Cannot cache void methods." ); return false; } // Does not support out parameters. ParameterInfo[] parameters = method.GetParameters(); for ( int i = 0; i < parameters.Length; i++ ) { if ( parameters[i].IsOut ) { Message.Write( SeverityType.Error, "CX0003", "Cannot cache methods with return values." ); return false; } } return true; }
public BuiltinMethodParameterList(TypeManager typeManager, MethodBase methodBase) { this.typeManager = typeManager; this.methodBase = methodBase; parameters = null; }
public override object Action(object target, MethodBase method, object[] parameters, object result) { string namePrincipal = Thread.CurrentPrincipal.Identity.Name; if (namePrincipal == string.Empty) { namePrincipal = "Anonymous User"; } namePrincipal = "User: "******"Assambly: " + target.ToString() + "\nMethod: " + method.Name; string content = Helper.ReadFile(_pathInternal); try { Helper.SaveToFile(namePrincipal, text, content, _pathInternal); } catch { throw; } return null; }
public override int GetNumberOfStackPushes(MethodBase aMethod) { switch (OpCode) { case Code.Initobj: return 0; case Code.Ldelema: return 1; case Code.Newarr: return 1; case Code.Box: return 1; case Code.Stelem: return 0; case Code.Ldelem: return 1; case Code.Isinst: return 1; case Code.Castclass: return 1; case Code.Constrained: return 0; case Code.Unbox_Any: return 1; case Code.Unbox: return 1; case Code.Stobj: return 0; case Code.Ldobj: return 1; default: throw new NotImplementedException("OpCode '" + OpCode + "' not implemented!"); } }
public string GetBaseName(MethodBase method, Func<DisplayAsAttribute, string> selectName) { var nameAttribute = method.GetCustomAttributes(typeof(DisplayAsAttribute), true); if(nameAttribute.Length != 0) return selectName(((DisplayAsAttribute)nameAttribute[0])); return NormalizeNamePattern.Replace(method.Name, " "); }
//=========================================================================================== private bool IsStatic(MethodBase[] methods) { if (methods.Length != 1) return false; return IsStatic(methods[0]); }
internal Method(MethodBase methodBase, UtilityFactory factory) { if (methodBase == null) throw new ArgumentNullException("methodBase"); this.methodBase = methodBase; this.factory = factory; }
// ReSharper disable UnusedParameter.Local private void AssertMethodRule(Func<string, Type, IRegexFilter> addMethod, MethodBase method, Type type, bool expectedInclude) { IRegexFilter actualFilter = addMethod(method.Name, type); int expectedRules = 1; if (expectedInclude && type != null) expectedRules++; Assert.Same(addMethod.Target, actualFilter); Assert.Equal(expectedRules, actualFilter.Rules.Count); RegexRule addedRule = actualFilter.MethodRules.Single(); Assert.Equal(expectedInclude, addedRule.Include); Assert.NotNull(addedRule.Method); Assert.True(addedRule.MatchMethod(type ?? GetType(), method)); Assert.Null(addedRule.Parameter); if (type == null) { Assert.Null(addedRule.Type); } else { Assert.NotNull(addedRule.Type); Assert.True(addedRule.MatchType(type)); } }
public static void LogInfo(Exception ex) { try { //Writes error information to the log file including name of the file, line number & error message description //Console.WriteLine("Start"); stackTrace = new StackTrace(ex, true); //Console.WriteLine("Frames: {0}", stackTrace.FrameCount); //Console.WriteLine("Frame 0: {0}", stackTrace.GetFrame(0).GetFileName()); //string fileNames = stackTrace.GetFrame((stackTrace.FrameCount - 1)).GetFileName(); //Console.WriteLine(fileNames); //fileNames = fileNames.Substring(fileNames.LastIndexOf(Application.ProductName)); //Console.WriteLine("Rawr"); //Int32 lineNumber = stackTrace.GetFrame((stackTrace.FrameCount - 1)).GetFileLineNumber(); //Console.WriteLine(lineNumber); methodBase = stackTrace.GetFrame((stackTrace.FrameCount - 1)).GetMethod(); //These two lines are respnsible to find out name of the method String methodName = methodBase.Name; Info("Error in method " + methodName + ". Message: " + ex.Message); //Info("Error in " + fileNames + ". Method name is " + methodName + ", at line number " + lineNumber.ToString() + ". Error Message: " + ex.Message); } catch (Exception genEx) { Info(genEx.Message); Log.LogInfo(genEx); } finally { Dispose(); } }
/// <summary> /// Creates a REST call from a given method. /// If the method has no marker, a null is returned /// </summary> /// <param name="methodBase">The method base.</param> /// <returns></returns> public static RestCall FromMethod(MethodBase methodBase) { var httpGet = methodBase.GetCustomAttribute<HttpGetAttribute>(); if (httpGet != null) return new RestCall("GET", httpGet.UriTemplate); return null; }
/// <summary> /// Initializes a new instance of the MethodActivationContext class. /// </summary> /// <param name="target">The object instance that initiated the activation request.</param> /// <param name="targetMethod">The method where the activation was invoked.</param> /// <param name="concreteType">The type to be constructed.</param> /// <param name="additionalArguments">The additional arguments that will be passed to the constructor.</param> public TypeActivationContext(object target, MethodBase targetMethod, Type concreteType, object[] additionalArguments) : base(concreteType, additionalArguments) { Target = target; TargetMethod = targetMethod; }
public override object Action(object target, MethodBase method, object[] parameters, object result) { string namePrincipal = Thread.CurrentPrincipal.Identity.Name; if (namePrincipal == string.Empty) { namePrincipal = "Anonymous User"; } namePrincipal = "User: "******"Assambly: {0}", target).AppendLine() .AppendFormat("Method: {0}", method.Name).AppendLine().AppendLine() .AppendFormat("InnerException: {0}" + (result as Exception).InnerException) .ToString(); string content = Helper.ReadFile(_pathInternal); try { Helper.SaveToFile(namePrincipal, text, content, _pathInternal); } catch { throw; } return null; }
private EcmaCil.MethodMeta EnqueueMethod(MethodBase aMethod, object aSource, string aSourceType) { if (mLogEnabled) { LogMapPoint(aSource, aSourceType, aMethod); } if (aMethod.IsGenericMethodDefinition) { throw new Exception("Cannot queue generic method definitions"); } Type xReturnType = null; var xMethodInfo = aMethod as MethodInfo; if (xMethodInfo != null) { xReturnType = xMethodInfo.ReturnType; } else { xReturnType = typeof(void); } var xQueuedMethod = new QueuedMethod(aMethod.DeclaringType, aMethod, (from item in aMethod.GetParameters() select item.ParameterType).ToArray(), xReturnType); EcmaCil.MethodMeta xMethodMeta; if(mMethods.TryGetValue(xQueuedMethod, out xMethodMeta)){ return xMethodMeta; } var xDeclaringType = EnqueueType(aMethod.DeclaringType, aMethod, "Declaring type"); xMethodMeta = new EcmaCil.MethodMeta(); mMethodMetaToMethod.Add(xMethodMeta, aMethod); xMethodMeta.DeclaringType = xDeclaringType; xDeclaringType.Methods.Add(xMethodMeta); mMethods.Add(xQueuedMethod, xMethodMeta); mQueue.Enqueue(xQueuedMethod); return xMethodMeta; }
public void InitialiseProperties( Type classUnderTest, object instanceUnderTest, MethodBase methodUnderTest, object[] parameters, string nullParameter, int nullIndex, IExecutionSetup executionSetup) { // Act var sut = new MethodData( classUnderTest, instanceUnderTest, methodUnderTest, parameters, nullParameter, nullIndex, executionSetup); // Assert Assert.Same(classUnderTest, sut.ClassUnderTest); Assert.Equal(instanceUnderTest, sut.InstanceUnderTest); Assert.Same(methodUnderTest, sut.MethodUnderTest); Assert.Same(parameters, sut.Parameters); Assert.Same(nullParameter, sut.NullParameter); Assert.Equal(nullIndex, sut.NullIndex); Assert.Same(executionSetup, sut.ExecutionSetup); }
private static TestResult RunTest(object instance, MethodBase method) { var result = new TestResult { Name = method.Name }; var sw = new Stopwatch(); sw.Start(); try { method.Invoke(instance, null); result.WasSuccessful = true; } catch (Exception ex) { result.WasSuccessful = false; result.Message = ex.ToString(); } finally { sw.Stop(); result.Duration = sw.ElapsedMilliseconds; } return result; }
public DynamicStackFrame(CodeContext context, MethodBase method, string funcName, string filename, int line) { _context = context; _funcName = funcName; _filename = filename; _lineNo = line; _method = method; }
//=========================================================================================== private bool IsStatic(MethodBase method) { if (method == null) return false; return method.GetParameters().Length == 0; }
public void Optimize(IQuery q, object predicate, MethodBase filterMethod) { // TODO: cache predicate expressions here var builder = new QueryExpressionBuilder(); var expression = builder.FromMethod(filterMethod); new SODAQueryBuilder().OptimizeQuery(expression, q, predicate, _classFactory, new CecilReferenceResolver()); }
/// <summary> /// Constructor. /// </summary> public MethodTracerItem(TypeEnum itemType, TracerItem.PriorityEnum priority, string message, MethodBase methodInfo, string threadName, string threadId) : base(itemType, priority, message) { _methodBase = methodInfo; _threadId = threadId; _threadName = threadName; }
private void CheckOptionalParametersAltNamesAreNotDuplicated(MethodBase method) { var parameterNames = new List<string>(); foreach (ParameterInfo parameter in method.GetParameters()) { if (_metadata.IsRequired(parameter)) { parameterNames.Add(parameter.Name.ToLower()); } else { if (parameterNames.Contains(parameter.Name.ToLower())) { throw new NConsolerException( "Found duplicated parameter name \"{0}\" in method \"{1}\". Please check alt names for optional parameters", parameter.Name, method.Name); } parameterNames.Add(parameter.Name.ToLower()); var optional = _metadata.GetOptional(parameter); foreach (string altName in optional.AltNames) { if (parameterNames.Contains(altName.ToLower())) { throw new NConsolerException( "Found duplicated parameter name \"{0}\" in method \"{1}\". Please check alt names for optional parameters", altName, method.Name); } parameterNames.Add(altName.ToLower()); } } } }
public MonoMethodMessage (MethodBase method, object [] out_args) { if (method != null) InitMessage ((MonoMethod)method, out_args); else args = null; }
// Messages will be intercepted here and redirected // to another object. public override IMessage Invoke (IMessage msg) { try { if (msg is IConstructionCallMessage) { IActivator remActivator = (IActivator) RemotingServices.Connect (typeof (IActivator), "tcp://localhost:1234/RemoteActivationService.rem"); IConstructionReturnMessage crm = remActivator.Activate ((IConstructionCallMessage) msg); return crm; } else { methodOverloaded = RemotingServices.IsMethodOverloaded ((IMethodMessage) msg); _mthBase = RemotingServices.GetMethodBaseFromMethodMessage ((IMethodMessage) msg); MethodCallMessageWrapper mcm = new MethodCallMessageWrapper ((IMethodCallMessage) msg); mcm.Uri = RemotingServices.GetObjectUri ((MarshalByRefObject) target); MarshalByRefObject objRem = (MarshalByRefObject) Activator.CreateInstance (GetProxiedType ()); RemotingServices.ExecuteMessage ((MarshalByRefObject) objRem, (IMethodCallMessage) msg); IMessage rtnMsg = null; try { rtnMsg = _sink.SyncProcessMessage (msg); } catch (Exception e) { Console.WriteLine (e.Message); } Console.WriteLine ("RR:" + rtnMsg); return rtnMsg; } } catch (Exception ex) { Console.WriteLine (ex); return null; } }
internal static MethodDescriptor Create(MethodBase method, Assembly containingAssembly, bool isDeclaration) { MethodDescriptor descriptor = null; if(method is MethodBuilder) { if(method.IsGenericMethod) { descriptor = new MethodGenericDeclarationDescriptor(method, containingAssembly); } else { descriptor = new MethodDescriptor(method, containingAssembly, isDeclaration); } } else if(method.IsGenericMethodDefinition) { descriptor = new MethodGenericDeclarationDescriptor(method, containingAssembly); } else if(method.IsGenericMethod) { descriptor = new MethodGenericInvocationDescriptor(method, containingAssembly); } else { descriptor = new MethodDescriptor(method, containingAssembly, isDeclaration); } return descriptor; }
protected byte CreateLocalsForByRefParams(byte paramArrayIndex, MethodBase invocationInfo) { byte numberOfByRefParams = 0; ParameterInfo[] parameters = invocationInfo.GetParameters(); for (int i = 0; i < ParameterTypes.Length; i++) { Type paramType = ParameterTypes[i]; if (paramType.IsByRef) { Type type = paramType.GetElementType(); Emit.DeclareLocal(type); if (!parameters[i].IsOut) // no initialization necessary is 'out' parameter { Emit.ldarg(paramArrayIndex) .ldc_i4(i) .ldelem_ref .CastFromObject(type) .stloc(numberOfByRefParams) .end(); } numberOfByRefParams++; } } return numberOfByRefParams; }
public ExceptionThrowingTest(TimeSpan runningTime, MethodBase method, Exception thrownException, IObjectInstance instance = null, IEnumerable<IObjectInstance> arguments = null) : base(runningTime, method, instance, arguments) { if (thrownException == null) throw new ArgumentNullException("thrownException"); Exception = thrownException; }
public MethodReference Import(SR.MethodBase meth, TypeDefinition context) { if (meth == null) { throw new ArgumentNullException("meth"); } CheckContext(context); ImportContext import_context = GetContext(context); if (meth is SR.ConstructorInfo) { return(m_controller.Helper.ImportConstructorInfo( meth as SR.ConstructorInfo, import_context)); } else { return(m_controller.Helper.ImportMethodInfo( meth as SR.MethodInfo, import_context)); } }
static StackObject *op_Inequality_4(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, 2); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); System.Reflection.MethodBase @right = (System.Reflection.MethodBase) typeof(System.Reflection.MethodBase).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); ptr_of_this_method = ILIntepreter.Minus(__esp, 2); System.Reflection.MethodBase @left = (System.Reflection.MethodBase) typeof(System.Reflection.MethodBase).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); var result_of_this_method = left != right; __ret->ObjectType = ObjectTypes.Integer; __ret->Value = result_of_this_method ? 1 : 0; return(__ret + 1); }
/// <summary> /// Construct the method name for later use /// </summary> /// <param name="method"></param> /// <param name="aspectInfo"></param> public override void CompileTimeInitialize(System.Reflection.MethodBase method, AspectInfo aspectInfo) { base.CompileTimeInitialize(method, aspectInfo); MethodName = string.Format("{0}.{1}", method.DeclaringType.Name, method.Name); if (ArgumentName != null) { string name = ArgumentName; if (name.Contains(".")) { name = name.Substring(0, name.IndexOf('.')); } ParameterInfo[] parameters = method.GetParameters(); foreach (ParameterInfo parameter in parameters) { if (parameter.Name == name) { ArgumentIndex = parameter.Position; } } } }
MethodReference ImportMethodSpecification(SR.MethodBase method, IGenericContext context) { var method_info = method as SR.MethodInfo; if (method_info == null) { throw new InvalidOperationException(); } var element_method = ImportMethod(method_info.GetGenericMethodDefinition(), context, ImportGenericKind.Definition); var instance = new GenericInstanceMethod(element_method); var arguments = method.GetGenericArguments(); var instance_arguments = instance.GenericArguments; for (int i = 0; i < arguments.Length; i++) { instance_arguments.Add(ImportType(arguments [i], context ?? element_method)); } return(instance); }
private IList <IParameter> GetArguments(System.Reflection.MethodBase method) { ParameterInfo[] parameters = method.GetParameters(); IParameter[] parameter = new IParameter[(int)parameters.Length]; for (int i = 0; i < (int)parameters.Length; i++) { ParameterInfo parameterInfo = parameters[i]; Type valueType = PlatformTypeHelper.GetValueType(parameterInfo); IType type = null; if (valueType != null) { type = this.typeResolver.GetType(valueType); } if (type == null) { type = this.typeResolver.ResolveType(PlatformTypes.Object); } parameter[i] = new BaseMethod.Parameter(type, parameterInfo.Name); } return(new ReadOnlyCollection <IParameter>(parameter)); }
private System.Collections.Generic.IList <Extent> ExecuteImpl <Extent>( Db4objects.Db4o.Query.IQuery query, object originalPredicate, object matchTarget, System.Reflection.MethodBase matchMethod, System.Predicate <Extent> match, Db4objects.Db4o.Query.IQueryComparator comparator) { Db4objects.Db4o.Query.IQuery q = QueryForExtent <Extent>(query, comparator); try { if (OptimizeNativeQueries()) { OptimizeQuery(q, matchTarget, matchMethod); OnQueryExecution(originalPredicate, QueryExecutionKind.DynamicallyOptimized); return(WrapQueryResult <Extent>(q)); } } catch (FileNotFoundException fnfe) { NativeQueryOptimizerNotLoaded(fnfe); } catch (TargetInvocationException tie) { NativeQueryOptimizerNotLoaded(tie); } catch (TypeLoadException tle) { NativeQueryOptimizerNotLoaded(tle); } catch (System.Exception e) { OnQueryOptimizationFailure(e); NativeQueryUnoptimized(e); } return(ExecuteUnoptimized(q, match)); }
static StackObject *Invoke_12(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, 6); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); System.Globalization.CultureInfo @culture = (System.Globalization.CultureInfo) typeof(System.Globalization.CultureInfo).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); ptr_of_this_method = ILIntepreter.Minus(__esp, 2); System.Object[] @parameters = (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, 3); System.Reflection.Binder @binder = (System.Reflection.Binder) typeof(System.Reflection.Binder).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); ptr_of_this_method = ILIntepreter.Minus(__esp, 4); System.Reflection.BindingFlags @invokeAttr = (System.Reflection.BindingFlags) typeof(System.Reflection.BindingFlags).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); ptr_of_this_method = ILIntepreter.Minus(__esp, 5); System.Object @obj = (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, 6); System.Reflection.MethodBase instance_of_this_method = (System.Reflection.MethodBase) typeof(System.Reflection.MethodBase).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); var result_of_this_method = instance_of_this_method.Invoke(@obj, @invokeAttr, @binder, @parameters, @culture); 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)); }
public FSharpExpr GetInvokerExpression(System.Reflection.MethodBase syntheticMethodBase, FSharpExpr[] parameters) { if (syntheticMethodBase is System.Reflection.ConstructorInfo) { var ac = syntheticMethodBase as ArtificialConstructorInfo; if (ac.DeclaringType.FullName == "N.T") { return(FSharpExpr.DefaultValue(ac.DeclaringType.BaseType)); } Debug.Assert(false, "NYI"); throw new NotImplementedException(); } else if (syntheticMethodBase is System.Reflection.MethodInfo) { var am = syntheticMethodBase as ArtificialMethodInfo; if (am.DeclaringType.FullName == "N.T" && am.Name == "M") { return(FSharpExpr.Lambda(new FSharpVar("", typeof(int[]), null), FSharpExpr.Value <int[]>(new[] { 1, 2, 3 }))); } else if (am.DeclaringType.FullName == "N.T" && am.Name == "get_StaticProp") { // Expression<Func<decimal[]>> e = () => K().Select(x=>(decimal)x).ToArray(); return(FSharpExpr.Lambda(new FSharpVar("", typeof(decimal), null), FSharpExpr.Value <decimal>(4.2M))); } else { Debug.Assert(false, "NYI"); throw new NotImplementedException(); } } else { Debug.Assert(false, "GetInvokerExpression() invoked with neither ConstructorInfo nor MethodInfo!"); return(null); } //Expression<Func<S>> e = () => new S(9); //return e.Body; //throw new NotImplementedException(); }
internal void InitFields(MessageData msgData) { this._frame = msgData.pFrame; this._delegateMD = msgData.pDelegateMD; this._methodDesc = msgData.pMethodDesc; this._flags = msgData.iFlags; this._initDone = true; this._metaSigHolder = msgData.pSig; this._governingType = msgData.thGoverningType; this._MethodName = null; this._MethodSignature = null; this._MethodBase = null; this._URI = null; this._Fault = null; this._ID = null; this._srvID = null; this._callContext = null; if (this._properties != null) { ((IDictionary)this._properties).Clear(); } }
public override bool Rewrite(Meta.CodeDescriptor decompilee, System.Reflection.MethodBase callee, Analysis.StackElement[] args, Analysis.IDecompiler stack, IFunctionBuilder builder) { object[] outArgs; object sample; if (!stack.TryGetReturnValueSample((MethodInfo)callee, args, out outArgs, out sample)) { throw new InvalidOperationException("Unable to create sample for ScSinCos call"); } if (args[1].Variability != Analysis.Msil.EVariability.Constant) { throw new InvalidOperationException("n argument of Rempow2 must be a constant"); } var fcall = IntrinsicFunctions.XILOpCode( new XILInstr(InstructionCodes.Rempow2, (int)args[1].Sample), TypeDescriptor.GetTypeOf(sample), new Expression[] { args[0].Expr }); stack.Push(fcall, sample); return(true); }
public static void Write(Severity enSeverity, System.Reflection.MethodBase oMethod, string sFormat, params object[] Params) { try { Type declaringType = oMethod.DeclaringType; string sTypeName = declaringType.Name; string sMethodName = oMethod.Name; string tempStr = Params != null?string.Format(sFormat, Params) : string.Empty; string message = string.Format("{0}.{1}:{2}", sTypeName, sMethodName, tempStr); Log4NetException excp = getExceptioObj(ref Params); Logger(cfgLogger, enSeverity, message, excp); } catch { Logger(cfgLogger, enSeverity, string.Format("Log.Write - {0}.{1}:{2}", oMethod.DeclaringType.Name, oMethod.Name), null); } }
static public void Warning(string err, System.Reflection.MethodBase mb) { //string msg = string.Format("Warning ({0}.{1}) : {2} ", mb.ReflectedType.Name, mb.Name, err); string msg = ExDash.SetLastWarning(err, mb); if (!Environment.UserInteractive) { send_email(msg); } else { //MessageBox.Show(msg, TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); EventLog.WriteEntry(EVENTSOURCE + " UserInteractive", msg); if (MAIL_ENABLE) { send_email(msg); } } //Application.Exit(); }
static StackObject *RegisterCLRMethodRedirection_0(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); ILRuntime.Runtime.Enviorment.CLRRedirectionDelegate @func = (ILRuntime.Runtime.Enviorment.CLRRedirectionDelegate) typeof(ILRuntime.Runtime.Enviorment.CLRRedirectionDelegate).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); ptr_of_this_method = ILIntepreter.Minus(__esp, 2); System.Reflection.MethodBase @mi = (System.Reflection.MethodBase) typeof(System.Reflection.MethodBase).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); ptr_of_this_method = ILIntepreter.Minus(__esp, 3); ILRuntime.Runtime.Enviorment.AppDomain instance_of_this_method = (ILRuntime.Runtime.Enviorment.AppDomain) typeof(ILRuntime.Runtime.Enviorment.AppDomain).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); instance_of_this_method.RegisterCLRMethodRedirection(@mi, @func); return(__ret); }
static StackObject *Invoke_0(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[] @parameters = (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.Object @obj = (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, 3); System.Reflection.MethodBase instance_of_this_method = (System.Reflection.MethodBase) typeof(System.Reflection.MethodBase).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); var result_of_this_method = instance_of_this_method.Invoke(@obj, @parameters); return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method, true)); }
public override void RuntimeInitialize(System.Reflection.MethodBase method) { className = method.DeclaringType; try { var methods = className.GetMethods(); foreach (var m in methods) { if (m.Name == methodName) { this.method = m; } } } catch (Exception e) { if (Application.Current != null && Application.Current.MainWindow != null && !DesignerProperties.GetIsInDesignMode(Application.Current.MainWindow)) { throw e; } } }
internal MethodResponse(IMethodCallMessage msg, SmuggledMethodReturnMessage smuggledMrm, ArrayList deserializedArgs) { this.MI = msg.MethodBase; this._methodCache = InternalRemotingServices.GetReflectionCachedData(this.MI); this.methodName = msg.MethodName; this.uri = msg.Uri; this.typeName = msg.TypeName; if (this._methodCache.IsOverloaded()) { this.methodSignature = (Type[])msg.MethodSignature; } this.retVal = smuggledMrm.GetReturnValue(deserializedArgs); this.outArgs = smuggledMrm.GetArgs(deserializedArgs); this.fault = smuggledMrm.GetException(deserializedArgs); this.callContext = smuggledMrm.GetCallContext(deserializedArgs); if (smuggledMrm.MessagePropertyCount > 0) { smuggledMrm.PopulateMessageProperties(this.Properties, deserializedArgs); } this.argCount = this._methodCache.Parameters.Length; this.fSoap = false; }
private static string[] GetMethodParameterNames(System.Reflection.MethodBase methodBase) { ArrayList methodParameterNames = new ArrayList(); try { System.Reflection.ParameterInfo[] methodBaseGetParameters = methodBase.GetParameters(); int methodBaseGetParametersCount = methodBaseGetParameters.GetUpperBound(0); for (int i = 0; i <= methodBaseGetParametersCount; i++) { methodParameterNames.Add(methodBaseGetParameters[i].ParameterType + " " + methodBaseGetParameters[i].Name); } } catch (Exception ex) { LogLog.Error(declaringType, "An exception ocurred while retreiving method parameters.", ex); } return((string[])methodParameterNames.ToArray(typeof(string))); }
private static int GetLineNumber(StackFrame frame) { int ilOffset = frame.GetILOffset(); if (ilOffset != StackFrame.OFFSET_UNKNOWN) { MethodBase mb = frame.GetMethod(); if (mb != null && mb.DeclaringType != null) { if (ClassLoaderWrapper.IsRemappedType(mb.DeclaringType)) { return(-1); } TypeWrapper tw = ClassLoaderWrapper.GetWrapperFromType(mb.DeclaringType); if (tw != null) { return(tw.GetSourceLineNumber(mb, ilOffset)); } } } return(-1); }
public ReturnMessage(object ret, object[] outArgs, int outArgsCount, System.Runtime.Remoting.Messaging.LogicalCallContext callCtx, IMethodCallMessage mcm) { this._ret = ret; this._outArgs = outArgs; this._outArgsCount = outArgsCount; if (callCtx != null) { this._callContext = callCtx; } else { this._callContext = CallContext.GetLogicalCallContext(); } if (mcm != null) { this._URI = mcm.Uri; this._methodName = mcm.MethodName; this._methodSignature = null; this._typeName = mcm.TypeName; this._hasVarArgs = mcm.HasVarArgs; this._methodBase = mcm.MethodBase; } }
static string GetTestCaseName(bool fullName) { System.Diagnostics.StackTrace trace = StackTraceHelper.Create(); var frames = trace.GetFrames(); for (int i = 0; i < frames.Length; i++) { System.Reflection.MethodBase method = frames[i].GetMethod(); object[] testAttrs = method.GetCustomAttributes(typeof(NUnit.Framework.TestAttribute), false).ToArray(); if (testAttrs != null && testAttrs.Length > 0) { if (fullName) { return(method.DeclaringType.FullName + "." + method.Name); } else { return(method.Name); } } } return("GetTestCaseName[UnknownTestMethod]"); }
public override void RuntimeInitialize(System.Reflection.MethodBase method) { if (_mode.HasFlag(AuthorizationMode.AccountRequest) || _mode.HasFlag(AuthorizationMode.AccountEntityCommand)) { _accountAuthorizer = IocContainer.AccountRequestAuthorizer; var methodParams = method.GetParameters(); for (int i = 0; i < methodParams.Length; i++) { var param = methodParams[i]; if (param.ParameterType.IsAssignableTo <IAuthoriziedAccountRequest>()) { _authoriziedAccountRequestParams.Add(i); } if (param.ParameterType.IsAssignableTo <IAuthoriziedEntityCommand>() && IocContainer.EntityCommandAuthorizers.TryGetValue(param.ParameterType, out IAuthorizer authorizer)) { _authorizersCache.Add(i, authorizer); } } } if (_mode.HasFlag(AuthorizationMode.ReturnValue) && method is MethodInfo info) { if (info.ReturnType.IsAssignableTo <IHasAccountNumber>()) { _returnValueHasAccountNumber = true; } else if (info.ReturnType.IsAssignableTo <IEnumerable <IHasAccountNumber> >()) { _returnValueHasAccountNumberEnumerable = true; } } base.RuntimeInitialize(method); }
private static string GetMethodName(MethodBase mb) { object[] attr = mb.GetCustomAttributes(typeof(NameSigAttribute), false); if (attr.Length == 1) { return(((NameSigAttribute)attr[0]).Name); } else if (mb.Name == ".ctor") { return("<init>"); } else if (mb.Name == ".cctor") { return("<clinit>"); } else if (mb.Name.StartsWith(NamePrefix.DefaultMethod, StringComparison.Ordinal)) { return(mb.Name.Substring(NamePrefix.DefaultMethod.Length)); } else { return(mb.Name); } }
static string GetMethodBaseSignature(SR.MethodBase meth, Type declaringType, Type retType) { StringBuilder sb = new StringBuilder(); sb.Append(GetTypeSignature(retType)); sb.Append(' '); sb.Append(GetTypeSignature(declaringType)); sb.Append("::"); sb.Append(meth.Name); if (IsGenericMethodSpec(meth)) { sb.Append("<"); Type [] genArgs = GetGenericArguments(meth as SR.MethodInfo); for (int i = 0; i < genArgs.Length; i++) { if (i > 0) { sb.Append(","); } sb.Append(GetTypeSignature(genArgs [i])); } sb.Append(">"); } sb.Append("("); SR.ParameterInfo [] parameters = meth.GetParameters(); for (int i = 0; i < parameters.Length; i++) { if (i > 0) { sb.Append(","); } sb.Append(GetTypeSignature(parameters [i].ParameterType)); } sb.Append(")"); return(sb.ToString()); }
/// <summary> /// Closes the channel /// </summary> private void Close() { try { System.Diagnostics.Trace.WriteLine("Closing channel '" + typeof(T).Name + "'"); // Access m_Channel directly because accessing Channel can cause stack overflow if (m_Channel != null) { // Kill existing channel m_Channel.Faulted -= new EventHandler(Channel_Faulted); try { m_Channel.Close(TimeSpan.FromMilliseconds(100)); } catch (Exception ex) { System.Reflection.MethodBase mb = System.Reflection.MethodBase.GetCurrentMethod(); System.Diagnostics.Trace.WriteLine(ex.Message, string.Format("{0}.{1}.{2}", mb.DeclaringType.Namespace, mb.DeclaringType.Name, mb.Name)); try { m_Channel.Abort(); } catch { // No-op } } } Channel = null; } catch (Exception ex) { System.Reflection.MethodBase mb = System.Reflection.MethodBase.GetCurrentMethod(); System.Diagnostics.Trace.WriteLine(ex.Message, string.Format("{0}.{1}.{2}", mb.DeclaringType.Namespace, mb.DeclaringType.Name, mb.Name)); } }
public MethodReference ImportReference(SR.MethodBase method) { return(ImportReference(method, null)); }
public MethodReference Import(SR.MethodBase method, IGenericParameterProvider context) { return(ImportReference(method, context)); }
public void Execute(SysReflection.MethodBase aStartMethod) { if (aStartMethod == null) { throw new ArgumentNullException("aStartMethod"); } // TODO: Investigate using MS CCI // Need to check license, as well as in profiler // http://cciast.codeplex.com/ #region Description // Methodology // // Ok - we've done the scanner enough times to know it needs to be // documented super well so that future changes won't inadvertently // break undocumented and unseen requirements. // // We've tried many approaches including recursive and additive scanning. // They typically end up being inefficient, overly complex, or both. // // -We would like to scan all types/methods so we can plug them. // -But we can't scan them until we plug them, because we will scan things // that plugs would remove/change the paths of. // -Plugs may also call methods which are also plugged. // -We cannot resolve plugs ahead of time but must do on the fly during // scanning. // -TODO: Because we do on the fly resolution, we need to add explicit // checking of plug classes and err when public methods are found that // do not resolve. Maybe we can make a list and mark, or rescan. Can be done // later or as an optional auditing step. // // This why in the past we had repetitive scans. // // Now we focus on more passes, but simpler execution. In the end it should // be eaiser to optmize and yield overall better performance. Most of the // passes should be low overhead versus an integrated system which often // would need to reiterate over items multiple times. So we do more loops on // with less repetitive analysis, instead of fewer loops but more repetition. // // -Locate all plug classes // -Scan from entry point collecting all types and methods while checking // for and following plugs // -For each type // -Include all ancestors // -Include all static constructors // -For each virtual method // -Scan overloads in descendants until IsFinal, IsSealed or end // -Scan base in ancestors until top or IsAbstract // -Go to scan types again, until no new ones found. // -Because the virtual method scanning will add to the list as it goes, maintain // 2 lists. // -Known Types and Methods // -Types and Methods in Queue - to be scanned // -Finally, do compilation #endregion mPlugManager.FindPlugImpls(); // Now that we found all plugs, scan them. // We have to scan them after we find all plugs, because // plugs can use other plugs mPlugManager.ScanFoundPlugs(); foreach (var xPlug in mPlugManager.PlugImpls) { CompilerHelpers.Debug($"Plug found: '{xPlug.Key.FullName}'"); } ILOp.mPlugManager = mPlugManager; // Pull in extra implementations, GC etc. Queue(RuntimeEngineRefs.InitializeApplicationRef, null, "Explicit Entry"); Queue(RuntimeEngineRefs.FinalizeApplicationRef, null, "Explicit Entry"); //Queue(typeof(CosmosAssembler).GetMethod("PrintException"), null, "Explicit Entry"); Queue(VTablesImplRefs.SetMethodInfoRef, null, "Explicit Entry"); Queue(VTablesImplRefs.IsInstanceRef, null, "Explicit Entry"); Queue(VTablesImplRefs.SetTypeInfoRef, null, "Explicit Entry"); Queue(VTablesImplRefs.GetMethodAddressForTypeRef, null, "Explicit Entry"); Queue(GCImplementationRefs.IncRefCountRef, null, "Explicit Entry"); Queue(GCImplementationRefs.DecRefCountRef, null, "Explicit Entry"); Queue(GCImplementationRefs.AllocNewObjectRef, null, "Explicit Entry"); // for now, to ease runtime exception throwing Queue(typeof(ExceptionHelper).GetMethod("ThrowNotImplemented", BindingFlags.Static | BindingFlags.Public, null, new Type[] { typeof(string) }, null), null, "Explicit Entry"); Queue(typeof(ExceptionHelper).GetMethod("ThrowOverflow", BindingFlags.Static | BindingFlags.Public, null, new Type[] { }, null), null, "Explicit Entry"); Queue(RuntimeEngineRefs.InitializeApplicationRef, null, "Explicit Entry"); Queue(RuntimeEngineRefs.FinalizeApplicationRef, null, "Explicit Entry"); // register system types: Queue(typeof(Array), null, "Explicit Entry"); Queue(typeof(Array).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, Type.EmptyTypes, null), null, "Explicit Entry"); var xThrowHelper = Type.GetType("System.ThrowHelper", true); Queue(xThrowHelper.GetMethod("ThrowInvalidOperationException", BindingFlags.NonPublic | BindingFlags.Static), null, "Explicit Entry"); Queue(typeof(MulticastDelegate).GetMethod("GetInvocationList"), null, "Explicit Entry"); Queue(ExceptionHelperRefs.CurrentExceptionRef, null, "Explicit Entry"); //System_Delegate____System_MulticastDelegate_GetInvocationList__ // Start from entry point of this program Queue(aStartMethod, null, "Entry Point"); ScanQueue(); UpdateAssemblies(); Assemble(); mAsmblr.EmitEntrypoint(aStartMethod); }
public MethodReference Import(SR.MethodBase method) { CheckMethod(method); return(MetadataImporter.ImportMethod(method, null, ImportGenericKind.Definition)); }
public MethodReference Import(SR.MethodBase method, MethodReference context) { return(Import(method, (IGenericParameterProvider)context)); }
public static bool IsInternalFrame(System.Reflection.MethodBase mb) { throw null; }