Exemple #1
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            List <byte> blob = new List <byte>();

            blob.Add(0x01);
            blob.Add(0x00);
            ParameterInfo[] parameters = m_ctor.GetParameters();
            for (int i = 0; i < parameters.Length; i++)
            {
                Type   type = parameters[i].ParameterType;
                string value;
                if (m_parameterControlList[i] is ComboBox)
                {
                    value = (m_parameterControlList[i] as ComboBox).SelectedItem.ToString();
                }
                else
                {
                    value = m_parameterControlList[i].Text;
                }
                if (!AddBlob(blob, type, value))
                {
                    MessageBox.Show(Resource.FormatString("Wrn_BadParameterInput", value, type.ToString()));
                    return;
                }
            }
            AppendNumNamedArgs(blob, 0);

            m_data = AddAttributeAction.GetStringByBlob(blob.ToArray());

            DialogResult = DialogResult.OK;
            Dispose();
        }
Exemple #2
0
        private void ParseData()
        {
            byte[] blob;
            int    index = 0;

            if (AddAttributeAction.GetBlobByString(m_data, out blob))
            {
                // skip 01 00
                index += 2;
                ParameterInfo[] parameters = m_ctor.GetParameters();
                for (int i = 0; i < parameters.Length; i++)
                {
                    Type   type  = parameters[i].ParameterType;
                    string value = GetValue(blob, ref index, type);
                    if (m_parameterControlList[i] is ComboBox)
                    {
                        (m_parameterControlList[i] as ComboBox).SelectedItem = value;
                    }
                    else
                    {
                        m_parameterControlList[i].Text = value;
                    }
                }
            }
            else
            {
                throw new ParseDataFailedException();
            }
        }
Exemple #3
0
        public AddAttributeActionWizard(AddAttributeAction fixedAddAttributeAction)
        {
            InitializeComponent();
            if (fixedAddAttributeAction != null)
            {
                m_fixedAddAttributeAction = fixedAddAttributeAction;

                m_assembly          = m_fixedAddAttributeAction.AssemblyName;
                m_selectedAttribute = m_fixedAddAttributeAction.TypeName;
                m_ctor  = m_fixedAddAttributeAction.Constructor;
                m_value = m_fixedAddAttributeAction.Data;
            }
        }
        protected void DefineType(ConverterInfo info, TypeInfo typeInfo, bool dealWithAlias)
        {
            m_info     = info;
            m_typeInfo = typeInfo;

            if (dealWithAlias)
            {
                m_nonAliasedTypeInfo = ConvCommon.GetAlias(typeInfo);
            }
            else
            {
                m_nonAliasedTypeInfo = typeInfo;
            }

            try
            {
                OnDefineType();

                //
                // Emit SuppressUnmanagedCodeSecurityAttribute for /unsafe switch
                //
                if ((m_info.Settings.m_flags & TypeLibImporterFlags.UnsafeInterfaces) != 0)
                {
                    if (ConvType != ConvType.ClassInterface && ConvType != ConvType.EventInterface)
                    {
                        m_typeBuilder.SetCustomAttribute(CustomAttributeHelper.GetBuilderForSuppressUnmanagedCodeSecurity());
                    }
                }

                // Rule Engine AddAttributeAction
                if (m_info.Settings.m_ruleSet != null)
                {
                    ICategory           category = TypeCategory.GetInstance();
                    TypeInfoMatchTarget target   = null;
                    using (TypeAttr attr = m_typeInfo.GetTypeAttr())
                    {
                        TypeLibTypes.Interop.TYPEKIND kind = attr.typekind;
                        target = new TypeInfoMatchTarget(m_typeInfo.GetContainingTypeLib(), m_typeInfo, kind);
                    }
                    AbstractActionManager actionManager     = RuleEngine.GetActionManager();
                    List <Rule>           addAttributeRules = m_info.Settings.m_ruleSet.GetRule(
                        category, AddAttributeActionDef.GetInstance(), target);
                    foreach (Rule rule in addAttributeRules)
                    {
                        AddAttributeAction addAttributeAction = rule.Action as AddAttributeAction;
                        ConstructorInfo    attributeCtor;
                        byte[]             blob;
                        bool success = true;
                        if (addAttributeAction.GetCustomAttribute(out attributeCtor, out blob))
                        {
                            try
                            {
                                m_typeBuilder.SetCustomAttribute(attributeCtor, blob);
                            }
                            catch (Exception)
                            {
                                success = false;
                            }
                        }
                        else
                        {
                            success = false;
                        }
                        if (!success)
                        {
                            string name = m_typeInfo.GetDocumentation();
                            string msg  = Resource.FormatString("Wrn_AddCustomAttributeFailed",
                                                                addAttributeAction.TypeName, name);
                            m_info.ReportEvent(WarningCode.Wrn_AddCustomAttributeFailed, msg);
                        }
                    }
                }
            }
            catch (ReflectionTypeLoadException)
            {
                throw; // Fatal failure. Throw
            }
            catch (TlbImpResolveRefFailWrapperException)
            {
                throw; // Fatal failure. Throw
            }
            catch (TlbImpGeneralException)
            {
                throw; // Fatal failure. Throw
            }
            catch (Exception)
            {
                string name = String.Empty;
                if (m_typeInfo != null)
                {
                    try
                    {
                        name = m_typeInfo.GetDocumentation();
                    }
                    catch (Exception)
                    {
                    }
                }

                if (name != String.Empty)
                {
                    string msg = Resource.FormatString("Wrn_InvalidTypeInfo", name);
                    m_info.ReportEvent(WarningCode.Wrn_InvalidTypeInfo, msg);
                }
                else
                {
                    string msg = Resource.FormatString("Wrn_InvalidTypeInfo_Unnamed");
                    m_info.ReportEvent(WarningCode.Wrn_InvalidTypeInfo_Unnamed, msg);
                }

                // When failure, try to create the type anyway
                if (m_typeBuilder != null)
                {
                    m_type = m_typeBuilder.CreateType();
                }
            }
        }