Bug 10839 - Conditional Razor attributes in Razor Generator
Summary: Conditional Razor attributes in Razor Generator
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: ASP.Net ()
Version: unspecified
Hardware: PC Mac OS
: High normal
Target Milestone: 4.2.3 (from master)
Assignee: Mikayla Hutchinson [MSFT]
Depends on:
Reported: 2013-03-01 20:58 UTC by Mikayla Hutchinson [MSFT]
Modified: 2014-01-14 11:14 UTC (History)
6 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Mikayla Hutchinson [MSFT] 2013-03-01 20:58:51 UTC
Currently, when using attributes in Razor, the engine generates horribly overcomplicated calls to a WriteAttributeMethod:

We need to implement WriteAttribute and WriteAttribute to on the Generated class, ideally also simplifying the signature a LOT.

To do this we may need to plug in altered generators:

We should also look at the other class and method names defined on GeneratedClassContext and either implement them or write code to make using these features a generation-time error:

In some cases, it may be necessary to alter the generators:
Comment 1 Mikayla Hutchinson [MSFT] 2013-12-05 03:45:52 UTC
Comment 2 Mohit Kheterpal 2014-01-14 09:28:48 UTC
We have tried to reproduce this issue. But we are not sure about steps.

Could you please provide some steps or sample application so that we can verify this issue?
Comment 3 Joseph Hill 2014-01-14 09:52:22 UTC
In a C# project in Xamarin Studio (for instance, create a new iOS project), add a Preprocessed Razor Template:
File-> New File... -> Text Templating -> Preprocessed Razor Template

In the new (i.e., test.cshtml), add this line:
<a href="@DateTime.Now.ToString()"></a>

Verify that the generated file (i.e., test.cs) has a call to "WriteAttribute", i.e.,:
WriteAttribute ("href", " href=\"", "\""

Verify that the project builds (i.e,. before this bug was fixed, WriteAttribute was not defined)
Comment 4 Mohit Kheterpal 2014-01-14 11:14:06 UTC
As per steps mention in comment 3, we are able to check that WriteAttribute
is defined.
i.e. "WriteAttribute ("href", " href=\"", "\""

Screencast : http://screencast.com/t/QnzDOD7JFjVi

Hence closing this issue.