Class

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I created the following class:

public class SyndicationResult : ActionResult {

public SyndicationFeed Feed { get; set; }
public SyndicationFormat Format { get; set; }

public override void ExecuteResult(ControllerContext context,
SyndicationFeed feed, SyndicationFeed format) : this(context, feed,
format) {
} // ExecuteResult

public override void ExecuteResult(ControllerContext context) {
context.HttpContext.Response.ContentType = "application/rss
+xml";
using (XmlWriter writer = XmlWriter.Create
(context.HttpContext.Response.Output)) {
switch (Format) {
case SyndicationFormat.Atom10:
Atom10FeedFormatter atom = new Atom10FeedFormatter(Feed);
atom.WriteTo(writer);
break;
case SyndicationFormat.Rss20:
Rss20FeedFormatter rss = new Rss20FeedFormatter(Feed);
rss.WriteTo(writer);
break;
}
}

} // ExecuteResult
} // SyndicationResult

On "this(context, feed, format) {" I get the error "; expected".

Can't I do it this way?

And do I need the properties on this case? ... Or maybe better, should
I have the properties in this class?

Thanks,
Miguel
 
shapper said:
I created the following class:

public class SyndicationResult : ActionResult {

public SyndicationFeed Feed { get; set; }
public SyndicationFormat Format { get; set; }

public override void ExecuteResult(ControllerContext context,
SyndicationFeed feed, SyndicationFeed format) : this(context, feed,
format) {
} // ExecuteResult
On "this(context, feed, format) {" I get the error "; expected".

Can't I do it this way?
This syntax is used for invoking constructors only. What are you trying to
do anyway? It's not clear from context.

To invoke the base method, use the syntax "base.ExecuteResult()" in the
method body.
 
This syntax is used for invoking constructors only. What are you trying to
do anyway? It's not clear from context.

To invoke the base method, use the syntax "base.ExecuteResult()" in the
method body.

Ok, I think I got it:

public class SyndicationResult : ActionResult {

public SyndicationFeed Feed { get; set; }
public SyndicationFormat Format { get; set; }
public override void ExecuteResult(ControllerContext context,
SyndicationFeed feed, SyndicationFormat format) {

Feed = feed;
Format = format;
ExecuteResult(context, feed, format);

} // ExecuteResult

public override void ExecuteResult(ControllerContext context) {

context.HttpContext.Response.ContentType = "application/rss
+xml";

using (XmlWriter writer = XmlWriter.Create
(context.HttpContext.Response.Output)) {
switch (Format) {
case SyndicationFormat.Atom10:
Atom10FeedFormatter atom = new Atom10FeedFormatter(Feed);
atom.WriteTo(writer);
break;
case SyndicationFormat.Rss20:
Rss20FeedFormatter rss = new Rss20FeedFormatter(Feed);
rss.WriteTo(writer);
break;
}
}

} // ExecuteResult

Since a Feed and a Format is always needed shouldn't I just have:

public class SyndicationResult : ActionResult {

public override void ExecuteResult(ControllerContext context,
SyndicationFeed feed, SyndicationFormat format) {

context.HttpContext.Response.ContentType = "application/rss
+xml";

using (XmlWriter writer = XmlWriter.Create
(context.HttpContext.Response.Output)) {
switch (format) {
case SyndicationFormat.Atom10:
Atom10FeedFormatter atom = new Atom10FeedFormatter(feed);
atom.WriteTo(writer);
break;
case SyndicationFormat.Rss20:
Rss20FeedFormatter rss = new Rss20FeedFormatter(feed);
rss.WriteTo(writer);
break;
}
}
} // ExecuteResult
}

Or should I keep the properties and throw exceptions on ExecuteResult
if they are null?

Just wondering the best way to do this since this will be used by
other persons and not just by me.

Thanks,
Miguel
 
Comments in-line:

shapper said:
Ok, I think I got it:

public class SyndicationResult : ActionResult {

public SyndicationFeed Feed { get; set; }
public SyndicationFormat Format { get; set; }
public override void ExecuteResult(ControllerContext context,
SyndicationFeed feed, SyndicationFormat format) {

Feed = feed;
Format = format;
ExecuteResult(context, feed, format);

The line directly above will cause infinite recursion. If you do not
include the "base." prefix, the program will run infinitely...since the
method ExecuteResult(ControllerContext, SyndicationFeed, SyndicationFormat)
is calling itself. Therefore, what you need here is the base prefix:

public override void ExecuteResult(
ControllerContext context,
SyndicationFeed feed,
SyndicationFormat format
) {
this.Feed = feed;
this.Format = format;
base.ExecuteResult(context, feed, format);
}
Since a Feed and a Format is always needed shouldn't I just have:

public class SyndicationResult : ActionResult {

public override void ExecuteResult(ControllerContext context,
SyndicationFeed feed, SyndicationFormat format) {

context.HttpContext.Response.ContentType = "application/rss
+xml";

using (XmlWriter writer = XmlWriter.Create
(context.HttpContext.Response.Output)) {
switch (format) {
case SyndicationFormat.Atom10:
Atom10FeedFormatter atom = new Atom10FeedFormatter(feed);
atom.WriteTo(writer);
break;
case SyndicationFormat.Rss20:
Rss20FeedFormatter rss = new Rss20FeedFormatter(feed);
rss.WriteTo(writer);
break;
}
}
} // ExecuteResult
}

Or should I keep the properties and throw exceptions on ExecuteResult
if they are null?

This is a design decision. Is the class required to "hang" around for
awhile for you to call multiple times? Does the class need to be called
once and then destroyed? If it hangs around and you need the values of the
properties more than once, then I'd say keep the properties and do proper
exception throwing/handling when required. Otherwise, if you don't need the
properties and only call the method a single time, then don't have the
properties.
Just wondering the best way to do this since this will be used by
other persons and not just by me.

Thanks,
Miguel

Hope this helps :)

Mythran
 
Comments in-line:








The line directly above will cause infinite recursion.  If you do not
include the "base." prefix, the program will run infinitely...since the
method ExecuteResult(ControllerContext, SyndicationFeed, SyndicationFormat)
is calling itself.  Therefore, what you need here is the base prefix:

public override void ExecuteResult(
    ControllerContext context,
    SyndicationFeed feed,
    SyndicationFormat format
) {
    this.Feed = feed;
    this.Format = format;
    base.ExecuteResult(context, feed, format);}

<snip>









This is a design decision.  Is the class required to "hang" around for
awhile for you to call multiple times?  Does the class need to be called
once and then destroyed?  If it hangs around and you need the values ofthe
properties more than once, then I'd say keep the properties and do proper
exception throwing/handling when required.  Otherwise, if you don't need the
properties and only call the method a single time, then don't have the
properties.



Hope this helps :)

Mythran

Thank you for your helped!!
 
Back
Top