Skip to content

Commit

Permalink
Add handling of broken Convert callsite from Orchard Project
Browse files Browse the repository at this point in the history
  • Loading branch information
marek-safar committed Feb 2, 2011
1 parent 83586e4 commit d448793
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
Expand Up @@ -69,7 +69,7 @@ public DynamicMetaObject Bind (DynamicContext ctx, Type callingType)
{
Expression res;
try {
var rc = new Compiler.ResolveContext (new RuntimeBinderContext (ctx, ctx.ImportType (callingType)), ResolveOptions);
var rc = new Compiler.ResolveContext (new RuntimeBinderContext (ctx, callingType), ResolveOptions);

// Static typemanager and internal caches are not thread-safe
lock (resolver) {
Expand Down
@@ -1,4 +1,4 @@
//
//
// RuntimeBinderContext.cs
//
// Authors:
Expand Down Expand Up @@ -35,18 +35,39 @@ namespace Microsoft.CSharp.RuntimeBinder
class RuntimeBinderContext : Compiler.IMemberContext
{
readonly Compiler.ModuleContainer module;
readonly Compiler.TypeSpec currentType;
readonly Type callingType;
readonly DynamicContext ctx;
Compiler.TypeSpec callingTypeImported;

public RuntimeBinderContext (DynamicContext ctx, Compiler.TypeSpec currentType)
public RuntimeBinderContext (DynamicContext ctx, Compiler.TypeSpec callingType)
{
this.ctx = ctx;
this.module = ctx.Module;
this.currentType = currentType;
this.callingTypeImported = callingType;
}

public RuntimeBinderContext (DynamicContext ctx, Type callingType)
{
this.ctx = ctx;
this.module = ctx.Module;
this.callingType = callingType;
}

#region IMemberContext Members

public Compiler.TypeSpec CurrentType {
get { return currentType; }
get {
//
// Delay importing of calling type to be compatible with .net
// Some libraries are setting it to null which is invalid
// but the NullReferenceException is thrown only when the context
// is used and not during initialization
//
if (callingTypeImported == null)
callingTypeImported = ctx.ImportType (callingType);

return callingTypeImported;
}
}

public Compiler.TypeParameter[] CurrentTypeParameters {
Expand Down

1 comment on commit d448793

@ArsenShnurkov
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.