PositiveTimeSpanValidatorとは? わかりやすく解説

PositiveTimeSpanValidator クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

TimeSpan オブジェクト検証提供します。このクラス継承できません。

名前空間: System.Configuration
アセンブリ: System.Configuration (system.configuration.dll 内)
構文構文

Public Class PositiveTimeSpanValidator
    Inherits ConfigurationValidatorBase
Dim instance As PositiveTimeSpanValidator
public class PositiveTimeSpanValidator : ConfigurationValidatorBase
public ref class PositiveTimeSpanValidator
 : public ConfigurationValidatorBase
public class PositiveTimeSpanValidator extends
 ConfigurationValidatorBase
public class PositiveTimeSpanValidator extends
 ConfigurationValidatorBase
解説解説
使用例使用例

PositiveTimeSpanValidator 型を使用する方法次のコード例示します

Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Configuration
Imports System.ComponentModel

Namespace Samples.AspNet.Configuration

    ' Implements a custom validator attribute. 
    <AttributeUsage(AttributeTargets.Property)> _
      Public NotInheritable Class
 CustomValidatorAttribute
        Inherits ConfigurationValidatorAttribute

        Public Sub New()
        End Sub 'New

        Public Sub New(ByVal
 validator As Type)
            MyBase.New(validator)
        End Sub 'New

        Public Shadows ReadOnly
 Property _
        ValidatorType() As Type
            Get
                Return [GetType]()
            End Get
        End Property

        Public Overrides ReadOnly
 Property ValidatorInstance() As ConfigurationValidatorBase
            Get
                ' Create validator.
                Return New PositiveTimeSpanValidator()
            End Get
        End Property
    End Class

    ' Implements a custom section class.
    Public Class SampleSection
        Inherits ConfigurationSection
        <ConfigurationProperty("name", DefaultValue:="MyBuildRoutine",
 IsRequired:=True), _
        StringValidator(InvalidCharacters:=" ~!@#$%^&*()[]{}/;'""|\",
 _
        MinLength:=1, MaxLength:=60)> _
         Public Property Name() As
 String
            Get
                Return CType(Me("name"),
 String)
            End Get
            Set(ByVal Value As
 String)
                Me("name") = Value
            End Set
        End Property

        <ConfigurationProperty("BuildStartTime",
 IsRequired:=True, _
          DefaultValue:="09:00:00")> _
        Public Property BuildStartTime() As
 TimeSpan
            Get
                Dim myTSC As TimeSpanConverter
 = New TimeSpanConverter()
                Return CType(Me("BuildStartTime"),
 TimeSpan)
            End Get
            Set(ByVal Value As
 TimeSpan)
                Me("BuildStartTime")
 = Value.ToString()
            End Set
        End Property

        <ConfigurationProperty("BuildEndTime",
 IsRequired:=True, _
          DefaultValue:="17:00:00")> _
        Public Property BuildEndTime() As
 TimeSpan
            Get
                Dim myTSC As TimeSpanConverter
 = New TimeSpanConverter()
                Return CType(Me("BuildEndTime"),
 TimeSpan)
            End Get
            Set(ByVal Value As
 TimeSpan)
                Me("BuildEndTime")
 = Value.ToString()
            End Set
        End Property
    End Class

    ' Implements the console user interface.
    Class TestingCustomValidatorAttribute
        ' Shows how to use the ValidatorInstance method.
        Public Shared Sub
 GetCustomValidatorInstance()
            Dim valBase As ConfigurationValidatorBase
            Dim customValAttr As CustomValidatorAttribute
            customValAttr = New CustomValidatorAttribute()

            Dim sampleSection As SampleSection
 = ConfigurationManager.GetSection("MyDailyProcess")

            Dim myTSC As TimeSpanConverter
 = New TimeSpanConverter()
            Dim StartTimeSpan As TimeSpan =
 CType(myTSC.ConvertFromString(SampleSection.BuildStartTime.ToString()), TimeSpan)
            Dim EndTimeSpan As TimeSpan = CType(myTSC.ConvertFromString(SampleSection.BuildEndTime.ToString()),
 TimeSpan)
            Dim resultTimeSpan As TimeSpan
 = EndTimeSpan - StartTimeSpan

            Try
                ' Determine if the Validator can validate
                ' the type it contains.
                valBase = customValAttr.ValidatorInstance
                If valBase.CanValidate(resultTimeSpan.GetType())
 Then
                    ' Validate the TimeSpan using a
                    ' custom PositiveTimeSpanValidator.
                    valBase.Validate(resultTimeSpan)
                End If
            Catch e As ArgumentException
                ' Store error message.
                Dim msg As String
 = e.Message.ToString()
