Skip to content

Commit

Permalink
Adding support for array types to the weaver
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Laub committed Jan 3, 2010
1 parent f3c8fc4 commit fd28aff
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 10 deletions.
Binary file added dist/DotWeb-20100101.7z
Binary file not shown.
Binary file added dist/DotWeb-20100101.zip
Binary file not shown.
5 changes: 5 additions & 0 deletions sample/DotWeb.Sample.MVC/Controllers/BaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ protected override void Initialize(RequestContext requestContext) {
}

ViewData["Mode"] = mode.Value;
var root = Request.ApplicationPath;
if (root.EndsWith("/")) {
root = root.Substring(0, root.Length - 1);
}
ViewData["Root"] = root;
}
}
}
4 changes: 0 additions & 4 deletions sample/DotWeb.Sample.MVC/DotWeb.Sample.MVC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,6 @@
<Content Include="Views\Web.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\DotWeb.Client\DotWeb.Client.csproj">
<Project>{0A46B99F-8A61-4544-8B1D-E5117DABBD90}</Project>
<Name>DotWeb.Client</Name>
</ProjectReference>
<ProjectReference Include="..\DotWeb.Sample.Script\DotWeb.Sample.Script.csproj">
<Project>{1D730EA2-0129-47B6-AA92-9D2C14EF38CD}</Project>
<Name>DotWeb.Sample.Script</Name>
Expand Down
2 changes: 1 addition & 1 deletion sample/DotWeb.Sample.MVC/Views/Shared/Application.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
%html{ xmlns="http://www.w3.org/1999/xhtml" }
%head
%title= ViewData["Title"]
%link{ href="../../Content/Site.css" rel="stylesheet" type="text/css" }
%link{ href='#{ViewData["Root"]}/Content/Site.css' rel="stylesheet" type="text/css" }
%body
.page
#header
Expand Down
6 changes: 5 additions & 1 deletion src/DotWeb.Web.Mvc/HttpContextImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ public string MapPath(string virtualPath) {
}

public string ResolveUrl(string url) {
return url.Replace("~/", context.Request.ApplicationPath);
var root = context.Request.ApplicationPath;
if (root.EndsWith("/")) {
root = root.Substring(0, root.Length - 1);
}
return url.Replace("~", root);
}

public System.Web.Caching.Cache Cache {
Expand Down
18 changes: 16 additions & 2 deletions test/DotWeb.Hosting.Test/HostingWeaverTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,24 @@ public void GenericMethodTest() {
}

[Test]
[Ignore]
public void ArrayTest() {
// weave an array then grab via reflection
Assert.Fail();
var test = this.hosted.CreateInstance("DotWeb.Weaver.Test.Script.ArrayTest");
var type = test.GetType();
Assert.IsNotNull(type);

var field = type.GetField("fieldArray");
Assert.IsNotNull(field);
Assert.AreEqual(typeof(int[]), field.FieldType);

var property = type.GetProperty("PropertyArray");
Assert.IsNotNull(property);
Assert.AreEqual(typeof(string[]), property.PropertyType);

var typeArray = type.GetField("typeArray");
Assert.IsNotNull(typeArray);
var elementType = typeArray.FieldType.GetElementType();
Assert.AreEqual(type, elementType);
}

[Test]
Expand Down
36 changes: 36 additions & 0 deletions test/DotWeb.Weaver.Test.Script/ArrayTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2009, Frank Laub
//
// This file is part of DotWeb.
//
// DotWeb is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// DotWeb is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with DotWeb. If not, see <http://www.gnu.org/licenses/>.
//
using DotWeb.Client;

namespace DotWeb.Weaver.Test.Script
{
class ArrayTest
{
public int[] fieldArray;
public string[] PropertyArray { get; set; }

public ArrayTest[] typeArray;

public ArrayTest() {
this.fieldArray = new int[4];
this.fieldArray[0] = 1;
this.typeArray = new ArrayTest[1];
this.typeArray[0] = this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<Compile Include="..\..\CommonAssemblyInfo.cs">
<Link>Properties\CommonAssemblyInfo.cs</Link>
</Compile>
<Compile Include="ArrayTest.cs" />
<Compile Include="CastTest.cs" />
<Compile Include="NestedTest.cs" />
<Compile Include="TypeTest.cs" />
Expand Down
7 changes: 6 additions & 1 deletion tools/DotWeb.Tools.Weaver/AssemblyProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ public IType ResolveTypeReference(TypeReference typeRef) {
private IType ProcessType(TypeReference typeRef) {
var typeDef = typeRef.Resolve();
if (typeRef is ArrayType) {
var arrayType = (ArrayType)typeRef;
var elementProc = this.resolver.ResolveTypeReference(arrayType.ElementType);
var realType = elementProc.Type.MakeArrayType(arrayType.Rank);
var externalWrapper = new ExternalType(this.resolver, realType);
return externalWrapper;
}

if (typeDef.IsEnum) {
Expand All @@ -143,7 +148,7 @@ private IType ProcessType(TypeReference typeRef) {
return enumProc;
}
else if (typeDef.IsNested) {
var outerProc = ResolveTypeReference(typeDef.DeclaringType);
var outerProc = this.resolver.ResolveTypeReference(typeDef.DeclaringType);
var outerBuilder = (TypeBuilder)outerProc.Type;
var typeProc = new TypeProcessor(this.resolver, this, typeDef, this.moduleBuilder, outerBuilder);
RegisterType(typeRef, typeProc);
Expand Down
11 changes: 10 additions & 1 deletion tools/DotWeb.Tools.Weaver/DotWebSystemAssembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,16 @@ public IType ResolveTypeReference(TypeReference typeRef) {
type = type.MakeGenericType(genericTypes);
}

if (type.IsDefined(this.useSystemAttribute, false)) {
var elementalType = type;
var arrayType = typeRef as ArrayType;
if (arrayType != null) {
// we don't need to resolve this type because we can assume that only other system types
// are referenced in DotWeb.System.
string modifiedElementName = "DotWeb." + arrayType.ElementType.FullName;
elementalType = this.asm.GetType(modifiedElementName);
}

if (elementalType.IsDefined(this.useSystemAttribute, false)) {
ret = new ExternalType(this.resolver, Type.GetType(fullName));
}
else {
Expand Down
2 changes: 2 additions & 0 deletions tools/DotWebWeaver/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ static void Main(string[] args) {
string inputDir = Path.GetDirectoryName(inputPath);
string outputDir = Path.GetDirectoryName(outputPath);

Console.WriteLine("Weaving {0} -> {1}", inputPath, outputPath);

var weaver = new HostingWeaver(inputDir, outputDir, searchDirs);
weaver.ProcessAssembly(inputPath);
}
Expand Down

0 comments on commit fd28aff

Please sign in to comment.