The Labs \ Source Viewer \ SSCLI \ Microsoft.JScript \ WrappedNamespace

  1. // ==++==
  2. //
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. //
  14. // ==--==
  15. namespace Microsoft.JScript
  16. {
  17.    
  18.     using Microsoft.JScript.Vsa;
  19.     using System;
  20.     using System.Reflection;
  21.    
  22.     internal sealed class WrappedNamespace : ActivationObject
  23.     {
  24.         internal string name;
  25.        
  26.         internal WrappedNamespace(string name, VsaEngine engine) : this(name, engine, true)
  27.         {
  28.         }
  29.        
  30.         internal WrappedNamespace(string name, VsaEngine engine, bool AddReferences) : base(null)
  31.         {
  32.             this.name = name;
  33.             this.engine = engine;
  34.             this.isKnownAtCompileTime = true;
  35.             if (name.Length > 0 && AddReferences)
  36.                 engine.TryToAddImplicitAssemblyReference(name);
  37.         }
  38.        
  39.         public override MemberInfo[] GetMember(string name, BindingFlags bindingAttr)
  40.         {
  41.             FieldInfo cachedfield = (FieldInfo)(this.name_table[name]);
  42.             if (cachedfield != null)
  43.                 return new MemberInfo[] {cachedfield};
  44.            
  45.             FieldAttributes attrs = FieldAttributes.Literal;
  46.             string fullname = this.name == null || this.name.Length == 0 ? name : this.name + "." + name;
  47.             object t = null;
  48.             if (this.name != null && this.name.Length > 0)
  49.                 t = this.engine.GetClass(fullname);
  50.             //Packages will not have classes residing in the default name space
  51.             if (t == null) {
  52.                 t = this.engine.GetType(fullname);
  53.                 if (t != null && !((Type)t).IsPublic) {
  54.                     if ((bindingAttr & BindingFlags.NonPublic) == 0)
  55.                         t = null;
  56.                     else
  57.                         attrs |= FieldAttributes.Private;
  58.                 }
  59.             }
  60.             else {
  61.                 if ((((ClassScope)t).owner.attributes & TypeAttributes.Public) == 0) {
  62.                     if ((bindingAttr & BindingFlags.NonPublic) == 0)
  63.                         t = null;
  64.                     else
  65.                         attrs |= FieldAttributes.Private;
  66.                 }
  67.             }
  68.             if (t == null) {
  69.                 if (this.parent != null && (bindingAttr & BindingFlags.DeclaredOnly) == 0)
  70.                     return this.parent.GetMember(name, bindingAttr);
  71.                 return new MemberInfo[0];
  72.             }
  73.            
  74.             JSGlobalField field = (JSGlobalField)this.CreateField(name, attrs, t);
  75.             if (engine.doFast)
  76.                 field.type = new TypeExpression(new ConstantWrapper(Typeob.Type, null));
  77.             this.name_table[name] = field;
  78.             this.field_table.Add(field);
  79.             return new MemberInfo[] {field};
  80.         }
  81.        
  82.         public override string ToString()
  83.         {
  84.             return this.name;
  85.         }
  86.        
  87.     }
  88.    
  89. }

Developer Fusion