public override void Exec(vsCommandExecOption executeOption, ref object varIn, ref object varOut)
        {
            CodeFunction2 currentMethod = CodeModelUtils.GetCurrentMethod(m_application);
            if (IsCommandAvailable(currentMethod))
            {
                try
                {
                    ConversionCodeGenerator codeGenerator = new ConversionCodeGenerator();

                    CodeParameter2 param = currentMethod.Parameters.Item(1) as CodeParameter2;

                    ArrayList toProperties;
                    ArrayList fromProperties;

                    try
                    {
                        toProperties = CodeModelUtils.GetPropertiesFromType(currentMethod.Type.CodeType);
                    }
                    catch (NotImplementedException)
                    {
                        throw new Exception("Method return type '" + currentMethod.Type.AsString + "' could not be resolved.");
                    }

                    try
                    {
                        fromProperties = CodeModelUtils.GetPropertiesFromType(param.Type.CodeType);
                    }
                    catch (NotImplementedException)
                    {
                        throw new Exception("Method parameter type '" + param.Type.AsString + "' could not be resolved.");
                    }

                    foreach (CodeProperty toProperty in toProperties)
                    {
                        bool mapped = false;
                        string toName = toProperty.Name;
                        string toNameNoDots = toName.Replace(".", string.Empty);
                        string toType = toProperty.Type.AsFullName;

                        foreach (CodeProperty fromProperty in fromProperties)
                        {
                            string fromName = fromProperty.Name;
                            string fromNameNoDots = fromName.Replace(".", string.Empty);
                            if (fromName == toName || fromName == toNameNoDots || fromNameNoDots == toNameNoDots)
                            {
                                string fromType = fromProperty.Type.AsFullName;
                                if (fromType.Replace("?", string.Empty) == toType.Replace("?", string.Empty))
                                {
                                    codeGenerator.AddProperty(toName, toType, fromName, fromType);
                                    mapped = true;
                                    break;
                                }
                            }
                        }

                        if (!mapped)
                        {
                            codeGenerator.AddProperty(toName, toType);
                        }
                    }

                    AddInUtils.InsertCodeInMethod(currentMethod, codeGenerator.GenerateCode(currentMethod));

                    m_application.StatusBar.Text = "Android/VS: Code inserted";
                }
                catch(Exception e)
                {
                    m_application.StatusBar.Text = "Android/VS: Unable to insert code: " + e.Message;
                    m_application.StatusBar.Highlight(true);
                }
            }
            else
            {
                m_application.StatusBar.Text = "Android/VS: Unable to insert code";
            }
        }
示例#2
0
        public override void Exec(vsCommandExecOption executeOption, ref object varIn, ref object varOut)
        {
            CodeFunction2 currentMethod = CodeModelUtils.GetCurrentMethod(m_application);

            if (IsCommandAvailable(currentMethod))
            {
                try
                {
                    ConversionCodeGenerator codeGenerator = new ConversionCodeGenerator();

                    CodeParameter2 param = currentMethod.Parameters.Item(1) as CodeParameter2;

                    ArrayList toProperties;
                    ArrayList fromProperties;

                    try
                    {
                        toProperties = CodeModelUtils.GetPropertiesFromType(currentMethod.Type.CodeType);
                    }
                    catch (NotImplementedException)
                    {
                        throw new Exception("Method return type '" + currentMethod.Type.AsString + "' could not be resolved.");
                    }

                    try
                    {
                        fromProperties = CodeModelUtils.GetPropertiesFromType(param.Type.CodeType);
                    }
                    catch (NotImplementedException)
                    {
                        throw new Exception("Method parameter type '" + param.Type.AsString + "' could not be resolved.");
                    }

                    foreach (CodeProperty toProperty in toProperties)
                    {
                        bool   mapped       = false;
                        string toName       = toProperty.Name;
                        string toNameNoDots = toName.Replace(".", string.Empty);
                        string toType       = toProperty.Type.AsFullName;

                        foreach (CodeProperty fromProperty in fromProperties)
                        {
                            string fromName       = fromProperty.Name;
                            string fromNameNoDots = fromName.Replace(".", string.Empty);
                            if (fromName == toName || fromName == toNameNoDots || fromNameNoDots == toNameNoDots)
                            {
                                string fromType = fromProperty.Type.AsFullName;
                                if (fromType.Replace("?", string.Empty) == toType.Replace("?", string.Empty))
                                {
                                    codeGenerator.AddProperty(toName, toType, fromName, fromType);
                                    mapped = true;
                                    break;
                                }
                            }
                        }

                        if (!mapped)
                        {
                            codeGenerator.AddProperty(toName, toType);
                        }
                    }

                    AddInUtils.InsertCodeInMethod(currentMethod, codeGenerator.GenerateCode(currentMethod));

                    m_application.StatusBar.Text = "Android/VS: Code inserted";
                }
                catch (Exception e)
                {
                    m_application.StatusBar.Text = "Android/VS: Unable to insert code: " + e.Message;
                    m_application.StatusBar.Highlight(true);
                }
            }
            else
            {
                m_application.StatusBar.Text = "Android/VS: Unable to insert code";
            }
        }