public override Object Invoke(Object obj, BindingFlags options, Binder binder, Object[] parameters, CultureInfo culture)
        {
            MethodInfo method = TypeReferences.ToExecutionContext(this.method);

            if (binder != null)
            {
                try{
                    return(method.Invoke(obj, options, binder, parameters, culture));
                }catch (TargetInvocationException e) {
                    throw e.InnerException;
                }
            }
            MethodInvoker invoker = this.methodInvoker;

            if (invoker == null)
            {
                this.methodInvoker = invoker = MethodInvoker.GetInvokerFor(method);
                if (invoker == null) //because the method is not safe to call via a thunk
                {
                    try{
                        return(method.Invoke(obj, options, binder, parameters, culture));
                    }catch (TargetInvocationException e) {
                        throw e.InnerException;
                    }
                }
            }
            return(invoker.Invoke(obj, parameters));
        }
        public override object Invoke(object obj, BindingFlags options, Binder binder, object[] parameters, CultureInfo culture)
        {
            MethodInfo method = TypeReferences.ToExecutionContext(this.method);

            if (binder != null)
            {
                try
                {
                    return(method.Invoke(obj, options, binder, parameters, culture));
                }
                catch (TargetInvocationException exception)
                {
                    throw exception.InnerException;
                }
            }
            MethodInvoker methodInvoker = this.methodInvoker;

            if ((methodInvoker == null) && ((this.methodInvoker = MethodInvoker.GetInvokerFor(method)) == null))
            {
                try
                {
                    return(method.Invoke(obj, options, binder, parameters, culture));
                }
                catch (TargetInvocationException exception2)
                {
                    throw exception2.InnerException;
                }
            }
            return(methodInvoker.Invoke(obj, parameters));
        }
Exemple #3
0
        public PapyrusFieldEditorViewModel(IEnumerable <string> availableTypes, PapyrusFieldDefinition fieldToEdit = null)
            : base(availableTypes)
        {
            this.fieldToEdit = fieldToEdit;
            if (fieldToEdit != null)
            {
                Name = fieldToEdit.Name.Value;
                if (fieldToEdit.DefaultValue != null)
                {
                    if (fieldToEdit.DefaultValue.Value != null)
                    {
                        DefaultValue = fieldToEdit.DefaultValue.Value;
                    }
                }

                if (fieldToEdit.TypeName.Contains("[]"))
                {
                    IsArray = true;
                }

                var ft =
                    fieldToEdit.TypeName.ToLower();

                ft = ft.Replace("[]", "");

                SelectedType = TypeReferences.FirstOrDefault(t => t.ToString().ToLower() == ft);
                if (SelectedType == null)
                {
                    SelectedType = fieldToEdit.TypeName.ToLower();
                }
            }
        }
Exemple #4
0
        public PapyrusParameterEditorViewModel(IEnumerable <string> types, PapyrusParameterDefinition parameter = null)
            : base(types)
        {
            this.parameter = parameter;

            if (this.parameter != null)
            {
                Name = this.parameter.Name.Value;

                if (parameter.TypeName.Value.Contains("[]"))
                {
                    IsArray = true;
                }

                var ft =
                    parameter.TypeName.Value.ToLower();

                ft = ft.Replace("[]", "");

                SelectedType = TypeReferences.FirstOrDefault(t => t.ToString().ToLower() == ft);
                if (SelectedType == null)
                {
                    SelectedType = this.parameter.TypeName.Value.ToLower();
                }
            }
        }
        public PapyrusVariableEditorViewModel(IEnumerable <string> types, PapyrusVariableReference variable = null)
            : base(types)
        {
            this.variable = variable;

            if (this.variable != null)
            {
                Name = this.variable.Name.Value;


                if (variable.TypeName.Value.Contains("[]"))
                {
                    IsArray = true;
                }

                var ft =
                    variable.TypeName.Value.ToLower();

                ft = ft.Replace("[]", "");

                SelectedType = TypeReferences.FirstOrDefault(t => t.ToString().ToLower() == ft);
                if (SelectedType == null)
                {
                    SelectedType = this.variable.TypeName.Value.ToLower();
                }
            }
        }
        public override Object GetValue(Object obj)
        {
            FieldAccessor accessor = this.fieldAccessor;

            if (accessor == null)
            {
                this.fieldAccessor = accessor = FieldAccessor.GetAccessorFor(TypeReferences.ToExecutionContext(this.field));
            }
            return(accessor.GetValue(obj));
        }
Exemple #7
0
        private static FieldAccessor SpitAndInstantiateClassFor(FieldInfo field)
        {
            Type          fieldType = field.FieldType;
            TypeBuilder   builder   = Runtime.ThunkModuleBuilder.DefineType("accessor" + count++, TypeAttributes.Public, typeof(FieldAccessor));
            MethodBuilder builder2  = builder.DefineMethod("GetValue", MethodAttributes.Virtual | MethodAttributes.Public, typeof(object), new Type[] { typeof(object) });

            builder2.SetCustomAttribute(new CustomAttributeBuilder(Runtime.TypeRefs.debuggerStepThroughAttributeCtor, new object[0]));
            builder2.SetCustomAttribute(new CustomAttributeBuilder(Runtime.TypeRefs.debuggerHiddenAttributeCtor, new object[0]));
            ILGenerator iLGenerator = builder2.GetILGenerator();

            if (field.IsLiteral)
            {
                new ConstantWrapper(TypeReferences.GetConstantValue(field), null).TranslateToIL(iLGenerator, fieldType);
            }
            else if (field.IsStatic)
            {
                iLGenerator.Emit(OpCodes.Ldsfld, field);
            }
            else
            {
                iLGenerator.Emit(OpCodes.Ldarg_1);
                iLGenerator.Emit(OpCodes.Ldfld, field);
            }
            if (fieldType.IsValueType)
            {
                iLGenerator.Emit(OpCodes.Box, fieldType);
            }
            iLGenerator.Emit(OpCodes.Ret);
            builder2 = builder.DefineMethod("SetValue", MethodAttributes.Virtual | MethodAttributes.Public, typeof(void), new Type[] { typeof(object), typeof(object) });
            builder2.SetCustomAttribute(new CustomAttributeBuilder(Runtime.TypeRefs.debuggerStepThroughAttributeCtor, new object[0]));
            builder2.SetCustomAttribute(new CustomAttributeBuilder(Runtime.TypeRefs.debuggerHiddenAttributeCtor, new object[0]));
            iLGenerator = builder2.GetILGenerator();
            if (!field.IsLiteral)
            {
                if (!field.IsStatic)
                {
                    iLGenerator.Emit(OpCodes.Ldarg_1);
                }
                iLGenerator.Emit(OpCodes.Ldarg_2);
                if (fieldType.IsValueType)
                {
                    Microsoft.JScript.Convert.EmitUnbox(iLGenerator, fieldType, Type.GetTypeCode(fieldType));
                }
                if (field.IsStatic)
                {
                    iLGenerator.Emit(OpCodes.Stsfld, field);
                }
                else
                {
                    iLGenerator.Emit(OpCodes.Stfld, field);
                }
            }
            iLGenerator.Emit(OpCodes.Ret);
            return((FieldAccessor)Activator.CreateInstance(builder.CreateType()));
        }
 internal static void ResolveReferences(IUnifiedIMObject obj, Type type = null)
 {
     if (type == null)
     {
         type = obj.GetType();
     }
     if (TypeReferences.ContainsKey(type))
     {
         foreach (UnifiedIMReference reference in TypeReferences[type])
         {
             ResolveReference(obj, reference, type);
         }
     }
 }