#If DEBUG Then
                Console.WriteLine("Error: {0}", msg)
#End If
            End Try
        End Sub

        ' Create required sections.
        Shared Sub CreateSection()
            ' Get the current configuration (file).
            Dim config As System.Configuration.Configuration
 = _
              ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)

            ' Define the sample section.
            Dim sampleSection As SampleSection

            ' Create the handler section named MyDailyProcess 
            ' in the <configSections>. Also, create the 
            ' <MyDailyProcess> target section
            ' in <configuration>.
            If config.Sections("MyDailyProcess")
 Is Nothing Then
                sampleSection = New SampleSection()
                config.Sections.Add("MyDailyProcess",
 sampleSection)
                sampleSection.SectionInformation.ForceSave = True
                config.Save(ConfigurationSaveMode.Full)
            End If
        End Sub

        Shared Sub DisplaySectionProperties()
            Dim sampleSection As SampleSection
 = ConfigurationManager.GetSection("MyDailyProcess")

            If SampleSection Is Nothing
 Then
                Console.WriteLine("Failed to load section.")
            Else
                Console.WriteLine("Defaults:")
                Console.WriteLine("  Name: {0}", SampleSection.Name)
                Console.WriteLine("  BuildStartTime: {0}",
 SampleSection.BuildStartTime)
                Console.WriteLine("  BuildEndTime: {0}",
 SampleSection.BuildEndTime)
            End If
        End Sub

        Shared Sub Main(ByVal
 args() As String)
            Console.WriteLine("[Create a section]")
            CreateSection()

            Console.WriteLine("[Display section information]")
            DisplaySectionProperties()

            ' Show how to use the ValidatorInstance method.
            GetCustomValidatorInstance()

            ' Display and wait.
            Console.ReadLine()
        End Sub
    End Class
End Namespace
using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.ComponentModel;

namespace Samples.AspNet
{
    // Implements a custom validator attribute. 
    [AttributeUsage(AttributeTargets.Property)]
    public sealed class CustomValidatorAttribute
 :
        ConfigurationValidatorAttribute
    {
        public CustomValidatorAttribute()
        {
        }

        public CustomValidatorAttribute(Type validator)
            : base(validator)
        {
        }

        new public Type ValidatorType
        {
            get
            { return GetType(); }
        }


        public override ConfigurationValidatorBase ValidatorInstance
        {
            get
            {
                // Create validator.
                return new PositiveTimeSpanValidator();
            }
        }
    }

    // Implements a custom section class.
    public class SampleSection : ConfigurationSection
    {
        [ConfigurationProperty("name", DefaultValue = "MyBuildRoutine"
,
                   IsRequired = true)]
        [StringValidator(InvalidCharacters = " ~!@#$%^&*()[]{}/;'\"|\\"
,
      MinLength = 1, MaxLength = 60)]
        public string Name
        {
            get
            {
                return (string)this["name"];
            }
            set
            {
                this["name"] = value;
            }
        }

        [ConfigurationProperty("BuildStartTime", IsRequired = true
,
          DefaultValue = "09:00:00")]
        public TimeSpan BuildStartTime
        {
            get
            {
                TimeSpanConverter myTSC = new TimeSpanConverter();
                return (TimeSpan)this["BuildStartTime"];
            }
            set
            {
                this["BuildStartTime"] = value.ToString();
            }
        }

        [ConfigurationProperty("BuildEndTime", IsRequired = true
,
          DefaultValue = "17:00:00")]
        public TimeSpan BuildEndTime
        {
            get
            {
                TimeSpanConverter myTSC = new TimeSpanConverter();
                return (TimeSpan)this["BuildEndTime"];
            }
            set
            {
                this["BuildEndTime"] = value.ToString();
            }

        }
    }

