this.parser = parser;
}
+ internal CodeStatement AddLinePragma (CodeExpression expression, ControlBuilder builder)
+ {
+ return AddLinePragma (new CodeExpressionStatement (expression), builder);
+ }
+
+ internal CodeStatement AddLinePragma (CodeStatement statement, ControlBuilder builder)
+ {
+ if (builder == null || statement == null)
+ return statement;
+
+ ILocation location = null;
+
+ if (!(builder is CodeRenderBuilder))
+ location = builder.location;
+
+ if (location != null)
+ return AddLinePragma (statement, location);
+ else
+ return AddLinePragma (statement, builder.line, builder.fileName);
+ }
+
+ internal CodeStatement AddLinePragma (CodeStatement statement, ILocation location)
+ {
+ if (location == null || statement == null)
+ return statement;
+
+ return AddLinePragma (statement, location.BeginLine, location.Filename);
+ }
+
+ internal CodeStatement AddLinePragma (CodeStatement statement, int line, string fileName)
+ {
+ if (statement == null)
+ return null;
+
+ statement.LinePragma = new CodeLinePragma (fileName, line);
+ return statement;
+ }
+
+ internal CodeTypeMember AddLinePragma (CodeTypeMember member, ControlBuilder builder)
+ {
+ if (builder == null || member == null)
+ return member;
+
+ ILocation location = builder.location;
+
+ if (location != null)
+ return AddLinePragma (member, location);
+ else
+ return AddLinePragma (member, builder.line, builder.fileName);
+ }
+
+ internal CodeTypeMember AddLinePragma (CodeTypeMember member, ILocation location)
+ {
+ if (location == null || member == null)
+ return member;
+
+ return AddLinePragma (member, location.BeginLine, location.Filename);
+ }
+
+ internal CodeTypeMember AddLinePragma (CodeTypeMember member, int line, string fileName)
+ {
+ if (member == null)
+ return null;
+
+ member.LinePragma = new CodeLinePragma (fileName, line);
+ return member;
+ }
+
void Init ()
{
unit = new CodeCompileUnit ();
CreateConstructor (null, null);
}
+ internal CodeFieldReferenceExpression GetMainClassFieldReferenceExpression (string fieldName)
+ {
+ CodeTypeReference mainClassTypeRef;
+ mainClassTypeRef = new CodeTypeReference (mainNS.Name + "." + mainClass.Name);
+
+#if NET_2_0
+ mainClassTypeRef.Options |= CodeTypeReferenceOptions.GlobalReference;
+#endif
+ return new CodeFieldReferenceExpression (
+ new CodeTypeReferenceExpression (mainClassTypeRef), fieldName);
+ }
+
protected virtual void CreateStaticFields ()
{
CodeMemberField fld = new CodeMemberField (typeof (bool), "__initialized");
if (VirtualPathUtility.IsAbsolute (arvp))
arvp = "~" + arvp;
- CodeExpression cast = new CodeCastExpression (baseType, new CodeThisReferenceExpression ());
+ CodeTypeReference baseTypeRef = new CodeTypeReference (baseType.FullName);
+ if (parser.BaseTypeIsGlobal)
+ baseTypeRef.Options |= CodeTypeReferenceOptions.GlobalReference;
+
+ CodeExpression cast = new CodeCastExpression (baseTypeRef, new CodeThisReferenceExpression ());
CodePropertyReferenceExpression arvpProp = new CodePropertyReferenceExpression (cast, "AppRelativeVirtualPath");
CodeAssignStatement arvpAssign = new CodeAssignStatement ();
arvpAssign.Left = arvpProp;
ctor.Attributes = MemberAttributes.Public;
mainClass.Members.Add (ctor);
-#if NET_2_0
- AssignAppRelativeVirtualPath (ctor);
-#endif
if (localVars != null)
ctor.Statements.AddRange (localVars);
- CodeTypeReferenceExpression r;
#if NET_2_0
- if (parser.IsPartial)
- r = new CodeTypeReferenceExpression (mainClass.Name);
- else
+ AssignAppRelativeVirtualPath (ctor);
#endif
- r = new CodeTypeReferenceExpression (mainNS.Name + "." + mainClass.Name);
- CodeFieldReferenceExpression initialized;
- initialized = new CodeFieldReferenceExpression (r, "__initialized");
+
+ CodeFieldReferenceExpression initialized = GetMainClassFieldReferenceExpression ("__initialized");
CodeBinaryOperatorExpression bin;
bin = new CodeBinaryOperatorExpression (initialized,
CodeAssignStatement assign = new CodeAssignStatement (initialized,
new CodePrimitiveExpression (true));
- CodeConditionStatement cond = new CodeConditionStatement (bin, assign);
+ CodeConditionStatement cond = new CodeConditionStatement ();
+ cond.Condition = bin;
+
if (trueStmt != null)
cond.TrueStatements.AddRange (trueStmt);
+ cond.TrueStatements.Add (assign);
ctor.Statements.Add (cond);
}
if (parser.Scripts == null || parser.Scripts.Count == 0)
return;
+ ServerSideScript sss;
+
foreach (object o in parser.Scripts) {
- if (o is string)
- mainClass.Members.Add (new CodeSnippetTypeMember ((string) o));
+ sss = o as ServerSideScript;
+
+ if (sss == null)
+ continue;
+
+ mainClass.Members.Add (AddLinePragma (new CodeSnippetTypeMember (sss.Script), sss.Location));
}
}