Exemple #9
0
            public MethodReferences(TypeReferences typeReferences)
            {
                this.CompilerGeneratedAttribute_Constructor = new MethodReference(".ctor", typeReferences.Void, typeReferences.CompilerGeneratedAttribute)
                {
                    HasThis = true
                };

                this.IMethodLogger_LogEnter = new MethodReference("LogEnter", typeReferences.Void, typeReferences.IMethodLogger)
                {
                    HasThis = true
                };
                this.IMethodLogger_LogEnter.Parameters.Add(new ParameterDefinition(typeReferences.Type));
                this.IMethodLogger_LogEnter.Parameters.Add(new ParameterDefinition(typeReferences.ObjectArray));

                this.IMethodLogger_LogException = new MethodReference("LogException", typeReferences.Void, typeReferences.IMethodLogger)
                {
                    HasThis = true
                };
                this.IMethodLogger_LogException.Parameters.Add(new ParameterDefinition(typeReferences.Type));
                this.IMethodLogger_LogException.Parameters.Add(new ParameterDefinition(typeReferences.Exception));

                this.IMethodLogger_LogLeave = new MethodReference("LogLeave", typeReferences.Void, typeReferences.IMethodLogger)
                {
                    HasThis = true
                };
                this.IMethodLogger_LogLeave.Parameters.Add(new ParameterDefinition(typeReferences.Type));
                this.IMethodLogger_LogLeave.Parameters.Add(new ParameterDefinition(new ArrayType(typeReferences.Object)));
                this.IMethodLogger_LogLeave.Parameters.Add(new ParameterDefinition(typeReferences.Object));

                this.IMethodLoggerFactory_Create = new MethodReference("Create", typeReferences.IMethodLogger, typeReferences.IMethodLoggerFactory)
                {
                    HasThis = true
                };
                this.IMethodLoggerFactory_Create.Parameters.Add(new ParameterDefinition(typeReferences.MethodBase));

                this.MethodBase_GetMethodFromHandle = new MethodReference("GetMethodFromHandle", typeReferences.MethodBase, typeReferences.MethodBase);
                this.MethodBase_GetMethodFromHandle.Parameters.Add(new ParameterDefinition(typeReferences.RuntimeMethodHandle));

                this.LogSpectInitializer_GetFactory = new MethodReference("get_Factory", typeReferences.IMethodLoggerFactory, typeReferences.LogSpectInitializer);

                this.Object_GetType = new MethodReference("GetType", typeReferences.Type, typeReferences.Object)
                {
                    HasThis = true
                };

                this.Type_GetTypeFromHandle = new MethodReference("GetTypeFromHandle", typeReferences.Type, typeReferences.Type);
                this.Type_GetTypeFromHandle.Parameters.Add(new ParameterDefinition(typeReferences.RuntimeTypeHandle));
            }
