Exemplo n.º 1
0
 public override void OnMemberReferenceExpression(MemberReferenceExpression node)
 {
     if (node.Entity is IField)
     {
         this._currentStatement.Expression = new CodeFieldReferenceExpression(this.VisitExpr(node.Target), node.Name);
         return;
     }
     if (node.Entity is IProperty)
     {
         this._currentStatement.Expression = new CodePropertyReferenceExpression(this.VisitExpr(node.Target), node.Name);
         return;
     }
     if (node.Entity is IType)
     {
         this._currentStatement.Expression = new CodeTypeReferenceExpression(BooCodeDomConverter.GetType(node.ToCodeString()));
         return;
     }
     if (node.Entity is IEvent)
     {
         this._currentStatement.Expression = new CodeEventReferenceExpression(this.VisitExpr(node.Target), node.Name);
         return;
     }
     if (node.Entity is IMethod)
     {
         this._currentStatement.Expression = new CodeMethodReferenceExpression(this.VisitExpr(node.Target), node.Name);
         return;
     }
     throw new Exception(new StringBuilder("Unknown member type for ").Append(node.ToCodeString()).ToString());
 }
Exemplo n.º 2
0
        private void OnTypeDefinition(TypeDefinition node)
        {
            CodeTypeDeclaration currentType = this._currentType;

            this._currentType = new CodeTypeDeclaration();
            this.OnTypeMember(node, this._currentType);
            this._currentType.IsPartial = ((TypeMemberModifiers.Partial & node.Modifiers) == TypeMemberModifiers.Partial);
            IEnumerator <TypeReference> enumerator = node.BaseTypes.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    TypeReference current = enumerator.Current;
                    this._currentType.BaseTypes.Add(BooCodeDomConverter.GetType(current.ToString()));
                }
            }
            finally
            {
                enumerator.Dispose();
            }
            this.Visit(node.GenericParameters);
            this.Visit(node.Members);
            if (currentType != null)
            {
                currentType.Members.Add(this._currentType);
            }
            else
            {
                this._defaultNS.Types.Add(this._currentType);
            }
            this._currentType = currentType;
        }
Exemplo n.º 3
0
        public override void OnField(Field node)
        {
            CodeMemberField codeMemberField = new CodeMemberField();

            this.OnTypeMember(node, codeMemberField);
            if (node.Type != null)
            {
                codeMemberField.Type = BooCodeDomConverter.GetType(node.Type.ToString());
            }
            codeMemberField.InitExpression = this.VisitExpr(node.Initializer);
            this._currentType.Members.Add(codeMemberField);
        }
Exemplo n.º 4
0
        public override void OnTryCastExpression(TryCastExpression node)
        {
            CodeExpression                codeExpression = this.VisitExpr(node.Target);
            CodeTypeReference             type           = BooCodeDomConverter.GetType(node.Type.ToCodeString());
            CodeMethodReferenceExpression codeMethodReferenceExpression = codeExpression as CodeMethodReferenceExpression;

            if (codeMethodReferenceExpression != null)
            {
                this._currentStatement.Expression = new CodeDelegateCreateExpression(type, codeMethodReferenceExpression.TargetObject, codeMethodReferenceExpression.MethodName);
            }
            else
            {
                this._currentStatement.Expression = new CodeCastExpression(type, codeExpression);
            }
        }
Exemplo n.º 5
0
        private bool HandleConstructorInvocation(MethodInvocationExpression node)
        {
            int result;

            if (node.Target.Entity.EntityType != EntityType.Constructor)
            {
                result = 0;
            }
            else
            {
                this._currentStatement.Expression = new CodeObjectCreateExpression(BooCodeDomConverter.GetType(node.Target.ToCodeString()), node.Arguments.Select(this.VisitExpr).ToArray());
                IParameter[] parameters = ((IEntityWithParameters)node.Target.Entity).GetParameters();
                int          num        = 0;
                int          length     = parameters.Length;
                if (length < 0)
                {
                    throw new ArgumentOutOfRangeException("max");
                }
                while (num < length)
                {
                    int index = num;
                    num++;
                    IParameter[] array = parameters;
                    if (string.Compare(array[RuntimeServices.NormalizeArrayIndex(array, index)].Type.Name, "single", true) == 0)
                    {
                        CodeExpression codeExpression = ((CodeObjectCreateExpression)this._currentStatement.Expression).Parameters[index];
                        if (codeExpression is CodePrimitiveExpression)
                        {
                            ((CodeObjectCreateExpression)this._currentStatement.Expression).Parameters[index] = new CodeCastExpression(BooCodeDomConverter.GetType("single"), codeExpression);
                        }
                    }
                }
                result = 1;
            }
            return((byte)result != 0);
        }
