Esempio n. 1
0
 /// <summary>
 /// Adds the given properties to the given type.
 /// </summary>
 /// <param name="type">The entity to add the properties to.</param>
 /// <param name="properties">A list of properties to add.</param>
 private void AddProperties(CompositeType type, IEnumerable <NRProperty> properties)
 {
     foreach (NRProperty nrProperty in properties)
     {
         type.AddProperty().InitFromDeclaration(new NRPropertyDeclaration(nrProperty));
     }
 }
Esempio n. 2
0
 /// <summary>
 ///     Adds the given properties to the given type.
 /// </summary>
 /// <param name="type">The entity to add the properties to.</param>
 /// <param name="properties">A list of properties to add.</param>
 private void AddProperties(CompositeType type, IEnumerable <NRProperty> properties)
 {
     foreach (var nrProperty in properties)
     {
         type.AddProperty().InitFromString(nrProperty.Declaration());
     }
 }
Esempio n. 3
0
 private void toolNewProperty_Click(object sender, EventArgs e)
 {
     if (parent.SupportsProperties)
     {
         Property property = parent.AddProperty();
         AddNewOperation(property);
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Adds the given properties to the given type.
        /// </summary>
        /// <param name="type">The entity to add the fields to.</param>
        /// <param name="tp">.</param>
        private void AddProperties(CompositeType type, TypeDeclaration tp)
        {
            foreach (PropertyDeclaration pp in tp.Descendants.OfType <PropertyDeclaration>())
            {
                Property prop = type.AddProperty();

                prop.Name           = pp.Name;
                prop.AccessModifier = pp.Modifiers.ToEnClass();;
                prop.Type           = pp.ReturnType.ToString();
            }
        }
Esempio n. 5
0
        private void toolNewProperty_Click(object sender, EventArgs e)
        {
            if (parent.SupportsProperties)
            {
                Property     property = parent.AddProperty();
                ListViewItem item     = AddOperationToList(property);

                OnContentsChanged(EventArgs.Empty);
                item.Focused  = true;
                item.Selected = true;
                txtName.SelectAll();
                txtName.Focus();
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Reflects all operations within the type <paramref name="xType"/>. Reflected
        /// operations are added to <paramref name="xOpContainer"/>.
        /// </summary>
        /// <param name="xType">The operations are taken from this type.</param>
        /// <param name="xOpContainer">Reflected operations are added to this OperationContainer.</param>
        private void ReflectOperations(Type xType, CompositeType xOpContainer)
        {
            #region --- Properties

            PropertyInfo[] axProperties     = xType.GetProperties(xStandardBindingFlags);
            List <string>  astPropertyNames = new List <string>();
            foreach (PropertyInfo xProperty in axProperties)
            {
                //Don't display derived Methods
                if (xProperty.DeclaringType != xType)
                {
                    continue;
                }

                astPropertyNames.Add(xProperty.Name);
                StringBuilder stDeclaration = new StringBuilder();
                //The access modifier for a property isn't stored at the property.
                //We have to use the access modifier from the corresponding get_XXX /
                //set_XXX Method.
                //Well - that's not the whole truth... It's possible to create a
                //public property with a private set method. But there could be also
                //a private property with a public get method. There's no way to get
                //this information back from the assembly.
                //Solution (for now): Take the first found access modifier as the
                // property access modifier.
                ParameterInfo[] axIndexParameter = xProperty.GetIndexParameters();
                //get_XXX and set_XXX might be overloaded, so we have to specify the
                //index parameters as well.
                Type[] axGetIndexParamTypes = new Type[axIndexParameter.Length];
                Type[] axSetIndexParamTypes = new Type[axIndexParameter.Length + 1];
                for (int i = 0; i < axIndexParameter.Length; i++)
                {
                    axGetIndexParamTypes[i] = axIndexParameter[i].ParameterType;
                    axSetIndexParamTypes[i] = axIndexParameter[i].ParameterType;
                }
                axSetIndexParamTypes[axSetIndexParamTypes.Length - 1] = xProperty.PropertyType;
                string     stGetMethodName = xProperty.Name.Insert(xProperty.Name.LastIndexOf('.') + 1, "get_");
                string     stSetMethodName = xProperty.Name.Insert(xProperty.Name.LastIndexOf('.') + 1, "set_");
                MethodInfo xGetMethod      = xType.GetMethod(stGetMethodName, xStandardBindingFlags, null, axGetIndexParamTypes, null); //, xStandardBindingFlags);
                MethodInfo xSetMethod      = xType.GetMethod(stSetMethodName, xStandardBindingFlags, null, axSetIndexParamTypes, null); //, xStandardBindingFlags);

                //If one of the access methods (get_XXX or set_XXX) should be importet
                //import the property.
                if (!((xProperty.CanRead && xImportSettings.CheckImportProperty(xGetMethod)) ||
                      (xProperty.CanWrite && xImportSettings.CheckImportProperty(xSetMethod))))
                {
                    continue;
                }
                if (!(xOpContainer is InterfaceType))
                {
                    if (xProperty.CanRead)
                    {
                        stDeclaration.Append(GetMethodAccessModifierString(xGetMethod));
                        stDeclaration.AppendFormat(" {0}", GetOperationModifierString(xGetMethod));
                        ChangeOperationModifierIfOverwritten(xType, xGetMethod, stDeclaration);
                    }
                    else
                    {
                        stDeclaration.Append(GetMethodAccessModifierString(xSetMethod));
                        stDeclaration.AppendFormat(" {0}", GetOperationModifierString(xSetMethod));
                        ChangeOperationModifierIfOverwritten(xType, xSetMethod, stDeclaration);
                    }
                }
                stDeclaration.AppendFormat(" {0}", GetTypeName(xProperty.PropertyType));
                //Is this an Item-property (public int this[int i])
                if (axIndexParameter.Length > 0)
                {
                    stDeclaration.Append(" this[");
                    foreach (ParameterInfo xParameter in axIndexParameter)
                    {
                        stDeclaration.AppendFormat("{0} ", GetTypeName(xParameter.ParameterType));
                        stDeclaration.AppendFormat("{0}, ", xParameter.Name);
                    }
                    //Get rid of the last ", "
                    stDeclaration.Length -= 2;
                    stDeclaration.Append("]");
                }
                else
                {
                    stDeclaration.AppendFormat(" {0}", xProperty.Name);
                }
                stDeclaration.AppendFormat(" {0}", "{");
                if (xProperty.CanRead)
                {
                    stDeclaration.AppendFormat(" {0}", "get;");
                    if (xProperty.CanWrite)
                    {
                        if (!stDeclaration.ToString().StartsWith(GetMethodAccessModifierString(xSetMethod)) && !(xOpContainer is InterfaceType))
                        {
                            //! set has a different access modifier
                            stDeclaration.AppendFormat(" {0}", GetMethodAccessModifierString(xSetMethod));
                        }
                        stDeclaration.AppendFormat(" {0}", "set;");
                    }
                }
                else
                {
                    //! Only set, so don't care about access modifier
                    stDeclaration.AppendFormat(" {0}", "set;");
                }
                stDeclaration.AppendFormat(" {0}", "}");

                Property xNewProperty = xOpContainer.AddProperty();
                xNewProperty.InitFromString(stDeclaration.ToString());
            }

            #endregion

            #region --- Methods

            MethodInfo[] axMethods = xType.GetMethods(xStandardBindingFlags);
            foreach (MethodInfo xMethod in axMethods)
            {
                //Don't display derived Methods
                if (xMethod.DeclaringType != xType)
                {
                    continue;
                }

                if (!xImportSettings.CheckImportMethod(xMethod))
                {
                    continue;
                }

                //There are sometimes some magic methods like '<.ctor>b__0'. Those
                //methods are generated by the compiler and shouldn't be importet.
                //Those methods have an attribute CompilerGeneratedAttribute.
                if (xMethod.GetCustomAttributes(typeof(CompilerGeneratedAttribute), true).Length > 0)
                {
                    continue;
                }

                //We store the method name here so it is much easier to take care about operators
                string stMethodName    = xMethod.Name;
                bool   boAddReturnType = true;
                if (xMethod.IsSpecialName)
                {
                    //SpecialName means that this method is an automaticaly generated
                    //method. This can be get_XXX and set_XXX for properties or
                    //add_XXX and remove_XXX for events. There are also special name
                    //methods starting with op_ for operators.
                    if (!xMethod.Name.StartsWith("op_"))
                    {
                        continue;
                    }
                    //!xMethod.Name starts witch 'op_' and so it is an operator. We
                    //have to get the 'real' method name here.
                    if (dstOperatorMethodsMap.ContainsKey(stMethodName))
                    {
                        stMethodName = dstOperatorMethodsMap[stMethodName];
                    }

                    if (stMethodName == "op_Implicit")
                    {
                        stMethodName    = "implicit operator " + GetTypeName(xMethod.ReturnType);
                        boAddReturnType = false;
                    }
                    else if (stMethodName == "op_Explicit")
                    {
                        stMethodName    = "explicit operator " + GetTypeName(xMethod.ReturnType);
                        boAddReturnType = false;
                    }
                }

                Method        xNewMethod    = (Method)xOpContainer.AddMethod();
                StringBuilder stDeclaration = new StringBuilder();

                if (!(xOpContainer is InterfaceType))
                {
                    stDeclaration.AppendFormat("{0} ", GetMethodAccessModifierString(xMethod));
                    stDeclaration.AppendFormat("{0} ", GetOperationModifierString(xMethod));
                }

                ChangeOperationModifierIfOverwritten(xType, xMethod, stDeclaration);

                if (boAddReturnType)
                {
                    stDeclaration.AppendFormat("{0} ", GetTypeName(xMethod.ReturnType));
                }
                stDeclaration.AppendFormat("{0}", stMethodName);

                stDeclaration.AppendFormat("{0}", GetParameterDeclarationString(xMethod));

                xNewMethod.InitFromString(stDeclaration.ToString());
            }

            #endregion

            #region --- Constructors

            if (xOpContainer.SupportsConstuctors)
            {
                ConstructorInfo[] axConstructors = xType.GetConstructors(xStandardBindingFlags);
                foreach (ConstructorInfo xConstructor in axConstructors)
                {
                    if (!xImportSettings.CheckImportConstructor(xConstructor))
                    {
                        continue;
                    }
                    Method        xNewConstructor = xOpContainer.AddConstructor();
                    StringBuilder stDeclaration   = new StringBuilder();
                    stDeclaration.AppendFormat("{0} ", GetMethodAccessModifierString(xConstructor));
                    stDeclaration.AppendFormat("{0}", xConstructor.IsStatic ? "static " : "");
                    stDeclaration.Append(xOpContainer.Name); //xOpContainer.Name since the name of the class/struct/... isn't set yet

                    stDeclaration.AppendFormat("{0}", GetParameterDeclarationString(xConstructor));
                    xNewConstructor.InitFromString(stDeclaration.ToString());
                }
            }

            #endregion

            ReflectTypeBase(xType, (TypeBase)xOpContainer);
        }