Exemple #10
0
 internal TypeReference Import(TypeReference tref, bool add)
 {
     foreach (var item in TypeReferences)
     {
         if (tref.Equals(item))
         {
             return(item);
         }
     }
     if (add)
     {
         // if !add see TypeDescriptor comment
         TypeReferences.Add(tref);
     }
     return(tref);
 }
        private OracleColumn BuildColumnDescription()
        {
            var columnReference = IsDirectReference && ColumnReferences.Count == 1
                                ? ColumnReferences[0]
                                : null;

            var columnDescription = columnReference?.ColumnDescription;

            _columnDescription =
                new OracleColumn
            {
                Name     = ColumnName,
                Nullable = columnDescription == null,
                DataType = OracleDataType.Empty
            };

            if (columnDescription != null)
            {
                _columnDescription.Nullable      = columnDescription.Nullable;
                _columnDescription.DataType      = columnDescription.DataType;
                _columnDescription.CharacterSize = columnDescription.CharacterSize;

                if (!_columnDescription.Nullable)
                {
                    if (columnReference.ValidObjectReference is OracleDataObjectReference objectReference)
                    {
                        _columnDescription.Nullable = objectReference.IsOuterJoined;
                    }
                }
            }
            if (IsAsterisk || RootNode.TerminalCount == 0)
            {
                return(_columnDescription);
            }

            var expressionNode = RootNode[0];

            if (String.Equals(expressionNode.Id, NonTerminals.AliasedExpression))
            {
                expressionNode = expressionNode[0];
            }

            if (OracleDataType.TryResolveDataTypeFromExpression(expressionNode, _columnDescription) && !_columnDescription.DataType.IsDynamicCollection)
            {
                if (_columnDescription.DataType.FullyQualifiedName.Name.EndsWith("CHAR"))
                {
                    _columnDescription.CharacterSize = _columnDescription.DataType.Length;
                }

                var isBuiltInDataType = _columnDescription.DataType.IsPrimitive && OracleDatabaseModelBase.BuiltInDataTypes.Any(t => String.Equals(t, _columnDescription.DataType.FullyQualifiedName.Name));
                if (!isBuiltInDataType && SemanticModel.HasDatabaseModel)
                {
                    var oracleType = SemanticModel.DatabaseModel.GetFirstSchemaObject <OracleTypeBase>(_columnDescription.DataType.FullyQualifiedName);
                    if (oracleType == null)
                    {
                        _columnDescription.DataType = OracleDataType.Empty;
                    }
                }
            }
            else if (columnDescription == null)
            {
                expressionNode = expressionNode.UnwrapIfNonChainedExpressionWithinParentheses(out bool isChainedExpression);

                if (!isChainedExpression)
                {
                    var programReference = ProgramReferences.SingleOrDefault(r => r.RootNode == expressionNode);
                    if (programReference == null)
                    {
                        var typeReference = TypeReferences.SingleOrDefault(r => r.RootNode == expressionNode);
                        if (typeReference?.Metadata != null)
                        {
                            var x = typeReference.Metadata.ReturnParameter.CustomDataType;
                        }
                    }
                    else if (programReference.Metadata != null)
                    {
                        if (programReference.Metadata.ReturnParameter == null)
                        {
                            if (programReference.Metadata.Identifier == OracleProgramIdentifier.IdentifierBuiltInProgramCoalesce)
                            {
                            }
                            else if (programReference.Metadata.Identifier == OracleProgramIdentifier.IdentifierBuiltInProgramBinaryToNumber)
                            {
                                _columnDescription.DataType = OracleDataType.NumberType;
                            }
                        }
                        else if (!String.IsNullOrEmpty(programReference.Metadata.ReturnParameter.DataType))
                        {
                            if (programReference.Metadata.Identifier != OracleProgramIdentifier.IdentifierBuiltInProgramNvl)
                            {
                                _columnDescription.DataType = new OracleDataType {
                                    FullyQualifiedName = OracleObjectIdentifier.Create(null, programReference.Metadata.ReturnParameter.DataType)
                                };

                                switch (programReference.Metadata.ReturnParameter.DataType)
                                {
                                case TerminalValues.Varchar:
                                case TerminalValues.Varchar2:
                                    _columnDescription.CharacterSize = _columnDescription.DataType.Length = SemanticModel.DatabaseModel.MaximumVarcharLength;
                                    break;

                                case TerminalValues.Raw:
                                    _columnDescription.DataType.Length = SemanticModel.DatabaseModel.MaximumRawLength;
                                    break;

                                case TerminalValues.NVarchar:
                                case TerminalValues.NVarchar2:
                                    _columnDescription.CharacterSize = _columnDescription.DataType.Length = SemanticModel.DatabaseModel.MaximumNVarcharLength;
                                    break;

                                case TerminalValues.Timestamp:
                                    _columnDescription.DataType = OracleDataType.CreateTimestampDataType(9);
                                    break;

                                case OracleDatabaseModelBase.BuiltInDataTypeTimestampWithTimeZone:
                                    _columnDescription.DataType = OracleDataType.CreateTimestampWithTimeZoneDataType(9);
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            return(_columnDescription);
        }
Exemple #12
0
        internal override object Invoke(object obj, object thisob, BindingFlags options, Binder binder, object[] parameters, CultureInfo culture)
        {
            int length = this.formalParams.Length;
            int n      = (parameters != null) ? parameters.Length : 0;

            if ((!this.hasThis && !this.hasVarargs) && (length == n))
            {
                if (binder != null)
                {
                    return(TypeReferences.ToExecutionContext(this.method).Invoke(base.obj, BindingFlags.SuppressChangeType, null, this.ConvertParams(0, parameters, binder, culture), null));
                }
                return(TypeReferences.ToExecutionContext(this.method).Invoke(base.obj, options, binder, parameters, culture));
            }
            int index = (this.hasThis ? 1 : 0) + (this.hasEngine ? 1 : 0);

            object[] target = new object[length];
            if (this.hasThis)
            {
                target[0] = thisob;
                if (this.hasEngine)
                {
                    target[1] = this.engine;
                }
            }
            else if (this.hasEngine)
            {
                target[0] = this.engine;
            }
            if (this.hasVarargs)
            {
                if (length == (index + 1))
                {
                    target[index] = parameters;
                }
                else
                {
                    int num4 = (length - 1) - index;
                    if (n > num4)
                    {
                        ArrayObject.Copy(parameters, 0, target, index, num4);
                        int      num5      = n - num4;
                        object[] objArray2 = new object[num5];
                        ArrayObject.Copy(parameters, num4, objArray2, 0, num5);
                        target[length - 1] = objArray2;
                    }
                    else
                    {
                        ArrayObject.Copy(parameters, 0, target, index, n);
                        for (int i = n; i < num4; i++)
                        {
                            target[i + index] = Microsoft.JScript.Missing.Value;
                        }
                        target[length - 1] = new object[0];
                    }
                }
            }
            else
            {
                if (parameters != null)
                {
                    if ((length - index) < n)
                    {
                        ArrayObject.Copy(parameters, 0, target, index, length - index);
                    }
                    else
                    {
                        ArrayObject.Copy(parameters, 0, target, index, n);
                    }
                }
                if ((length - index) > n)
                {
                    for (int j = n + index; j < length; j++)
                    {
                        if (((j == (length - 1)) && this.formalParams[j].ParameterType.IsArray) && Microsoft.JScript.CustomAttribute.IsDefined(this.formalParams[j], typeof(ParamArrayAttribute), true))
                        {
                            target[j] = Array.CreateInstance(this.formalParams[j].ParameterType.GetElementType(), 0);
                        }
                        else
                        {
                            target[j] = Microsoft.JScript.Missing.Value;
                        }
                    }
                }
            }
            if (binder != null)
            {
                return(TypeReferences.ToExecutionContext(this.method).Invoke(base.obj, BindingFlags.SuppressChangeType, null, this.ConvertParams(index, target, binder, culture), null));
            }
            return(TypeReferences.ToExecutionContext(this.method).Invoke(base.obj, options, binder, target, culture));
        }
 internal override AST PartiallyEvaluate()
 {
     this.BindName();
     if ((base.members == null) || (base.members.Length == 0))
     {
         ScriptObject parent = base.Globals.ScopeStack.Peek();
         while (parent is FunctionScope)
         {
             parent = parent.GetParent();
         }
         if (!(parent is WithObject) || base.isFullyResolved)
         {
             base.context.HandleError(JSError.UndeclaredVariable, base.isFullyResolved && base.Engine.doFast);
         }
     }
     else
     {
         base.ResolveRHValue();
         MemberInfo member = base.member;
         if (member is FieldInfo)
         {
             FieldInfo field = (FieldInfo)member;
             if ((field is JSLocalField) && !((JSLocalField)field).isDefined)
             {
                 ((JSLocalField)field).isUsedBeforeDefinition = true;
                 base.context.HandleError(JSError.VariableMightBeUnitialized);
             }
             if (!field.IsLiteral)
             {
                 if ((field.IsInitOnly && field.IsStatic) && ((field.DeclaringType == Typeob.GlobalObject) && base.isFullyResolved))
                 {
                     return(new ConstantWrapper(field.GetValue(null), base.context));
                 }
             }
             else
             {
                 object obj3 = (field is JSVariableField) ? ((JSVariableField)field).value : TypeReferences.GetConstantValue(field);
                 if (obj3 is AST)
                 {
                     AST ast = ((AST)obj3).PartiallyEvaluate();
                     if ((ast is ConstantWrapper) && base.isFullyResolved)
                     {
                         return(ast);
                     }
                     obj3 = null;
                 }
                 if (!(obj3 is FunctionObject) && base.isFullyResolved)
                 {
                     return(new ConstantWrapper(obj3, base.context));
                 }
             }
         }
         else if (member is PropertyInfo)
         {
             PropertyInfo info3 = (PropertyInfo)member;
             if ((!info3.CanWrite && !(info3 is JSProperty)) && ((info3.DeclaringType == Typeob.GlobalObject) && base.isFullyResolved))
             {
                 return(new ConstantWrapper(info3.GetValue(null, null), base.context));
             }
         }
         if ((member is Type) && base.isFullyResolved)
         {
             return(new ConstantWrapper(member, base.context));
         }
     }
     return(this);
 }
Exemple #14
0
        private static FieldAccessor SpitAndInstantiateClassFor(FieldInfo field)
        {
            Type        ft = field.FieldType;
            TypeBuilder tb = Runtime.ThunkModuleBuilder.DefineType("accessor" + FieldAccessor.count++, TypeAttributes.Public, typeof(FieldAccessor));

            MethodBuilder mb = tb.DefineMethod("GetValue", MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.ReuseSlot,
                                               typeof(Object), new Type[] { typeof(Object) });

#if !DEBUG
            mb.SetCustomAttribute(new CustomAttributeBuilder(Runtime.TypeRefs.debuggerStepThroughAttributeCtor, new Object[] {}));
            mb.SetCustomAttribute(new CustomAttributeBuilder(Runtime.TypeRefs.debuggerHiddenAttributeCtor, new Object[] {}));
#endif
            ILGenerator il = mb.GetILGenerator();
            if (field.IsLiteral)
            {
                (new ConstantWrapper(TypeReferences.GetConstantValue(field), null)).TranslateToIL(il, ft);
            }
            else if (field.IsStatic)
            {
                il.Emit(OpCodes.Ldsfld, field);
            }
            else
            {
                il.Emit(OpCodes.Ldarg_1);
                il.Emit(OpCodes.Ldfld, field);
            }
            if (ft.IsValueType)
            {
                il.Emit(OpCodes.Box, ft);
            }
            il.Emit(OpCodes.Ret);


            mb = tb.DefineMethod("SetValue", MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.ReuseSlot,
                                 typeof(void), new Type[] { typeof(Object), typeof(Object) });
#if !DEBUG
            mb.SetCustomAttribute(new CustomAttributeBuilder(Runtime.TypeRefs.debuggerStepThroughAttributeCtor, new Object[] {}));
            mb.SetCustomAttribute(new CustomAttributeBuilder(Runtime.TypeRefs.debuggerHiddenAttributeCtor, new Object[] {}));
#endif
            il = mb.GetILGenerator();
            if (!field.IsLiteral)
            {
                if (!field.IsStatic)
                {
                    il.Emit(OpCodes.Ldarg_1);
                }
                il.Emit(OpCodes.Ldarg_2);
                if (ft.IsValueType)
                {
                    Convert.EmitUnbox(il, ft, Type.GetTypeCode(ft));
                }
                if (field.IsStatic)
                {
                    il.Emit(OpCodes.Stsfld, field);
                }
                else
                {
                    il.Emit(OpCodes.Stfld, field);
                }
            }
            il.Emit(OpCodes.Ret);

            Type t = tb.CreateType();
            return((FieldAccessor)Activator.CreateInstance(t));
        }
 internal override AST PartiallyEvaluate()
 {
     this.BindName(null);
     if ((base.members == null) || (base.members.Length == 0))
     {
         if (this.rootObject is ConstantWrapper)
         {
             object obj2 = this.rootObject.Evaluate();
             if (obj2 is Namespace)
             {
                 return(new ConstantWrapper(Namespace.GetNamespace(((Namespace)obj2).Name + "." + base.name, base.Engine), base.context));
             }
         }
         this.HandleNoSuchMemberError();
         return(this);
     }
     base.ResolveRHValue();
     if ((base.member is FieldInfo) && ((FieldInfo)base.member).IsLiteral)
     {
         object obj3 = (base.member is JSVariableField) ? ((JSVariableField)base.member).value : TypeReferences.GetConstantValue((FieldInfo)base.member);
         if (obj3 is AST)
         {
             AST ast = ((AST)obj3).PartiallyEvaluate();
             if (ast is ConstantWrapper)
             {
                 return(ast);
             }
             obj3 = null;
         }
         if (!(obj3 is FunctionObject) && (!(obj3 is ClassScope) || ((ClassScope)obj3).owner.IsStatic))
         {
             return(new ConstantWrapper(obj3, base.context));
         }
     }
     else if (base.member is Type)
     {
         return(new ConstantWrapper(base.member, base.context));
     }
     return(this);
 }
        internal override AST PartiallyEvaluate()
        {
            this.ctor = this.ctor.PartiallyEvaluateAsCallable();
            ASTList args  = new ASTList(this.args.context);
            ASTList list2 = new ASTList(this.args.context);
            int     num   = 0;
            int     count = this.args.count;

            while (num < count)
            {
                AST    ast  = this.args[num];
                Assign elem = ast as Assign;
                if (elem != null)
                {
                    elem.rhside = elem.rhside.PartiallyEvaluate();
                    list2.Append(elem);
                }
                else
                {
                    args.Append(ast.PartiallyEvaluate());
                }
                num++;
            }
            int num3 = args.count;

            IReflect[] argIRs = new IReflect[num3];
            for (int i = 0; i < num3; i++)
            {
                AST ast2 = args[i];
                if (ast2 is ConstantWrapper)
                {
                    object argument = ast2.Evaluate();
                    if ((argIRs[i] = TypeOfArgument(argument)) == null)
                    {
                        goto Label_0120;
                    }
                    this.positionalArgValues.Add(argument);
                    continue;
                }
                if ((ast2 is ArrayLiteral) && ((ArrayLiteral)ast2).IsOkToUseInCustomAttribute())
                {
                    argIRs[i] = Typeob.ArrayObject;
                    this.positionalArgValues.Add(ast2.Evaluate());
                    continue;
                }
Label_0120:
                ast2.context.HandleError(JSError.InvalidCustomAttributeArgument);
                return(null);
            }
            this.type = this.ctor.ResolveCustomAttribute(args, argIRs, this.target);
            if (this.type == null)
            {
                return(null);
            }
            if (Microsoft.JScript.Convert.IsPromotableTo((IReflect)this.type, Typeob.CodeAccessSecurityAttribute))
            {
                base.context.HandleError(JSError.CannotUseStaticSecurityAttribute);
                return(null);
            }
            ParameterInfo[] parameters = ((ConstructorInfo)((Binding)this.ctor).member).GetParameters();
            int             num5       = 0;
            int             num6       = this.positionalArgValues.Count;

            foreach (ParameterInfo info2 in parameters)
            {
                IReflect reflect = (info2 is ParameterDeclaration) ? ((ParameterDeclaration)info2).ParameterIReflect : info2.ParameterType;
                if (num5 < num6)
                {
                    object obj3 = this.positionalArgValues[num5];
                    this.positionalArgValues[num5] = Microsoft.JScript.Convert.Coerce(obj3, reflect, obj3 is ArrayObject);
                    num5++;
                }
                else
                {
                    object defaultParameterValue;
                    if (TypeReferences.GetDefaultParameterValue(info2) == System.Convert.DBNull)
                    {
                        defaultParameterValue = Microsoft.JScript.Convert.Coerce(null, reflect);
                    }
                    else
                    {
                        defaultParameterValue = TypeReferences.GetDefaultParameterValue(info2);
                    }
                    this.positionalArgValues.Add(defaultParameterValue);
                }
            }
            int num7 = 0;
            int num8 = list2.count;

            while (num7 < num8)
            {
                Assign assign2 = (Assign)list2[num7];
                if ((assign2.lhside is Lookup) && ((assign2.rhside is ConstantWrapper) || ((assign2.rhside is ArrayLiteral) && ((ArrayLiteral)assign2.rhside).IsOkToUseInCustomAttribute())))
                {
                    object   obj5     = assign2.rhside.Evaluate();
                    IReflect reflect2 = null;
                    if ((obj5 is ArrayObject) || (((reflect2 = TypeOfArgument(obj5)) != null) && (reflect2 != Typeob.Object)))
                    {
                        string       name   = ((Lookup)assign2.lhside).Name;
                        MemberInfo[] member = ((IReflect)this.type).GetMember(name, BindingFlags.Public | BindingFlags.Instance);
                        if ((member == null) || (member.Length == 0))
                        {
                            assign2.context.HandleError(JSError.NoSuchMember);
                            return(null);
                        }
                        if (member.Length == 1)
                        {
                            MemberInfo info3 = member[0];
                            if (info3 is FieldInfo)
                            {
                                FieldInfo info4 = (FieldInfo)info3;
                                if (info4.IsLiteral || info4.IsInitOnly)
                                {
                                    goto Label_04B6;
                                }
                                try
                                {
                                    IReflect reflect3 = (info4 is JSVariableField) ? ((JSVariableField)info4).GetInferredType(null) : info4.FieldType;
                                    obj5 = Microsoft.JScript.Convert.Coerce(obj5, reflect3, obj5 is ArrayObject);
                                    this.namedArgFields.Add(info3);
                                    this.namedArgFieldValues.Add(obj5);
                                    goto Label_04C9;
                                }
                                catch (JScriptException)
                                {
                                    assign2.rhside.context.HandleError(JSError.TypeMismatch);
                                    return(null);
                                }
                            }
                            if (info3 is PropertyInfo)
                            {
                                PropertyInfo prop      = (PropertyInfo)info3;
                                MethodInfo   setMethod = JSProperty.GetSetMethod(prop, false);
                                if (setMethod != null)
                                {
                                    ParameterInfo[] infoArray3 = setMethod.GetParameters();
                                    if ((infoArray3 != null) && (infoArray3.Length == 1))
                                    {
                                        try
                                        {
                                            IReflect reflect4 = (infoArray3[0] is ParameterDeclaration) ? ((ParameterDeclaration)infoArray3[0]).ParameterIReflect : infoArray3[0].ParameterType;
                                            obj5 = Microsoft.JScript.Convert.Coerce(obj5, reflect4, obj5 is ArrayObject);
                                            this.namedArgProperties.Add(info3);
                                            this.namedArgPropertyValues.Add(obj5);
                                            goto Label_04C9;
                                        }
                                        catch (JScriptException)
                                        {
                                            assign2.rhside.context.HandleError(JSError.TypeMismatch);
                                            return(null);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
Label_04B6:
                assign2.context.HandleError(JSError.InvalidCustomAttributeArgument);
                return(null);

Label_04C9:
                num7++;
            }
            if (!this.CheckIfTargetOK(this.type))
            {
                return(null);
            }
            try
            {
                Type type = this.type as Type;
                if ((type != null) && (this.target is AssemblyCustomAttributeList))
                {
                    if (type.FullName == "System.Reflection.AssemblyAlgorithmIdAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            base.Engine.Globals.assemblyHashAlgorithm = (AssemblyHashAlgorithm)Microsoft.JScript.Convert.CoerceT(this.positionalArgValues[0], typeof(AssemblyHashAlgorithm));
                        }
                        return(null);
                    }
                    if (type.FullName == "System.Reflection.AssemblyCultureAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            string str2 = Microsoft.JScript.Convert.ToString(this.positionalArgValues[0]);
                            if ((base.Engine.PEFileKind != PEFileKinds.Dll) && (str2.Length > 0))
                            {
                                base.context.HandleError(JSError.ExecutablesCannotBeLocalized);
                                return(null);
                            }
                            base.Engine.Globals.assemblyCulture = new CultureInfo(str2);
                        }
                        return(null);
                    }
                    if (type.FullName == "System.Reflection.AssemblyDelaySignAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            base.Engine.Globals.assemblyDelaySign = Microsoft.JScript.Convert.ToBoolean(this.positionalArgValues[0], false);
                        }
                        return(null);
                    }
                    if (type.FullName == "System.Reflection.AssemblyFlagsAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            base.Engine.Globals.assemblyFlags = (AssemblyFlags)((uint)Microsoft.JScript.Convert.CoerceT(this.positionalArgValues[0], typeof(uint)));
                        }
                        return(null);
                    }
                    if (type.FullName == "System.Reflection.AssemblyKeyFileAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            base.Engine.Globals.assemblyKeyFileName        = Microsoft.JScript.Convert.ToString(this.positionalArgValues[0]);
                            base.Engine.Globals.assemblyKeyFileNameContext = base.context;
                            if ((base.Engine.Globals.assemblyKeyFileName != null) && (base.Engine.Globals.assemblyKeyFileName.Length == 0))
                            {
                                base.Engine.Globals.assemblyKeyFileName        = null;
                                base.Engine.Globals.assemblyKeyFileNameContext = null;
                            }
                        }
                        return(null);
                    }
                    if (type.FullName == "System.Reflection.AssemblyKeyNameAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            base.Engine.Globals.assemblyKeyName        = Microsoft.JScript.Convert.ToString(this.positionalArgValues[0]);
                            base.Engine.Globals.assemblyKeyNameContext = base.context;
                            if ((base.Engine.Globals.assemblyKeyName != null) && (base.Engine.Globals.assemblyKeyName.Length == 0))
                            {
                                base.Engine.Globals.assemblyKeyName        = null;
                                base.Engine.Globals.assemblyKeyNameContext = null;
                            }
                        }
                        return(null);
                    }
                    if (type.FullName == "System.Reflection.AssemblyVersionAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            base.Engine.Globals.assemblyVersion = this.ParseVersion(Microsoft.JScript.Convert.ToString(this.positionalArgValues[0]));
                        }
                        return(null);
                    }
                    if (type.FullName == "System.CLSCompliantAttribute")
                    {
                        base.Engine.isCLSCompliant = ((this.args == null) || (this.args.count == 0)) || Microsoft.JScript.Convert.ToBoolean(this.positionalArgValues[0], false);
                        return(this);
                    }
                }
            }
            catch (ArgumentException)
            {
                base.context.HandleError(JSError.InvalidCall);
            }
            return(this);
        }
Exemple #17
0
 public MethodRewriter(ModuleDefinition module)
 {
     this.module           = module;
     this.typeReferences   = new TypeReferences(this.module);
     this.methodReferences = new MethodReferences(this.typeReferences);
 }
        internal static void RegisterType(Type type)
        {
            if (AllowReferences)
            {
                PropertyInfo[] props = type.GetPropertiesCached()
                                       .Union(type.GetProperties(BindingFlags.NonPublic | BindingFlags.Instance))
                                       .ToArray();
                foreach (PropertyInfo prop in props)
                {
                    UnifiedIMReference reff = prop.GetCustomAttribute <UnifiedIMReference>();
                    UnifiedIMIndex     indx = prop.GetCustomAttribute <UnifiedIMIndex>();
                    bool alreadyIndexed     = false;

                    if (reff != null)
                    {
                        if (reff.HostPropertyType == null)
                        {
                            reff.HostPropertyType = props.FirstOrDefault(x => x.Name == reff.HostProperty)?.PropertyType;
                        }
                        if (reff.HostType == null)
                        {
                            reff.HostType = prop.DeclaringType;
                        }
                        reff.SetProperty     = prop.Name;
                        reff.SetPropertyType = prop.PropertyType;
                        if (reff.SetPropertyType == null)
                        {
                            throw new ArgumentException("Set Property does not exist");
                        }
                        References.Add(reff);
                        if (!HostReferences.ContainsKey(type))
                        {
                            HostReferences.Add(type, new List <UnifiedIMReference>());
                        }
                        HostReferences[type].Add(reff);
                        if (!TargetReferences.ContainsKey(reff.TargetType))
                        {
                            TargetReferences.Add(reff.TargetType, new List <UnifiedIMReference>());
                        }
                        TargetReferences[reff.TargetType].Add(reff);
                        if (!TypeReferences.ContainsKey(reff.HostType))
                        {
                            TypeReferences.Add(reff.HostType, new List <UnifiedIMReference>());
                        }
                        if (!TypeReferences.ContainsKey(reff.TargetType))
                        {
                            TypeReferences.Add(reff.TargetType, new List <UnifiedIMReference>());
                        }
                        TypeReferences[reff.TargetType].Add(reff);
                        TypeReferences[reff.HostType].Add(reff);
                        if (AllowIndexes && CreateReferenceIndexes)
                        {
                            if (reff.TargetProperty != "ObjectID" && !HasIndex(reff.TargetType, reff.TargetProperty))
                            {
                                AddIndex(reff.TargetType, reff.TargetProperty);
                            }
                            if (reff.HostProperty != "ObjectID" && !HasIndex(reff.HostType, reff.HostProperty))
                            {
                                AddIndex(reff.HostType, reff.HostProperty);
                            }

                            if (reff.TargetType == type || reff.HostType == type)
                            {
                                alreadyIndexed = true;
                            }
                        }
                    }

                    if (!alreadyIndexed && prop.Name != "ObjectID" && indx != null)
                    {
                        AddIndex(type, prop.Name);
                    }
                }
            }

            if (!_databaseGetters.ContainsKey(type))
            {
                _databaseGetters.Add(type, ((IUnifiedIMObject)Activator.CreateInstance(type)).DatabaseBase);
            }
        }
        internal static void HandleObjectCreation <T>(IUnifiedIMObject obj)
        {
            if (UnifiedSystem.AllowReferences)
            {
                UnifiedSystem.ResolveReferences(obj, typeof(T));
            }
            if (UnifiedSystem.UseOmniBase)
            {
                lock (UnifiedSystem.OmniBase)
                    UnifiedSystem.OmniBase.Add(obj.ObjectID, obj);
            }

            List <string> indexesToAdd = new List <string>();

            if (UnifiedSystem.AllowReferences)
            {
                List <UnifiedIMReference> refs = new List <UnifiedIMReference>();
                if (TypeReferences.ContainsKey(typeof(T)))
                {
                    refs = TypeReferences[typeof(T)];
                }

                /*
                 * ObjectIndex<IUnifiedIMObject> oi = null;
                 * if (CreateReferenceIndexes)
                 *  if (Indexes.ContainsKey(typeof(T)))
                 *      oi = Indexes[typeof(T)];*/

                foreach (UnifiedIMReference reff in refs)
                {
                    if (reff.HostType == typeof(T))
                    {
                        //object value = reff.GetHostProperty(obj);
                        //if(!obj.PropertyStates.ContainsKey(reff.HostProperty))
                        //obj.PropertyStates.Add(reff.HostProperty, new UIMPropertyState(value));
                        if (CreateReferenceIndexes && reff.HostProperty != "ObjectID")
                        {
                            // oi.AddIndex(reff.HostProperty, value, obj);
                            indexesToAdd.Add(reff.HostProperty);
                        }
                    }

                    else if (reff.TargetType == typeof(T))
                    {
                        //object value = reff.GetTargetProperty(obj);
                        //if (!obj.PropertyStates.ContainsKey(reff.TargetProperty))
                        //    obj.PropertyStates.Add(reff.TargetProperty, new UIMPropertyState(value));
                        if (CreateReferenceIndexes && reff.TargetProperty != "ObjectID")
                        {
                            //oi.AddIndex(reff.TargetProperty, value, obj);
                            indexesToAdd.Add(reff.TargetProperty);
                        }
                    }
                }
            }

            if (AllowIndexes)
            {
                if (IndexProperties.ContainsKey(typeof(T)))
                {
                    indexesToAdd.AddRange(IndexProperties[typeof(T)]);
                }

                ObjectIndexer <IUnifiedIMObject> oi = null;
                if (Indexes.ContainsKey(typeof(T)))
                {
                    oi = Indexes[typeof(T)];
                }

                if (oi != null)
                {
                    foreach (string idx in indexesToAdd.Distinct())
                    {
                        object value = Property.Get(obj, idx);
                        if (!obj.PropertyStates.ContainsKey(idx))
                        {
                            obj.PropertyStates.Add(idx, new UIMPropertyState(value));
                        }
                        oi.AddIndex(idx, value, obj);
                    }
                }
            }
        }
 internal override AST PartiallyEvaluate()
 {
     this.BindName(null);
     if (this.members == null || this.members.Length == 0)
     {
         //if this rootObject is a constant and its value is a namespace, turn this node also into a namespace constant
         if (this.rootObject is ConstantWrapper)
         {
             Object val = this.rootObject.Evaluate();
             if (val is Namespace)
             {
                 return(new ConstantWrapper(Namespace.GetNamespace(((Namespace)val).Name + "." + this.name, this.Engine), this.context));
             }
         }
         this.HandleNoSuchMemberError();
         return(this);
     }
     this.ResolveRHValue();
     if (this.member is FieldInfo && ((FieldInfo)this.member).IsLiteral)
     {
         Object val = this.member is JSVariableField ? ((JSVariableField)this.member).value : TypeReferences.GetConstantValue((FieldInfo)this.member);
         if (val is AST)
         {
             AST pval = ((AST)val).PartiallyEvaluate();
             if (pval is ConstantWrapper)
             {
                 return(pval);
             }
             val = null;
         }
         if (!(val is FunctionObject) && (!(val is ClassScope) || ((ClassScope)val).owner.IsStatic))
         {
             return(new ConstantWrapper(val, this.context));
         }
     }
     else if (this.member is Type)
     {
         return(new ConstantWrapper(this.member, this.context));
     }
     return(this);
 }
Exemple #21
0
        internal override Object Invoke(Object obj, Object thisob, BindingFlags options, Binder binder, Object[] parameters, CultureInfo culture)
        {
            int n  = this.formalParams.Length;
            int pn = (parameters != null ? parameters.Length : 0);

            if (!this.hasThis && !this.hasVarargs && n == pn)
            {
                if (binder != null)
                {
                    return(TypeReferences.ToExecutionContext(this.method).Invoke(this.obj, BindingFlags.SuppressChangeType, null, this.ConvertParams(0, parameters, binder, culture), null));
                }
                else
                {
                    return(TypeReferences.ToExecutionContext(this.method).Invoke(this.obj, options, binder, parameters, culture));
                }
            }

            int offset = (this.hasThis ? 1 : 0) + (this.hasEngine ? 1 : 0);

            Object[] arguments = new Object[n];
            if (this.hasThis)
            {
                arguments[0] = thisob;
                if (this.hasEngine)
                {
                    arguments[1] = this.engine;
                }
            }
            else if (this.hasEngine)
            {
                arguments[0] = this.engine;
            }
            if (this.hasVarargs)
            {
                if (n == offset + 1) //No params other than the vararg array
                {
                    arguments[offset] = parameters;
                }
                else
                {
                    //Some of the values in parameters must be passed separately from the vararg array
                    int argsToCopy = n - 1 - offset; //The number of separate arguments
                    if (pn > argsToCopy)
                    {
                        ArrayObject.Copy(parameters, 0, arguments, offset, argsToCopy);
                        int      vn      = pn - argsToCopy;
                        Object[] varargs = new Object[vn];
                        ArrayObject.Copy(parameters, argsToCopy, varargs, 0, vn);
                        arguments[n - 1] = varargs;
                    }
                    else
                    {
                        ArrayObject.Copy(parameters, 0, arguments, offset, pn);
                        for (int i = pn; i < argsToCopy; i++)
                        {
                            arguments[i + offset] = Missing.Value;
                        }
                        arguments[n - 1] = new Object[0];
                    }
                }
            }
            else
            {
                if (parameters != null)
                {
                    if (n - offset < pn)
                    {
                        ArrayObject.Copy(parameters, 0, arguments, offset, n - offset);
                    }
                    else
                    {
                        ArrayObject.Copy(parameters, 0, arguments, offset, pn);
                    }
                }
                if (n - offset > pn)
                {
                    for (int i = pn + offset; i < n; i++)
                    {
                        if (i == n - 1 && this.formalParams[i].ParameterType.IsArray && CustomAttribute.IsDefined(this.formalParams[i], typeof(ParamArrayAttribute), true))
                        {
                            arguments[i] = System.Array.CreateInstance(this.formalParams[i].ParameterType.GetElementType(), 0);
                        }
                        else
                        {
                            arguments[i] = Missing.Value;
                        }
                    }
                }
            }
            if (binder != null)
            {
                return(TypeReferences.ToExecutionContext(this.method).Invoke(this.obj, BindingFlags.SuppressChangeType, null, this.ConvertParams(offset, arguments, binder, culture), null));
            }
            else
            {
                return(TypeReferences.ToExecutionContext(this.method).Invoke(this.obj, options, binder, arguments, culture));
            }
        }
Exemple #22
0
 internal override AST PartiallyEvaluate()
 {
     this.BindName();
     if (this.members == null || this.members.Length == 0)
     {
         //Give a warning, unless inside a with statement
         ScriptObject scope = Globals.ScopeStack.Peek();
         while (scope is FunctionScope)
         {
             scope = scope.GetParent();
         }
         if (!(scope is WithObject) || this.isFullyResolved)
         {
             this.context.HandleError(JSError.UndeclaredVariable, this.isFullyResolved && this.Engine.doFast);
         }
     }
     else
     {
         this.ResolveRHValue();
         MemberInfo member = this.member;
         if (member is FieldInfo)
         {
             FieldInfo field = (FieldInfo)member;
             if (field is JSLocalField && !((JSLocalField)field).isDefined)
             {
                 ((JSLocalField)field).isUsedBeforeDefinition = true;
                 this.context.HandleError(JSError.VariableMightBeUnitialized);
             }
             if (field.IsLiteral)
             {
                 Object val = field is JSVariableField ? ((JSVariableField)field).value : TypeReferences.GetConstantValue(field);
                 if (val is AST)
                 {
                     AST pval = ((AST)val).PartiallyEvaluate();
                     if (pval is ConstantWrapper && this.isFullyResolved)
                     {
                         return(pval);
                     }
                     val = null;
                 }
                 if (!(val is FunctionObject) && this.isFullyResolved)
                 {
                     return(new ConstantWrapper(val, this.context));
                 }
             }
             else if (field.IsInitOnly && field.IsStatic && field.DeclaringType == Typeob.GlobalObject && this.isFullyResolved)
             {
                 return(new ConstantWrapper(field.GetValue(null), this.context));
             }
         }
         else if (member is PropertyInfo)
         {
             PropertyInfo prop = (PropertyInfo)member;
             if (!prop.CanWrite && !(prop is JSProperty) && prop.DeclaringType == Typeob.GlobalObject && this.isFullyResolved)
             {
                 return(new ConstantWrapper(prop.GetValue(null, null), this.context));
             }
         }
         if (member is Type && this.isFullyResolved)
         {
             return(new ConstantWrapper(member, this.context));
         }
     }
     return(this);
 }
Exemple #23
0
        internal override AST PartiallyEvaluate()
        {
            this.ctor = this.ctor.PartiallyEvaluateAsCallable();

            //first weed out assignment expressions and use them as property initializers
            ASTList positionalArgs = new ASTList(this.args.context);
            ASTList namedArgs      = new ASTList(this.args.context);

            for (int i = 0, m = this.args.count; i < m; i++)
            {
                AST    arg    = this.args[i];
                Assign assign = arg as Assign;
                if (assign != null)
                {
                    assign.rhside = assign.rhside.PartiallyEvaluate();
                    namedArgs.Append(assign);
                }
                else
                {
                    positionalArgs.Append(arg.PartiallyEvaluate());
                }
            }

            int n = positionalArgs.count;

            IReflect[] argIRs = new IReflect[n];
            for (int i = 0; i < n; i++)
            {
                AST arg = positionalArgs[i];
                // only accept ConstantWrappers
                if (arg is ConstantWrapper)
                {
                    Object argument = arg.Evaluate();
                    if ((argIRs[i] = CustomAttribute.TypeOfArgument(argument)) != null)
                    {
                        this.positionalArgValues.Add(argument);
                        continue;
                    }
                }
                else if (arg is ArrayLiteral && ((ArrayLiteral)arg).IsOkToUseInCustomAttribute())
                {
                    argIRs[i] = Typeob.ArrayObject;
                    this.positionalArgValues.Add(arg.Evaluate());
                    continue;
                }
                arg.context.HandleError(JSError.InvalidCustomAttributeArgument);
                return(null); // the custom attribute is not good and it will be ignored
            }

            //Get the custom attribute and the appropriate constructor (under the covers)
            this.type = this.ctor.ResolveCustomAttribute(positionalArgs, argIRs, this.target);
            if (this.type == null)
            {
                return(null);
            }
            if (Convert.IsPromotableTo((IReflect)this.type, Typeob.CodeAccessSecurityAttribute))
            {
                this.context.HandleError(JSError.CannotUseStaticSecurityAttribute);
                return(null);
            }


            //Coerce the positional arguments to the right type and supply default values for optional parameters
            ConstructorInfo c = (ConstructorInfo)((Binding)this.ctor).member;

            ParameterInfo[] parameters = c.GetParameters();
            int             j          = 0;
            int             len        = this.positionalArgValues.Count;

            foreach (ParameterInfo p in parameters)
            {
                IReflect ir = p is ParameterDeclaration ? ((ParameterDeclaration)p).ParameterIReflect : p.ParameterType;
                if (j < len)
                {
                    Object value = this.positionalArgValues[j];
                    this.positionalArgValues[j] = Convert.Coerce(value, ir, value is ArrayObject);
                    j++;
                }
                else
                {
                    Object value;
                    if (TypeReferences.GetDefaultParameterValue(p) == System.Convert.DBNull)
                    {
                        value = Convert.Coerce(null, ir);
                    }
                    else
                    {
                        value = TypeReferences.GetDefaultParameterValue(p);
                    }
                    this.positionalArgValues.Add(value);
                }
            }

            //Check validity of property/field initializers
            for (int i = 0, m = namedArgs.count; i < m; i++)
            {
                Assign assign = (Assign)namedArgs[i];
                if (assign.lhside is Lookup &&
                    (assign.rhside is ConstantWrapper ||
                     (assign.rhside is ArrayLiteral && ((ArrayLiteral)assign.rhside).IsOkToUseInCustomAttribute())))
                {
                    Object   value   = assign.rhside.Evaluate();
                    IReflect argType = null;
                    if (value is ArrayObject || ((argType = CustomAttribute.TypeOfArgument(value)) != null && argType != Typeob.Object))
                    {
                        String        name    = ((Lookup)assign.lhside).Name;
                        MemberInfo [] members = ((IReflect)this.type).GetMember(name, BindingFlags.Public | BindingFlags.Instance);
                        if (members == null || members.Length == 0)
                        {
                            assign.context.HandleError(JSError.NoSuchMember);
                            return(null);
                        }
                        if (members.Length == 1)
                        {
                            MemberInfo member = members[0];
                            if (member is FieldInfo)
                            {
                                FieldInfo fieldInfo = (FieldInfo)member;
                                if (!fieldInfo.IsLiteral && !fieldInfo.IsInitOnly)
                                {
                                    try{
                                        IReflect ir = fieldInfo is JSVariableField ? ((JSVariableField)fieldInfo).GetInferredType(null) : fieldInfo.FieldType;
                                        value = Convert.Coerce(value, ir, value is ArrayObject);
                                        this.namedArgFields.Add(member);
                                        this.namedArgFieldValues.Add(value);
                                        continue;
                                    }catch (JScriptException) {
                                        assign.rhside.context.HandleError(JSError.TypeMismatch);
                                        return(null); // the custom attribute is not good and it will be ignored
                                    }
                                }
                            }
                            else if (member is PropertyInfo)
                            {
                                PropertyInfo propertyInfo  = (PropertyInfo)member;
                                MethodInfo   setMethodInfo = JSProperty.GetSetMethod(propertyInfo, false);
                                if (setMethodInfo != null)
                                {
                                    ParameterInfo [] paramInfo = setMethodInfo.GetParameters();
                                    if (paramInfo != null && paramInfo.Length == 1)
                                    {
                                        try{
                                            IReflect ir = paramInfo[0] is ParameterDeclaration ? ((ParameterDeclaration)paramInfo[0]).ParameterIReflect : paramInfo[0].ParameterType;
                                            value = Convert.Coerce(value, ir, value is ArrayObject);
                                            this.namedArgProperties.Add(member);
                                            this.namedArgPropertyValues.Add(value);
                                        }catch (JScriptException) {
                                            assign.rhside.context.HandleError(JSError.TypeMismatch);
                                            return(null); // the custom attribute is not good and it will be ignored
                                        }
                                        continue;
                                    }
                                }
                            }
                        }
                    }
                }
                assign.context.HandleError(JSError.InvalidCustomAttributeArgument);
                return(null);
            }

            if (!this.CheckIfTargetOK(this.type))
            {
                return(null); //Ignore attribute
            }
            //Consume and discard assembly name attributes
            try{
                Type ty = this.type as Type;
                if (ty != null && this.target is AssemblyCustomAttributeList)
                {
                    if (ty.FullName == "System.Reflection.AssemblyAlgorithmIdAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            this.Engine.Globals.assemblyHashAlgorithm = (AssemblyHashAlgorithm)Convert.CoerceT(this.positionalArgValues[0], typeof(AssemblyHashAlgorithm));
                        }
                        return(null);
                    }
                    if (ty.FullName == "System.Reflection.AssemblyCultureAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            String cultureId = Convert.ToString(this.positionalArgValues[0]);
                            if (this.Engine.PEFileKind != PEFileKinds.Dll && cultureId.Length > 0)
                            {
                                this.context.HandleError(JSError.ExecutablesCannotBeLocalized);
                                return(null);
                            }
                            this.Engine.Globals.assemblyCulture = new CultureInfo(cultureId);
                        }
                        return(null);
                    }
                    if (ty.FullName == "System.Reflection.AssemblyDelaySignAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            this.Engine.Globals.assemblyDelaySign = Convert.ToBoolean(this.positionalArgValues[0], false);
                        }
                        return(null);
                    }
                    if (ty.FullName == "System.Reflection.AssemblyFlagsAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            this.Engine.Globals.assemblyFlags = (AssemblyFlags)(uint)Convert.CoerceT(this.positionalArgValues[0], typeof(uint));
                        }
                        return(null);
                    }
                    if (ty.FullName == "System.Reflection.AssemblyKeyFileAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            this.Engine.Globals.assemblyKeyFileName        = Convert.ToString(this.positionalArgValues[0]);
                            this.Engine.Globals.assemblyKeyFileNameContext = this.context;
                            if (this.Engine.Globals.assemblyKeyFileName != null && this.Engine.Globals.assemblyKeyFileName.Length == 0)
                            {
                                this.Engine.Globals.assemblyKeyFileName        = null;
                                this.Engine.Globals.assemblyKeyFileNameContext = null;
                            }
                        }
                        return(null);
                    }
                    if (ty.FullName == "System.Reflection.AssemblyKeyNameAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            this.Engine.Globals.assemblyKeyName        = Convert.ToString(this.positionalArgValues[0]);
                            this.Engine.Globals.assemblyKeyNameContext = this.context;
                            if (this.Engine.Globals.assemblyKeyName != null && this.Engine.Globals.assemblyKeyName.Length == 0)
                            {
                                this.Engine.Globals.assemblyKeyName        = null;
                                this.Engine.Globals.assemblyKeyNameContext = null;
                            }
                        }
                        return(null);
                    }
                    if (ty.FullName == "System.Reflection.AssemblyVersionAttribute")
                    {
                        if (this.positionalArgValues.Count > 0)
                        {
                            this.Engine.Globals.assemblyVersion = this.ParseVersion(Convert.ToString(this.positionalArgValues[0]));
                        }
                        return(null);
                    }
                    if (ty.FullName == "System.CLSCompliantAttribute")
                    {
                        this.Engine.isCLSCompliant = this.args == null || this.args.count == 0 || Convert.ToBoolean(this.positionalArgValues[0], false);
                        return(this);
                    }
                }
            }catch (ArgumentException) {
                this.context.HandleError(JSError.InvalidCall);
            }

            return(this);
        }