Click here to Skip to main content
15,906,816 members
Home / Discussions / C#
   

C#

 
QuestionNew to C#, wants to put it all together... Pin
logikos29-Nov-09 12:04
logikos29-Nov-09 12:04 
AnswerRe: New to C#, wants to put it all together... Pin
T210229-Nov-09 13:14
T210229-Nov-09 13:14 
AnswerRe: New to C#, wants to put it all together... Pin
minnie mouse1-Dec-09 12:31
minnie mouse1-Dec-09 12:31 
Questionmagic wand Pin
bayram_ytu29-Nov-09 9:59
bayram_ytu29-Nov-09 9:59 
AnswerRe: magic wand Pin
Alan N29-Nov-09 13:16
Alan N29-Nov-09 13:16 
GeneralRe: magic wand Pin
bayram_ytu29-Nov-09 13:31
bayram_ytu29-Nov-09 13:31 
AnswerRe: magic wand Pin
_Maxxx_30-Nov-09 17:03
professional_Maxxx_30-Nov-09 17:03 
QuestionConfigurationProperty Validator Pin
koleraba29-Nov-09 7:42
koleraba29-Nov-09 7:42 
Hi
I have a question concerning custom ConfigurationValidator, which verifies the entries in the app.config file. Below is the class which represents the section in the config file.

public class SettingSection : ConfigurationSection
{
   [ConfigurationProperty("appId", IsKey=true, IsRequired=true), ConfigurationValidator(typeof(AppIdValidator))]
   public string AppId
   {
      get { return (string)base["appId"]; }
   }
}

public class AppIdValidator : ConfigurationValidatorBase
{
    public override bool CanValidate(Type type)
    {
        return true;
    }

    public override void Validate(object value)
    {
       string val = (string)value;
       Regex regex = new Regex(@"\A\d{4}-\d{4}-\d{4}-\d{4}\z");
       if (regex.IsMatch(val))
       {
          return;
       }
       else
       {
          throw new FormatException("Input string is not in correct format");
       }
   }
}

The problem is when the instance of SettingSection is created, and the validator is called, the metod Validate is called with empty string - no metter what is the value in the app.config file. If I set the DefaultValue of the ConfigurationProperty attribute, than the validator is called with that value - again regardless to the entry in app.config.

Any idea will be appreciated

Uros
QuestionCopyright Question Pin
Zaegra29-Nov-09 6:36
Zaegra29-Nov-09 6:36 
AnswerMessage Closed Pin
29-Nov-09 7:20
stancrm29-Nov-09 7:20 
GeneralRe: Copyright Question Pin
Zaegra29-Nov-09 7:41
Zaegra29-Nov-09 7:41 
QuestionRe: Copyright Question Pin
Richard MacCutchan29-Nov-09 9:58
mveRichard MacCutchan29-Nov-09 9:58 
GeneralRe: Copyright Question Pin
Zaegra29-Nov-09 11:01
Zaegra29-Nov-09 11:01 
AnswerRe: Copyright Question Pin
DaveyM6929-Nov-09 11:48
professionalDaveyM6929-Nov-09 11:48 
QuestionC# string conversion issues Pin
gtr197129-Nov-09 5:14
gtr197129-Nov-09 5:14 
AnswerRe: C# string conversion issues Pin
Dave Kreskowiak29-Nov-09 5:26
mveDave Kreskowiak29-Nov-09 5:26 
GeneralRe: C# string conversion issues Pin
gtr197129-Nov-09 5:33
gtr197129-Nov-09 5:33 
GeneralRe: C# string conversion issues Pin
Richard MacCutchan29-Nov-09 5:46
mveRichard MacCutchan29-Nov-09 5:46 
AnswerRe: C# string conversion issues Pin
PIEBALDconsult29-Nov-09 5:50
mvePIEBALDconsult29-Nov-09 5:50 
GeneralRe: C# string conversion issues Pin
gtr197129-Nov-09 5:56
gtr197129-Nov-09 5:56 
GeneralRe: C# string conversion issues Pin
Natza Mitzi29-Nov-09 6:10
Natza Mitzi29-Nov-09 6:10 
GeneralRe: C# string conversion issues Pin
gtr197129-Nov-09 6:20
gtr197129-Nov-09 6:20 
GeneralRe: C# string conversion issues Pin
Richard MacCutchan29-Nov-09 6:23
mveRichard MacCutchan29-Nov-09 6:23 
GeneralRe: C# string conversion issues Pin
Natza Mitzi29-Nov-09 6:32
Natza Mitzi29-Nov-09 6:32 
GeneralRe: C# string conversion issues Pin
PIEBALDconsult29-Nov-09 11:39
mvePIEBALDconsult29-Nov-09 11:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.