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

  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 System;
  19.     using System.Reflection;
  20.     using System.Reflection.Emit;
  21.    
  22.     internal sealed class ParameterDeclaration : ParameterInfo
  23.     {
  24.         internal string identifier;
  25.         internal TypeExpression type;
  26.         internal Context context;
  27.         internal CustomAttributeList customAttributes;
  28.        
  29.         internal ParameterDeclaration(Context context, string identifier, TypeExpression type, CustomAttributeList customAttributes) : base()
  30.         {
  31.             this.identifier = identifier;
  32.             this.type = type == null ? new TypeExpression(new ConstantWrapper(Typeob.Object, context)) : type;
  33.             this.context = context;
  34.             ActivationObject current_scope = (ActivationObject)context.document.engine.Globals.ScopeStack.Peek();
  35.             if (current_scope.name_table[this.identifier] != null)
  36.                 context.HandleError(JSError.DuplicateName, this.identifier, current_scope is ClassScope || current_scope.fast || type != null);
  37.             //Only happens if there is another parameter declarations with the same name
  38.             else {
  39.                 JSVariableField field = current_scope.AddNewField(this.identifier, null, 0);
  40.                 field.originalContext = context;
  41.             }
  42.             this.customAttributes = customAttributes;
  43.         }
  44.        
  45.         internal ParameterDeclaration(Type type, string identifier) : base()
  46.         {
  47.             this.identifier = identifier;
  48.             this.type = new TypeExpression(new ConstantWrapper(type, null));
  49.             this.customAttributes = null;
  50.         }
  51.        
  52.         public override object DefaultValue {
  53.             get { return System.Convert.DBNull; }
  54.         }
  55.        
  56.         public override object[] GetCustomAttributes(bool inherit)
  57.         {
  58.             return new FieldInfo[0];
  59.         }
  60.        
  61.         public override object[] GetCustomAttributes(Type attributeType, bool inherit)
  62.         {
  63.             return new FieldInfo[0];
  64.         }
  65.        
  66.         public override bool IsDefined(Type attributeType, bool inherit)
  67.         {
  68.             if (this.customAttributes != null)
  69.                 return this.customAttributes.GetAttribute(attributeType) != null;
  70.             else
  71.                 return false;
  72.         }
  73.        
  74.         public override string Name {
  75.             get { return this.identifier; }
  76.         }
  77.        
  78.         internal IReflect ParameterIReflect {
  79.             get { return this.type.ToIReflect(); }
  80.         }
  81.        
  82.         public override Type ParameterType {
  83.             get {
  84.                 Type result = this.type.ToType();
  85.                 if (result == Typeob.Void)
  86.                     result = Typeob.Object;
  87.                 return result;
  88.             }
  89.         }
  90.        
  91.         internal void PartiallyEvaluate()
  92.         {
  93.             if (this.type != null)
  94.                 this.type.PartiallyEvaluate();
  95.             if (this.customAttributes != null) {
  96.                 this.customAttributes.PartiallyEvaluate();
  97.                 if (CustomAttribute.IsDefined(this, typeof(ParamArrayAttribute), false)) {
  98.                     if (this.type != null) {
  99.                         IReflect ir = this.type.ToIReflect();
  100.                         if ((ir is Type && ((Type)ir).IsArray) || (ir is TypedArray))
  101.                             return;
  102.                     }
  103.                     this.customAttributes.context.HandleError(JSError.IllegalParamArrayAttribute);
  104.                 }
  105.             }
  106.         }
  107.        
  108.     }
  109. }

Developer Fusion