Пример #1
0
		static void AddCapturedLocalVariables(List<LocalVariable> vars, IMethod method, ILRange[] ilranges, ValueGetter getCaptureClass, IType captureClassType)
		{
			if (captureClassType.IsDisplayClass()) {
				foreach(IField fieldInfo in captureClassType.GetFields()) {
					IField fieldInfoCopy = fieldInfo;
					if (fieldInfo.Name.StartsWith("CS$")) continue; // Ignore
					LocalVariable locVar = new LocalVariable(
						method,
						-1,
						fieldInfo.Type,
						fieldInfo.Name,
						ilranges,
						// TODO: Use eval thread
						context => getCaptureClass(context).GetFieldValue(context.Thread, fieldInfoCopy)
					);
					locVar.IsCaptured = true;
					if (locVar.Name.StartsWith("<>")) {
						if (locVar.Name.EndsWith("__this")) {
							locVar.Name = "this";
							locVar.IsThis = true;
						} else {
							continue; // Ignore
						}
					}
					if (locVar.Name.StartsWith("<")) {
						int endIndex = locVar.Name.IndexOf('>');
						if (endIndex == -1) continue; // Ignore
						locVar.Name = fieldInfo.Name.Substring(1, endIndex - 1);
					}
					vars.Add(locVar);
				}
			}
		}
Пример #2
0
		public static List<LocalVariable> GetLocalVariables(ISymbolSource symbolSource, IMethod method)
		{
			var module = method.ParentAssembly.GetModule();
			
			List<LocalVariable> localVariables = new List<LocalVariable>();
			
			foreach (ILLocalVariable ilvar in symbolSource.GetLocalVariables(method)) {
				int index = ilvar.Index;
				// NB: Display class does not have the compiler-generated flag
				if (ilvar.IsCompilerGenerated || ilvar.Name.StartsWith("CS$")) {
					// Get display class from local variable
					AddCapturedLocalVariables(
						localVariables,
						method,
						ilvar.ILRanges,
						context => GetLocalVariableValue(context, index),
						ilvar.Type
					);
				} else {
					LocalVariable locVar = new LocalVariable(
						method,
						ilvar.Index,
						ilvar.Type,
						ilvar.Name,
						ilvar.ILRanges,
						context => GetLocalVariableValue(context, index)
					);
					localVariables.Add(locVar);
				}
			}
			
			if (method.DeclaringType.IsDisplayClass()) {
				// Get display class from 'this'
				AddCapturedLocalVariables(
					localVariables,
					method,
					new [] { new ILRange(0, int.MaxValue) },
					context => context.GetThisValue(false),
					method.DeclaringType
				);
				// Get display classes from fields
				foreach(IField fieldInfo in method.DeclaringType.GetFields(f => f.Name.StartsWith("CS$"), GetMemberOptions.None)) {
					IField fieldInfoCopy = fieldInfo;
					AddCapturedLocalVariables(
						localVariables,
						method,
						new [] { new ILRange(0, int.MaxValue) },
						// TODO: Use eval thread
						context => context.GetThisValue(false).GetFieldValue(context.Thread, fieldInfoCopy),
						fieldInfo.Type
					);
				}
			} else {
				// Add this
				if (!method.IsStatic) {
					LocalVariable thisVar = new LocalVariable(
						method,
						-1,
						method.DeclaringType,
						"this",
						new [] { new ILRange(0, int.MaxValue) },
						context => context.GetThisValue(false)
					);
					thisVar.IsThis = true;
					localVariables.Add(thisVar);
				}
			}
			
			return localVariables;
		}
Пример #3
0
        public static List <LocalVariable> GetLocalVariables(ISymbolSource symbolSource, IMethod method)
        {
            var module = method.ParentAssembly.GetModule();

            List <LocalVariable> localVariables = new List <LocalVariable>();

            foreach (ILLocalVariable ilvar in symbolSource.GetLocalVariables(method))
            {
                int index = ilvar.Index;
                // NB: Display class does not have the compiler-generated flag
                if (ilvar.IsCompilerGenerated || ilvar.Name.StartsWith("CS$"))
                {
                    // Get display class from local variable
                    AddCapturedLocalVariables(
                        localVariables,
                        method,
                        ilvar.ILRanges,
                        context => GetLocalVariableValue(context, index),
                        ilvar.Type
                        );
                }
                else
                {
                    LocalVariable locVar = new LocalVariable(
                        method,
                        ilvar.Index,
                        ilvar.Type,
                        ilvar.Name,
                        ilvar.ILRanges,
                        context => GetLocalVariableValue(context, index)
                        );
                    localVariables.Add(locVar);
                }
            }

            if (method.DeclaringType.IsDisplayClass())
            {
                // Get display class from 'this'
                AddCapturedLocalVariables(
                    localVariables,
                    method,
                    new [] { new ILRange(0, int.MaxValue) },
                    context => context.GetThisValue(false),
                    method.DeclaringType
                    );
                // Get display classes from fields
                foreach (IField fieldInfo in method.DeclaringType.GetFields(f => f.Name.StartsWith("CS$"), GetMemberOptions.None))
                {
                    IField fieldInfoCopy = fieldInfo;
                    AddCapturedLocalVariables(
                        localVariables,
                        method,
                        new [] { new ILRange(0, int.MaxValue) },
                        // TODO: Use eval thread
                        context => context.GetThisValue(false).GetFieldValue(context.Thread, fieldInfoCopy),
                        fieldInfo.Type
                        );
                }
            }
            else
            {
                // Add this
                if (!method.IsStatic)
                {
                    LocalVariable thisVar = new LocalVariable(
                        method,
                        -1,
                        method.DeclaringType,
                        "this",
                        new [] { new ILRange(0, int.MaxValue) },
                        context => context.GetThisValue(false)
                        );
                    thisVar.IsThis = true;
                    localVariables.Add(thisVar);
                }
            }

            return(localVariables);
        }