예제 #1
0
            public object Get(IReadonlyContext context)
            {
                var result = context.TryGet(_parameter, out var val) ? val : _parameter.DefaultValue;

                _parameter.IsValidOrThrow(result);
                if (!(_adapter?.IsValid(_parameter.Field, result) ?? true))
                {
                    throw new ArgumentException($"Value of field '{_parameter.Field}' is invalid");
                }
                return(result);
            }
예제 #2
0
            public object Get(IReadonlyContext context)
            {
                var instance = Activator.CreateInstance(_targetType);

                foreach (var pair in _fieldInitializerDict)
                {
                    pair.Key.SetValue(instance, pair.Value.Get(context));
                }
                if (!(_adapter?.IsValid(_field, instance) ?? true))
                {
                    throw new ArgumentException($"Value of field '{_field}' is invalid");
                }
                return(instance);
            }