[C#] XML comment

Pagina: 1
Acties:

  • pjvandesande
  • Registratie: Maart 2004
  • Laatst online: 21-05 14:59

pjvandesande

GC.Collect(head);

Topicstarter
Ik maak sinds een lange tijd al gebruik van de XML comments.

Nu wil ik alleen een stuk XML in me <b><example></b> gedeelte een voorbeelde zetten van de app.settings file. Maar dit is ook XML, hoe zet ik dit er tussen? Bij het compilen komt vs met devolgende fout:
D:\QuSoft\Software\ErrorReport\ErrorReport.cs(249): XML comment on 'Qusoft.ErrorReport.LoadSettings()' has badly formed XML -- 'Invalid xml declaration.
'
C#:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/// <summary>
/// Load the SMTP setting from the appliction settings file.
/// </summary>
/// <example>
/// <?xml version="1.0" encoding="utf-8" />
/// <configuration>
///     <appSettings>
///         <!-- Error report settings />
///         <add key="errorreport:smtp" value="smtp.domain.com" />
///         <add key="errorreport:to" value="alias@domain.com" />
///         <add key="errorreport:port" value="25" />
///         <add key="errorreport:username" value="username" />
///         <add key="errorreport:password" value="password" />
///     </appSettings>
/// </configuration>
/// </example>
public void LoadSettings()
{
    this.SMTP = ConfigurationSettings.AppSettings.Get("errorreport:smtp");
    this.To = ConfigurationSettings.AppSettings.Get("errorreport:to");
    this.Port = int.Parse(ConfigurationSettings.AppSettings.Get("errorreport:port"));
    this.Username = ConfigurationSettings.AppSettings.Get("errorreport:username");
    this.Password = ConfigurationSettings.AppSettings.Get("errorreport:password");
}

  • PrisonerOfPain
  • Registratie: Januari 2003
  • Laatst online: 07-04 13:41
code:
1
2
/// <example>
/// <?xml version="1.0" encoding="utf-8" />

omdraaien?

woei, foutje, maar je sluit je commentaar niet af <!-- Error report settings />

[ Voor 46% gewijzigd door PrisonerOfPain op 05-05-2004 20:54 ]


  • pjvandesande
  • Registratie: Maart 2004
  • Laatst online: 21-05 14:59

pjvandesande

GC.Collect(head);

Topicstarter
PrisonerOfPain schreef op 05 mei 2004 @ 20:53:
code:
1
2
/// <example>
/// <?xml version="1.0" encoding="utf-8" />

omdraaien?
huh.. oke, questa snapt de hint niet! :?

  • Rickets
  • Registratie: Augustus 2001
  • Niet online

Rickets

Finger and a shift

De xml-processing instruction is niet verplicht, dus die kan je gewoon weglaten.
Je sluit hem wel verkeerd af, je behandelt het nu als een element.

If some cunt can fuck something up, that cunt will pick the worst possible time to fucking fuck it up, because that cunt’s a cunt.


  • pjvandesande
  • Registratie: Maart 2004
  • Laatst online: 21-05 14:59

pjvandesande

GC.Collect(head);

Topicstarter
Rickets schreef op 05 mei 2004 @ 20:55:
De xml-processing instruction is niet verplicht, dus die kan je gewoon weglaten.
Je sluit hem wel verkeerd af, je behandelt het nu als een element.
Nee, dat is deel van de example. Alles tussen die tag moet hij van mij gewoon als een string pakken. Maar hij ziet het als XML.

  • Rickets
  • Registratie: Augustus 2001
  • Niet online

Rickets

Finger and a shift

questa schreef op 05 mei 2004 @ 20:58:
Nee, dat is deel van de example. Alles tussen die tag moet hij van mij gewoon als een string pakken. Maar hij ziet het als XML.
Ja, dat snap ik :P
Maar je kan het weglaten uit het voorbeeld, het is een niet-verplicht iets.
En anders moet je een CDATA-sectie gebruiken.

If some cunt can fuck something up, that cunt will pick the worst possible time to fucking fuck it up, because that cunt’s a cunt.


  • pjvandesande
  • Registratie: Maart 2004
  • Laatst online: 21-05 14:59

pjvandesande

GC.Collect(head);

Topicstarter
Rickets schreef op 05 mei 2004 @ 20:59:
[...]

Ja, dat snap ik :P
Maar je kan het weglaten uit voorbeeld, het is een niet-verplicht iets.
En anders moet je een CDATA-sectie gebruiken.
Oja, visual studio zet het al voor me neer als ik een app.config file in me solution zet... maargoed, CDATA werkt perfect!

  • Rolgordijn
  • Registratie: Januari 2000
  • Laatst online: 30-06-2022
Ik zag de manier waarop je de parameters prefixed, waarschijnlijk doe je dat om je config parameters te catagoriseren oid. Je app.config heeft hier standaard functionaliteiten voor.

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?xml version="1.0" encoding="utf-8" ?>
<configuration>

    <configSections>
        <sectionGroup name="errorReport">
            <section name="emailNotification" type="System.Configuration.NameValueSectionHandler" />
        </sectionGroup>
    </configSections>

    <errorReport>
        <emailNotification>
            <add key="smtp" value="smtp.domain.com" />
            <add key="to" value="alias@domain.com" />
            <add key="port" value="25" />
            <add key="username" value="username" />
            <add key="password" value="password" />
        </emailNotification>
    </errorReport>

</configuration>


Om de betreffende configuratie settings op te halen in je code kan je gebruik maken van iets dergelijks als:

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Configuration;

public class ErrorReport
{

    private static NameValueCollection _errorReportConfig =
            ( NameValueCollection ) ConfigurationSettings.GetConfig( "errorReport/emailNotification" );

    // andere attributen hier

    public ErrorReport()
    {
    }

    public void LoadSettings()
    {
        this.SMTP       = _errorReportConfig( "smtp" );
        this.To         = _errorReportConfig( "to" );
        this.Port       = Convert.Int32( _errorReportConfig( "port" ) );
        this.Username   = _errorReportConfig( "username" );
        this.Password   = _errorReportConfig( "password" );
    }

}


Er kunnen misschien wat typo's in staan (heb de code niet getest) maar het maakt je App.config een stuk beter leesbaar, vooral als je veel config settings hebt.

  • pjvandesande
  • Registratie: Maart 2004
  • Laatst online: 21-05 14:59

pjvandesande

GC.Collect(head);

Topicstarter
Geweldig, bedankt voor je aanvulling. Wist ik niet! _/-\o_

[ Voor 6% gewijzigd door pjvandesande op 05-05-2004 21:25 ]

Pagina: 1