Ejemplo n.º 1
0
        private Attribute GetCustomAttributeObject()
        {
            Type attribute = LanguagePrimitives.ConvertStringToAttribute(this._name);

            if (attribute == null)
            {
                throw InterpreterError.NewInterpreterException((object)this.NodeToken, typeof(RuntimeException), this.NodeToken, "CustomAttributeTypeNotFound", (object)this._name);
            }
            if (!attribute.IsSubclassOf(typeof(Attribute)))
            {
                throw InterpreterError.NewInterpreterException((object)this.NodeToken, typeof(RuntimeException), this.NodeToken, "InValidCustomAttributeType", (object)this._name);
            }
            try
            {
                if (this._arguments.Length == 0)
                {
                    ConstructorInfo constructor = attribute.GetConstructor(Type.EmptyTypes);
                    if (constructor != null)
                    {
                        if (constructor.IsPublic)
                        {
                            return((Attribute)DotNetAdapter.ConstructorInvokeDotNet(attribute, new ConstructorInfo[1]
                            {
                                constructor
                            }, this._arguments));
                        }
                    }
                }
                else
                {
                    ConstructorInfo[] constructors = attribute.GetConstructors();
                    if (constructors.Length != 0)
                    {
                        return((Attribute)DotNetAdapter.ConstructorInvokeDotNet(attribute, constructors, this._arguments));
                    }
                }
            }
            catch (RuntimeException ex)
            {
                if (ex.ErrorRecord.InvocationInfo == null)
                {
                    ex.ErrorRecord.SetInvocationInfo(new InvocationInfo((CommandInfo)null, this.NodeToken));
                }
                throw;
            }
            throw InterpreterError.NewInterpreterException((object)this.NodeToken, typeof(RuntimeException), this.NodeToken, "CannotFindConstructorForCustomAttribute", (object)this._name);
        }