Exemplo n.º 6
0
 public override void OnArrayLiteralExpression(ArrayLiteralExpression node)
 {
     this._currentStatement.Expression = new CodeArrayCreateExpression(BooCodeDomConverter.GetType(node.Type.ElementType.ToCodeString()), node.Items.Select(this.VisitExpr).ToArray());
 }
Exemplo n.º 7
0
 private void VisitMethod(Method node, CodeMemberMethod result)
 {
     result.Name = node.Name;
     this.VisitParameters(node.Parameters, result.Parameters);
     if (node.ReturnType != null)
     {
         result.ReturnType = BooCodeDomConverter.GetType(node.ReturnType.ToCodeString());
     }
     this.OnTypeMember(node, result);
     if (node.Name == "InitializeComponent")
     {
         CodeStatementCollection currentBlock = this._currentBlock;
         this._currentBlock = result.Statements;
         this.Visit(node.Body);
         if (node.ImplementationFlags != 0)
         {
             throw new AssertionFailedException("node.ImplementationFlags == MethodImplementationFlags.None");
         }
         if (node.ExplicitInfo != null)
         {
             throw new AssertionFailedException("node.ExplicitInfo is null");
         }
         this._currentBlock = currentBlock;
     }
     else
     {
         string[] array = node.Body.ToCodeString().Split(new string[3]
         {
             "\r\n",
             "\r",
             "\n"
         }, StringSplitOptions.None);
         int  num   = 1;
         Node node2 = node;
         while (node2.ParentNode != null && RuntimeServices.op_Member(node2.ParentNode.NodeType, new NodeType[2]
         {
             NodeType.ClassDefinition,
             NodeType.StructDefinition
         }))
         {
             num   = checked (num + 1);
             node2 = node2.ParentNode;
         }
         int num2   = 0;
         int length = array.Length;
         if (length < 0)
         {
             throw new ArgumentOutOfRangeException("max");
         }
         while (num2 < length)
         {
             int index = num2;
             num2++;
             string[] array2 = array;
             int      num3   = RuntimeServices.NormalizeArrayIndex(array2, index);
             string   lhs    = new string('\t', num);
             string[] array3 = array;
             array2[num3] = lhs + array3[RuntimeServices.NormalizeArrayIndex(array3, index)];
         }
         string value = string.Join("\r\n", array);
         result.Statements.Add(new CodeSnippetStatement(value));
     }
     this._currentType.Members.Add(result);
 }
Exemplo n.º 8
0
        private void VisitParameters(IEnumerable <ParameterDeclaration> @params, CodeParameterDeclarationExpressionCollection collection)
        {
            IEnumerator <ParameterDeclaration> enumerator = @params.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    ParameterDeclaration current = enumerator.Current;
                    CodeParameterDeclarationExpression codeParameterDeclarationExpression = new CodeParameterDeclarationExpression(BooCodeDomConverter.GetType(current.Type.ToString()), current.Name);
                    if (current.Modifiers == ParameterModifiers.Ref)
                    {
                        codeParameterDeclarationExpression.Direction = FieldDirection.Ref;
                    }
                    this.VisitAttributes(current.Attributes, codeParameterDeclarationExpression.CustomAttributes);
                    collection.Add(codeParameterDeclarationExpression);
                }
            }
            finally
            {
                enumerator.Dispose();
            }
        }
Exemplo n.º 9
0
 public override void OnCastExpression(CastExpression node)
 {
     this._currentStatement.Expression = new CodeCastExpression(BooCodeDomConverter.GetType(node.Type.ToCodeString()), this.VisitExpr(node.Target));
 }