Esempio n. 1
0
        public override ILValue CreateInstance(DmdConstructorInfo ctor, ILValue[] arguments)
        {
            DbgDotNetValueResult res;

            DbgDotNetArrayDimensionInfo[] dimensionInfos;
            switch (ctor.SpecialMethodKind)
            {
            case DmdSpecialMethodKind.Array_Constructor1:
                dimensionInfos = new DbgDotNetArrayDimensionInfo[arguments.Length];
                for (int i = 0; i < dimensionInfos.Length; i++)
                {
                    dimensionInfos[i] = new DbgDotNetArrayDimensionInfo(0, (uint)ReadInt32(arguments[i]));
                }
                res = runtime.CreateArray(context, frame, ctor.ReflectedType.GetElementType(), dimensionInfos, cancellationToken);
                return(CreateILValue(res));

            case DmdSpecialMethodKind.Array_Constructor2:
                dimensionInfos = new DbgDotNetArrayDimensionInfo[arguments.Length / 2];
                for (int i = 0; i < dimensionInfos.Length; i++)
                {
                    dimensionInfos[i] = new DbgDotNetArrayDimensionInfo(ReadInt32(arguments[i * 2]), (uint)ReadInt32(arguments[i * 2 + 1]));
                }
                res = runtime.CreateArray(context, frame, ctor.ReflectedType.GetElementType(), dimensionInfos, cancellationToken);
                return(CreateILValue(res));

            default:
                res = runtime.CreateInstance(context, frame, ctor, Convert(arguments, ctor.GetMethodSignature().GetParameterTypes()), cancellationToken);
                return(CreateILValue(res));
            }
        }
Esempio n. 2
0
		DbgDotNetValueResult CreateInstanceCore(DmdConstructorInfo ctor, ILValue[] arguments) {
			if (ctor.IsStatic)
				return new DbgDotNetValueResult(PredefinedEvaluationErrorMessages.InternalDebuggerError);

			const DotNetClassHookCallOptions options = DotNetClassHookCallOptions.None;
			foreach (var anyHook in anyClassHooks) {
				var res = anyHook.CreateInstance(options, ctor, arguments);
				if (res != null)
					return new DbgDotNetValueResult(res, valueIsException: false);
			}

			var type = ctor.DeclaringType;
			if (type.IsConstructedGenericType)
				type = type.GetGenericTypeDefinition();
			var typeName = DmdTypeName.Create(type);
			if (classHooks.TryGetValue(typeName, out var hook)) {
				if (DmdWellKnownTypeUtils.TryGetWellKnownType(typeName, out var wellKnownType)) {
					if (type != type.AppDomain.GetWellKnownType(wellKnownType, isOptional: true))
						hook = null;
				}
				if (hook != null) {
					var res = hook.CreateInstance(options, ctor, arguments);
					if (res != null)
						return new DbgDotNetValueResult(res, valueIsException: false);
				}
			}

			if (!canFuncEval)
				throw new InterpreterMessageException(PredefinedEvaluationErrorMessages.FuncEvalDisabled);
			return runtime.CreateInstance(context, frame, ctor, Convert(arguments, ctor.GetMethodSignature().GetParameterTypes()), cancellationToken);
		}