예제 #1
0
        internal object GetValue(Type type)
        {
            var val = GetTargetArg(type);

            if (val != null)
            {
                return(val);
            }

            // Nullable
            if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable <>))
            {
                var v = _values.Get();
                // GetHasValue
                var hasValue = (bool)v.GetValue(typeof(bool));
                if (!hasValue)
                {
                    return(null);
                }

                var baseType    = Nullable.GetUnderlyingType(type);
                var genericType = typeof(Nullable <>).MakeGenericType(baseType);
                return(Activator.CreateInstance(genericType, v.GetValue(baseType)));
            }

            if (IsClassOrStruct(type))
            {
                var instance = Activator.CreateInstance(type);
                var v        = _values.Get();
                foreach (var field in type.GetFields(Flags))
                {
                    field.SetValue(instance, v.GetValue(field.FieldType));
                }

                return(instance);
            }

            return(null);
        }
        internal object GetValue(Type type)
        {
            if (type.IsArray)
            {
                var array = (Array)Activator.CreateInstance(type, Values.Length);
                for (var i = 0; i < Values.Length; i++)
                {
                    array.SetValue(Values.Get().GetValue(_elementType), i);
                }

                return(array);
            }

            var genericType = typeof(List <>).MakeGenericType(_elementType);
            var list        = (IList)Activator.CreateInstance(genericType);

            for (var i = 0; i < Values.Length; i++)
            {
                list.Add(Values.Get().GetValue(_elementType));
            }

            return(list);
        }
예제 #3
0
        /// <summary>
        /// 引数を取得
        /// </summary>
        internal object[] GetArgs(MethodInfo info)
        {
            var parameters = info.GetParameters();
            var returns    = new object[parameters.Length];

            _args.ResetIndex();
            for (var i = 0; i < parameters.Length; i++)
            {
                var arg = _args.Get();
                arg.ResetIndex();
                returns[i] = arg.GetValue(parameters[i].ParameterType);
            }

            return(returns);
        }