    // Implements the console user interface.
    class TestingCustomValidatorAttribute
    {
        // Shows how to use the ValidatorInstance method.
        public static void
 GetCustomValidatorInstance()
        {
            ConfigurationValidatorBase valBase;
            CustomValidatorAttribute customValAttr;
            customValAttr = new CustomValidatorAttribute();

            SampleSection sampleSection =
              ConfigurationManager.GetSection("MyDailyProcess") as SampleSection;

            TimeSpanConverter myTSC = new TimeSpanConverter();
            TimeSpan StartTimeSpan = (TimeSpan)myTSC.ConvertFromString(sampleSection.BuildStartTime.ToString());
            TimeSpan EndTimeSpan = (TimeSpan)myTSC.ConvertFromString(sampleSection.BuildEndTime.ToString());
            TimeSpan resultTimeSpan = EndTimeSpan - StartTimeSpan;

            try
            {
                // Determine if the Validator can validate
                // the type it contains.
                valBase = customValAttr.ValidatorInstance;
                if (valBase.CanValidate(resultTimeSpan.GetType()))
                {
                    // Validate the TimeSpan using a
                    // custom PositiveTimeSpanValidator.
                    valBase.Validate(resultTimeSpan);
                }
            }
            catch (ArgumentException e)
            {
                // Store error message.
                string msg = e.Message.ToString();
#if DEBUG
                Console.WriteLine("Error: {0}", msg);
#endif
            }
        }

        // Create required sections.
        static void CreateSection()
        {
            // Get the current configuration (file).
            System.Configuration.Configuration config =
              ConfigurationManager.OpenExeConfiguration(
              ConfigurationUserLevel.None);

            // Define the sample section.
            SampleSection sampleSection;

            // Create the handler section named MyDailyProcess 
            // in the <configSections>. Also, create the 
            // <MyDailyProcess> target section
            // in <configuration>.
            if (config.Sections["MyDailyProcess"] ==
 null)
            {
                sampleSection = new SampleSection();
                config.Sections.Add("MyDailyProcess", sampleSection);
                sampleSection.SectionInformation.ForceSave = true;
                config.Save(ConfigurationSaveMode.Full);
            }
        }

        static void DisplaySectionProperties()
        {
            SampleSection sampleSection =
               ConfigurationManager.GetSection("MyDailyProcess") as SampleSection;

            if (sampleSection == null)
                Console.WriteLine("Failed to load section.");
            else
            {
                Console.WriteLine("Defaults:");
                Console.WriteLine("  Name: {0}", sampleSection.Name);
                Console.WriteLine("  BuildStartTime: {0}", sampleSection.BuildStartTime);
                Console.WriteLine("  BuildEndTime: {0}", sampleSection.BuildEndTime);
            }
        }

        static void Main(string[]
 args)
        {
            Console.WriteLine("[Create a section]");
            CreateSection();

            Console.WriteLine("[Display section information]");
            DisplaySectionProperties();

            // Show how to use the ValidatorInstance method.
            GetCustomValidatorInstance();

            // Display and wait.
            Console.ReadLine();
        }
    }
}
継承階層継承階層
System.Object
   System.Configuration.ConfigurationValidatorBase
    System.Configuration.PositiveTimeSpanValidator
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
PositiveTimeSpanValidator メンバ
System.Configuration 名前空間
TimeSpanValidator
ConfigurationValidatorBase クラス

PositiveTimeSpanValidator コンストラクタ

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

PositiveTimeSpanValidator クラスインスタンス初期化します。

名前空間: System.Configuration
アセンブリ: System.Configuration (system.configuration.dll 内)
構文構文

Dim instance As New PositiveTimeSpanValidator
public PositiveTimeSpanValidator ()
public:
PositiveTimeSpanValidator ()
public PositiveTimeSpanValidator ()
public function PositiveTimeSpanValidator ()
使用例使用例

PositiveTimeSpanValidator コンストラクタ使用する方法次のコード例示します。このコード例は、PositiveTimeSpanValidator クラストピック取り上げているコード例一部分です。

' Create validator.
Return New PositiveTimeSpanValidator()
// Create validator.
return new PositiveTimeSpanValidator();
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
PositiveTimeSpanValidator クラス
PositiveTimeSpanValidator メンバ
System.Configuration 名前空間

PositiveTimeSpanValidator メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

PositiveTimeSpanValidator クラス
System.Configuration 名前空間
TimeSpanValidator
ConfigurationValidatorBase クラス

PositiveTimeSpanValidator メンバ

TimeSpan オブジェクト検証提供します。このクラス継承できません。

PositiveTimeSpanValidator データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド PositiveTimeSpanValidator PositiveTimeSpanValidator クラスインスタンス初期化します。
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

PositiveTimeSpanValidator クラス
System.Configuration 名前空間
TimeSpanValidator
ConfigurationValidatorBase クラス


このページでは「.NET Framework クラス ライブラリ リファレンス」からPositiveTimeSpanValidatorを検索した結果を表示しています。
Weblioに収録されているすべての辞書からPositiveTimeSpanValidatorを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からPositiveTimeSpanValidator を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「PositiveTimeSpanValidator」の関連用語

PositiveTimeSpanValidatorのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



PositiveTimeSpanValidatorのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS