コード例 #1
0
        public ValidateOptionsResult Validate(string?name, TOptions options)
        {
            // Null name is used to configure all named options.
            if (Name != null && Name != name)
            {
                // Ignored if not validating this instance.
                return(ValidateOptionsResult.Skip);
            }

            // Ensure options are provided to validate against
            ThrowHelper.ThrowIfNull(options);

            var validationResults = new List <ValidationResult>();

            if (Validator.TryValidateObject(options, new ValidationContext(options), validationResults, validateAllProperties: true))
            {
                return(ValidateOptionsResult.Success);
            }

            string typeName = options.GetType().Name;
            var    errors   = new List <string>();

            foreach (ValidationResult result in validationResults)
            {
                errors.Add($"DataAnnotation validation failed for '{typeName}' members: '{string.Join(",", result.MemberNames)}' with the error: '{result.ErrorMessage}'.");
            }

            return(ValidateOptionsResult.Fail(errors));
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: synctam/SuJpModAid
        private static int Main(string[] args)
        {
            var opt = new TOptions(args);

            if (opt.IsError)
            {
                TDebugUtils.Pause();
                return(1);
            }

            if (opt.Arges.Help)
            {
                opt.ShowUsage();

                TDebugUtils.Pause();
                return(1);
            }

            //// 空の言語情報を作成
            var langInfo = new SuLanguageInfo();

            //// 言語ファイルを格納されているフォルダーから読み込み、言語情報に格納する。
            SuLanguageDao.LoadFromFolder(langInfo, opt.Arges.FolderNameLangInput);
            //// 言語情報を使い翻訳シートをCSV形式で保存する。
            SuTransSheetDao.SaveToCsv(langInfo, opt.Arges.FileNameSheet);

            TDebugUtils.Pause();
            return(0);
        }
コード例 #3
0
        public static IEnumerable <OptionSource> Get <TOptions>() where TOptions : new()
        {
            var defaultOptions = new TOptions();

            return(typeof(TOptions).GetProperties()
                   .Select(property => OptionSource.Typed("<DEFAULT>", property.Name, property.GetValue(defaultOptions, null))));
        }
コード例 #4
0
        public static TOptions GetTestOptions <TOptions>()
            where TOptions : TestOptionAttributeBase, new()
        {
            TestContext.TestAdapter test = TestContext.CurrentContext.Test;
            var typeName   = test.ClassName;
            var methodName = test.MethodName;

            // This will only get types from whatever is already loaded in the app domain.
            var type = Type.GetType(typeName, false);

            if (type == null)
            {
                // automatically add the executing and calling assemblies to the list to scan for this type
                var scanAssemblies = ScanAssemblies.Union(new[] { Assembly.GetExecutingAssembly(), Assembly.GetCallingAssembly() }).ToList();

                type = scanAssemblies
                       .Select(assembly => assembly.GetType(typeName, false))
                       .FirstOrDefault(x => x != null);
                if (type == null)
                {
                    throw new PanicException($"Could not resolve the running test fixture from type name {typeName}.\n" +
                                             $"To use base classes from Umbraco.Tests, add your test assembly to TestOptionAttributeBase.ScanAssemblies");
                }
            }

            MethodInfo methodInfo = type.GetMethod(methodName); // what about overloads?
            TOptions   options    = GetTestOptions <TOptions>(methodInfo);

            return(options);
        }
コード例 #5
0
        private static int Main(string[] args)
        {
            var opt = new TOptions(args);

            if (opt.IsError)
            {
                TDebugUtils.Pause();
                return(1);
            }

            if (opt.Arges.Help)
            {
                opt.ShowUsage();

                TDebugUtils.Pause();
                return(1);
            }

            //// 翻訳シートを読み込む。
            var transSheet = SuTransSheetDao.LoadFromCsv(opt.Arges.FileNameSheet);

            //// 翻訳シートと原文の言語情報から翻訳された言語ファイルを保存する。
            SuLanguageDao.SaveToFolder(
                transSheet,
                opt.Arges.FolderNameInput,
                opt.Arges.FileNameOutput,
                opt.Arges.UseMachineTrans,
                opt.Arges.UseReplace);

            TDebugUtils.Pause();
            return(0);
        }
コード例 #6
0
ファイル: OptionsBase.cs プロジェクト: lvyitian/Alex
        protected TOptions DefineBranch <TOptions>() where TOptions : OptionsBase, new()
        {
            var opt = new TOptions();

            Properties.Add(opt);
            return(opt);
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: synctam/CrsJpModAid
        private static int Main(string[] args)
        {
            try
            {
                TOptions opt = new TOptions(args);
                if (opt.IsError)
                {
                    TDebugUtils.Pause();
                    return(1);
                }

                if (opt.Arges.Help)
                {
                    opt.ShowUsage();

                    TDebugUtils.Pause();
                    return(1);
                }

                MakeSheet(opt.Arges);
                return(0);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);

                TDebugUtils.Pause();
                return(1);
            }
        }
コード例 #8
0
ファイル: OptionsMonitor.cs プロジェクト: mikem8361/runtime
        private void InvokeChanged(string?name)
        {
            name ??= Options.DefaultName;
            _cache.TryRemove(name);
            TOptions options = Get(name);

            _onChange?.Invoke(options, name);
        }
コード例 #9
0
 /// <summary>
 /// Tries to adds a new option to the cache, will return false if the name already exists.
 /// </summary>
 /// <param name="name">The name of the options instance.</param>
 /// <param name="options">The options instance.</param>
 /// <returns>Whether anything was added.</returns>
 public virtual bool TryAdd(string name, TOptions options)
 {
     if (options == null)
     {
         throw new ArgumentNullException(nameof(options));
     }
     name = name ?? Options.DefaultName;
     return(_cache.TryAdd(name, new Lazy <TOptions>(() => options)));
 }
コード例 #10
0
        public CIDBAttributeCell(TOptions aOptions)
        {
            if (aOptions == TOptions.ENone)
            {
                throw new ArgumentException("Options cannot be \'none\'");
            }

            iOptions = aOptions;
        }
コード例 #11
0
 private void InvokeChanged(string? name)
 {
     name = name ?? Options.DefaultName;
     _cache.TryRemove(name);
     TOptions options = Get(name);
     if (_onChange != null)
     {
         _onChange.Invoke(options, name);
     }
 }
コード例 #12
0
 protected RandomForestObjectiveFunction(Dataset trainData, TOptions options, double maxStepSize)
     : base(trainData,
            1,     // No learning rate in random forests.
            1,     // No shrinkage in random forests.
            maxStepSize,
            1,     // No derivative sampling in random forests.
            false, // Improvements to quasi-newton step not relevant to RF.
            options.Seed)
 {
 }
コード例 #13
0
        public static TOptions GetTestOptions <TOptions>()
            where TOptions : TestOptionAttributeBase, new()
        {
            TestContext.TestAdapter test = TestContext.CurrentContext.Test;
            var        methodName        = test.MethodName;
            var        type       = TestExecutionContext.CurrentContext.TestObject.GetType();
            MethodInfo methodInfo = type.GetMethod(methodName); // what about overloads?
            TOptions   options    = GetTestOptions <TOptions>(methodInfo);

            return(options);
        }
コード例 #14
0
        public OptionSource[] Get <TOptions>() where TOptions : IOptions, new()
        {
            _parsedOptions = new List <OptionSource>();
            var defaultOptions = new TOptions();

            foreach (var property in typeof(TOptions).GetProperties())
            {
                _parsedOptions.Add(new OptionSource("<DEFAULT>", property.Name, property.GetValue(defaultOptions, null)));
            }
            return(_parsedOptions.ToArray());
        }
コード例 #15
0
        private static List <Tuple <string, OptionSource> > SetupOptionsForDumping <TOptions>() where TOptions : IOptions, new()
        {
            var options       = new TOptions();
            var parsedOptions = new List <Tuple <string, OptionSource> >();

            foreach (var property in typeof(TOptions).GetProperties())
            {
                var defaultValue = property.GetValue(options, null);
                parsedOptions.Add(new Tuple <string, OptionSource>(property.Name, new OptionSource(DefaultOptionSource, defaultValue)));
            }
            return(parsedOptions);
        }
コード例 #16
0
            public MethodGenerationArgs()
            {
                EnumType       = typeof(TEnum);
                StreamType     = typeof(TStreamType);
                UnderlyingType = Enum.GetUnderlyingType(EnumType);

                // Check if the user wants us to always use the underlying type
                UseUnderlyingType = StreamType == typeof(EnumBinaryStreamerUseUnderlyingType);
                if (UseUnderlyingType)
                {
                    StreamType = UnderlyingType;
                }

                EnumUtils.AssertTypeIsEnum(EnumType);
                EnumUtils.AssertUnderlyingTypeIsSupported(EnumType, UnderlyingType);
                AssertStreamTypeIsValid(out StreamTypeIsSigned);

                UnderlyingTypeNeedsConversion = UnderlyingType != StreamType;

                Options = new TOptions();

                if (Options.UseNoneSentinelEncoding)
                {
                    if (StreamType == typeof(sbyte) || StreamType == typeof(byte))
                    {
                        throw new ArgumentException(
                                  "{0}: UseNoneSentinelEncoding can't operate on (s)byte types (StreamType)",
                                  EnumType.FullName);
                    }
                }
                #region Options.BitSwap
                if (Options.BitSwap)
                {
                    if (StreamTypeIsSigned)
                    {
                        throw new ArgumentException(
                                  "{0}: Bit-swapping only makes sense on flags/unsigned types, but StreamType is signed",
                                  EnumType.FullName);
                    }
                }
                else
                {
                    if (Options.BitSwapGuardAgainstOneBit)
                    {
                        Debug.Trace.IO.TraceInformation("{0}'s {1} says we should guard against one bit cases, but not bitswap",
                                                        EnumType.FullName, typeof(TOptions).FullName);
                    }
                }
                #endregion
            }
コード例 #17
0
ファイル: OptionsSnapshot.cs プロジェクト: savionak/runtime
        /// <summary>
        /// Returns a configured <typeparamref name="TOptions"/> instance with the given <paramref name="name"/>.
        /// </summary>
        public TOptions Get(string name)
        {
            if (name == null || name == Options.DefaultName)
            {
                if (_unnamedOptionsValue is TOptions value)
                {
                    return(value);
                }

                return(_unnamedOptionsValue = _optionsMonitor.Get(Options.DefaultName));
            }

            var cache = _cache ?? Interlocked.CompareExchange(ref _cache, new(concurrencyLevel: 1, capacity: 5, StringComparer.Ordinal), null) ?? _cache;

#if NETSTANDARD2_1
            TOptions options = cache.GetOrAdd(name, static (name, optionsMonitor) => optionsMonitor.Get(name), _optionsMonitor);
コード例 #18
0
ファイル: Program.cs プロジェクト: synctam/PfkJpModAid
        private static int Main(string[] args)
        {
            //// コマンドラインオプションの処理
            TOptions opt = new TOptions(args);

            if (opt.IsError)
            {
                TDebugUtils.Pause();
                return(1);
            }

            if (opt.Arges.Help)
            {
                opt.ShowUsage();

                TDebugUtils.Pause();
                return(1);
            }

            try
            {
                switch (opt.Arges.SheetType)
                {
                case TOptions.NSheetType.Csv:
                    MakeCsv(opt.Arges);
                    break;

                case TOptions.NSheetType.Excel:
                    MakeExcel(opt.Arges);
                    break;

                case TOptions.NSheetType.Unknown:
                default:
                    var msg = $"Unknown sheet type error. SheetType({opt.Arges.SheetType})";
                    throw new Exception(msg);
                }

                TDebugUtils.Pause();
                return(0);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                TDebugUtils.Pause();
                return(1);
            }
        }
コード例 #19
0
        private static int Main(string[] args)
        {
            var opt = new TOptions(args);

            if (opt.IsError)
            {
                TDebugUtils.Pause();
                return(1);
            }

            if (opt.Arges.Help)
            {
                opt.ShowUsage();

                TDebugUtils.Pause();
                return(1);
            }

            try
            {
                if (opt.Arges.CommandDialog)
                {
                    SheetDialog(opt.Arges);
                }
                else if (opt.Arges.CommandLocalization)
                {
                    SheetLocalization(opt.Arges);
                }
                else
                {
                    throw new Exception($"Unknown error.");
                }

                TDebugUtils.Pause();
                return(0);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);

                TDebugUtils.Pause();
                return(1);
            }
        }
コード例 #20
0
            public static void LoadFromString()
            {
                if (StringThunk != null)
                {
                    return;
                }

                lock (StringThunkInitLock)
                {
                    if (StringThunk != null || StringThunkBeingBuilt)
                    {
                        return;
                    }
                    StringThunkBeingBuilt = true;

                    var options = new TOptions();

                    StringThunk = InlineDeserializerHelper.BuildFromString <T>(typeof(TOptions), options.DateFormat, options.SerializationNameFormat, exceptionDuringBuild: out ExceptionDuringBuildFromString);
                }
            }
コード例 #21
0
        private static int Main(string[] args)
        {
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfoByIetfLanguageTag("en");

            Stopwatch sw = new Stopwatch();
            sw.Start();

            TOptions opt = new TOptions(args);
            if (opt.IsError)
            {
                TDebugUtils.Pause();
                return 1;
            }

            if (opt.Arges.Help)
            {
                opt.ShowUsage();

                TDebugUtils.Pause();
                return 1;
            }

            if (opt.Arges.IsInit)
            {
                InitDB(opt.Arges);
            }
            else
            {
                //// ToDo: テスト期間中は初期化を行う。
                //// InitDB(opt.Arges);

                OE2DB_No2(opt.Arges);
                DB2MieObj(opt.Arges);
            }

            sw.Stop();
            Console.WriteLine(sw.Elapsed);

            TDebugUtils.Pause();
            return 0;
        }
コード例 #22
0
ファイル: OptionsFactory.cs プロジェクト: z77ma/runtime
        /// <summary>
        /// Returns a configured <typeparamref name="TOptions"/> instance with the given <paramref name="name"/>.
        /// </summary>
        public TOptions Create(string name)
        {
            TOptions options = CreateInstance(name);

            foreach (IConfigureOptions <TOptions> setup in _setups)
            {
                if (setup is IConfigureNamedOptions <TOptions> namedSetup)
                {
                    namedSetup.Configure(name, options);
                }
                else if (name == Options.DefaultName)
                {
                    setup.Configure(options);
                }
            }
            foreach (IPostConfigureOptions <TOptions> post in _postConfigures)
            {
                post.PostConfigure(name, options);
            }

            if (_validations.Length > 0)
            {
                var failures = new List <string>();
                foreach (IValidateOptions <TOptions> validate in _validations)
                {
                    ValidateOptionsResult result = validate.Validate(name, options);
                    if (result is not null && result.Failed)
                    {
                        failures.AddRange(result.Failures);
                    }
                }
                if (failures.Count > 0)
                {
                    throw new OptionsValidationException(name, typeof(TOptions), failures);
                }
            }

            return(options);
        }
コード例 #23
0
ファイル: Program.cs プロジェクト: synctam/PoE2JpModTools
        /// <summary>
        /// 翻訳シートと言語DBから統合版日本語化MODを作成する。
        /// </summary>
        /// <param name="args">args</param>
        /// <returns>終了コード</returns>
        private static int Main(string[] args)
        {
            TOptions opt = new TOptions(args);

            if (opt.IsError)
            {
                TDebugUtils.Pause();
                return(1);
            }

            if (opt.Arges.Help)
            {
                opt.ShowUsage();

                TDebugUtils.Pause();
                return(1);
            }

            CreateMod(opt.Arges);

            TDebugUtils.Pause();
            return(0);
        }
コード例 #24
0
 /// <summary>
 /// Creates a wrapper around an instance of <typeparamref name="TOptions"/> to return itself as an <see cref="IOptions{TOptions}"/>.
 /// </summary>
 /// <typeparam name="TOptions">Options type.</typeparam>
 /// <param name="options">Options object.</param>
 /// <returns>Wrapped options object.</returns>
 public static IOptions <TOptions> Create <[DynamicallyAccessedMembers(DynamicallyAccessedMembers)] TOptions>(TOptions options)
     where TOptions : class
 {
     return(new OptionsWrapper <TOptions>(options));
 }
コード例 #25
0
 public Microsoft.Extensions.Options.ValidateOptionsResult Validate(string name, TOptions options)
 {
     throw null;
 }
コード例 #26
0
 public void OnChangeException(TOptions options, string name, Exception e) => _listener.Invoke(options, name, e);
コード例 #27
0
 public void OnChange(TOptions options, string name) => _listener.Invoke(options, name);
コード例 #28
0
 public OptionsWrapper(TOptions options)
 {
 }
        protected override RemoteWebDriver CreateDriver(TService service, TOptions options, TimeSpan commandTimeout)
        {
            Context.Set(service, options, commandTimeout);

            return(Context.ReturnsNull ? null : base.CreateDriver(service, options, commandTimeout));
        }
コード例 #30
0
 private static void BindFromOptions(TOptions options, IConfiguration config) => ConfigurationBinder.Bind(config, options);