Ejemplo n.º 1
0
        /// <summary>
        /// The view is asking for variable names for its intellisense.
        /// </summary>
        /// <param name="o">Fully- or partially-qualified object name for which we want completion options.</param>
        /// <param name="properties">If true, property suggestions will be generated.</param>
        /// <param name="methods">If true, method suggestions will be generated.</param>
        /// <param name="events">If true, event suggestions will be generated.</param>
        /// <returns>List of completion options.</returns>
        private static List <ContextItem> ExamineObjectForContextItems(object o, bool properties, bool methods, bool events)
        {
            List <ContextItem> allItems;
            Type objectType = o is Type ? o as Type : o.GetType();

            allItems = ExamineTypeForContextItems(objectType, properties, methods, events);

            // add in the child models.
            if (o is IModel)
            {
                foreach (IModel model in (o as IModel).Children)
                {
                    if (allItems.Find(m => m.Name == model.Name) == null)
                    {
                        NeedContextItemsArgs.ContextItem item = new NeedContextItemsArgs.ContextItem();
                        item.Name        = model.Name;
                        item.IsProperty  = false;
                        item.IsEvent     = false;
                        item.IsWriteable = false;
                        item.TypeName    = model.GetType().Name;
                        item.Units       = string.Empty;
                        allItems.Add(item);
                    }
                }
                allItems.Sort(delegate(ContextItem c1, ContextItem c2) { return(c1.Name.CompareTo(c2.Name)); });
            }
            return(allItems);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The view is asking for variable names for its intellisense.
        /// </summary>
        public static List<ContextItem> ExamineObjectForContextItems(object o, bool properties, bool methods, bool events)
        {
            List<ContextItem> allItems = ExamineTypeForContextItems(o.GetType(), properties, methods, events);

            // add in the child models.
            if (o != null && o is IModel)
            {
                foreach (IModel model in (o as IModel).Children)
                {
                    if (allItems.Find(m => m.Name == model.Name) == null)
                    {
                        NeedContextItemsArgs.ContextItem item = new NeedContextItemsArgs.ContextItem();
                        item.Name = model.Name;
                        item.IsProperty = false;
                        item.IsEvent = false;
                        item.IsWriteable = false;
                        item.TypeName = model.GetType().Name;
                        item.Units = string.Empty;
                        allItems.Add(item);
                    }
                }

                allItems.Sort(delegate(ContextItem c1, ContextItem c2) { return c1.Name.CompareTo(c2.Name); });
            }
            return allItems;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// The view is asking for variable names for its intellisense.
        /// </summary>
        /// <param name="atype">Data type for which we want completion options.</param>
        /// <param name="properties">If true, property suggestions will be generated.</param>
        /// <param name="methods">If true, method suggestions will be generated.</param>
        /// <param name="events">If true, event suggestions will be generated.</param>
        /// <returns>List of completion options.</returns>
        public static List <ContextItem> ExamineTypeForContextItems(Type atype, bool properties, bool methods, bool events)
        {
            List <ContextItem> allItems = new List <ContextItem>();

            // find the properties and methods
            if (atype != null)
            {
                if (properties)
                {
                    foreach (PropertyInfo property in atype.GetProperties(BindingFlags.Instance | BindingFlags.Public))
                    {
                        VariableProperty var = new VariableProperty(atype, property);
                        NeedContextItemsArgs.ContextItem item = new NeedContextItemsArgs.ContextItem();
                        item.Name        = var.Name;
                        item.IsProperty  = true;
                        item.IsEvent     = false;
                        item.IsWriteable = !var.IsReadOnly;
                        item.TypeName    = var.DataType.Name;
                        item.Descr       = var.Description;
                        item.Units       = var.Units;
                        allItems.Add(item);
                    }
                }

                if (methods)
                {
                    foreach (MethodInfo method in atype.GetMethods(BindingFlags.Instance | BindingFlags.Public))
                    {
                        if (!method.Name.StartsWith("get_") && !method.Name.StartsWith("set_"))
                        {
                            DescriptionAttribute             descriptionAttribute = ReflectionUtilities.GetAttribute(atype, typeof(DescriptionAttribute), false) as DescriptionAttribute;
                            NeedContextItemsArgs.ContextItem item = new NeedContextItemsArgs.ContextItem();
                            item.Name        = method.Name;
                            item.IsProperty  = false;
                            item.IsEvent     = true;
                            item.IsWriteable = false;
                            item.TypeName    = method.ReturnType.Name;
                            if (descriptionAttribute != null)
                            {
                                item.Descr = descriptionAttribute.ToString();
                            }
                            item.Units = string.Empty;

                            // build a parameter string representation
                            ParameterInfo[] allparams = method.GetParameters();
                            StringBuilder   paramText = new StringBuilder("( ");
                            if (allparams.Count() > 0)
                            {
                                for (int p = 0; p < allparams.Count(); p++)
                                {
                                    ParameterInfo parameter = allparams[p];
                                    paramText.Append(parameter.ParameterType.Name + " " + parameter.Name);
                                    if (p < allparams.Count() - 1)
                                    {
                                        paramText.Append(", ");
                                    }
                                }
                            }
                            paramText.Append(" )");
                            item.ParamString = paramText.ToString();

                            allItems.Add(item);
                        }
                    }
                }

                if (events)
                {
                    foreach (EventInfo evnt in atype.GetEvents(BindingFlags.Instance | BindingFlags.Public))
                    {
                        NeedContextItemsArgs.ContextItem item = new NeedContextItemsArgs.ContextItem();
                        item.Name        = evnt.Name;
                        item.IsProperty  = true;
                        item.IsEvent     = true;
                        item.IsWriteable = false;
                        item.TypeName    = evnt.ReflectedType.Name;
                        item.Descr       = "";
                        item.Units       = "";
                        allItems.Add(item);
                    }
                }
            }

            allItems.Sort(delegate(ContextItem c1, ContextItem c2) { return(c1.Name.CompareTo(c2.Name)); });
            return(allItems);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// The view is asking for variable names for its intellisense.
        /// </summary>
        /// <param name="atype">Data type for which we want completion options.</param>
        /// <param name="properties">If true, property suggestions will be generated.</param>
        /// <param name="methods">If true, method suggestions will be generated.</param>
        /// <param name="publishedEvents">If true, published events will be returned.</param>
        /// <param name="subscribedEvents">If true, subscribed events will be returned.</param>
        /// <returns>List of completion options.</returns>
        public static List <ContextItem> ExamineTypeForContextItems(Type atype, bool properties, bool methods, bool publishedEvents, bool subscribedEvents)
        {
            List <ContextItem> allItems = new List <ContextItem>();

            // find the properties and methods
            if (atype != null)
            {
                if (properties)
                {
                    foreach (PropertyInfo property in atype.GetProperties(BindingFlags.Instance | BindingFlags.Public))
                    {
                        VariableProperty var  = new VariableProperty(atype, property);
                        ContextItem      item = new ContextItem
                        {
                            Name        = var.Name,
                            IsProperty  = true,
                            IsEvent     = false,
                            IsWriteable = !var.IsReadOnly,
                            TypeName    = GetTypeName(var.DataType),
                            Descr       = GetDescription(property),
                            Units       = var.Units
                        };
                        allItems.Add(item);
                    }
                }

                if (methods)
                {
                    foreach (MethodInfo method in atype.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy))
                    {
                        if (!method.Name.StartsWith("get_") && !method.Name.StartsWith("set_") &&
                            !method.Name.StartsWith("add_") && !method.Name.StartsWith("remove_"))
                        {
                            ContextItem item = new ContextItem
                            {
                                Name        = method.Name,
                                IsProperty  = false,
                                IsEvent     = false,
                                IsMethod    = true,
                                IsWriteable = false,
                                TypeName    = method.ReturnType.Name,
                                Descr       = GetDescription(method),
                                Units       = string.Empty
                            };

                            // build a parameter string representation
                            ParameterInfo[] allparams = method.GetParameters();
                            StringBuilder   paramText = new StringBuilder("( ");
                            if (allparams.Count() > 0)
                            {
                                for (int p = 0; p < allparams.Count(); p++)
                                {
                                    ParameterInfo parameter = allparams[p];
                                    paramText.Append(parameter.ParameterType.Name + " " + parameter.Name);
                                    if (parameter.DefaultValue != DBNull.Value)
                                    {
                                        paramText.Append(" = " + parameter.DefaultValue?.ToString() ?? "null");
                                    }
                                    if (p < allparams.Count() - 1)
                                    {
                                        paramText.Append(", ");
                                    }
                                }
                            }
                            paramText.Append(" )");
                            item.ParamString = paramText.ToString();

                            allItems.Add(item);
                        }
                    }
                }

                if (publishedEvents)
                {
                    foreach (EventInfo evnt in atype.GetEvents(BindingFlags.Instance | BindingFlags.Public))
                    {
                        NeedContextItemsArgs.ContextItem item = new NeedContextItemsArgs.ContextItem();
                        item.Name        = evnt.Name;
                        item.IsProperty  = true;
                        item.IsEvent     = true;
                        item.IsMethod    = false;
                        item.IsWriteable = false;
                        item.TypeName    = evnt.ReflectedType.Name;
                        item.Descr       = GetDescription(evnt);
                        item.Units       = "";
                        allItems.Add(item);
                    }
                }

                if (subscribedEvents)
                {
                    foreach (MethodInfo method in atype.GetMethods(/*BindingFlags.Instance |*/ BindingFlags.NonPublic | BindingFlags.FlattenHierarchy))
                    {
                        EventSubscribeAttribute subscriberAttribute = (EventSubscribeAttribute)ReflectionUtilities.GetAttribute(method, typeof(EventSubscribeAttribute), false);
                        if (subscriberAttribute != null)
                        {
                            NeedContextItemsArgs.ContextItem item = new NeedContextItemsArgs.ContextItem();
                            item.Name        = subscriberAttribute.ToString();
                            item.IsProperty  = false;
                            item.IsEvent     = false;
                            item.IsMethod    = true;
                            item.IsWriteable = false;
                            item.TypeName    = atype.Name;
                            item.Descr       = GetDescription(atype);
                            item.Units       = "";
                            allItems.Add(item);
                        }
                    }
                }
            }

            allItems.Sort(delegate(ContextItem c1, ContextItem c2) { return(c1.Name.CompareTo(c2.Name)); });
            return(allItems);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// The view is asking for variable names for its intellisense.
        /// </summary>
        public static List<ContextItem> ExamineTypeForContextItems(Type atype, bool properties, bool methods, bool events)
        {
            List<ContextItem> allItems = new List<ContextItem>();

            // find the properties and methods
            if (atype != null)
            {
                if (properties)
                {
                    foreach (PropertyInfo property in atype.GetProperties(BindingFlags.Instance | BindingFlags.Public))
                    {
                        VariableProperty var = new VariableProperty(atype, property);
                        NeedContextItemsArgs.ContextItem item = new NeedContextItemsArgs.ContextItem();
                        item.Name = var.Name;
                        item.IsProperty = true;
                        item.IsEvent = false;
                        item.IsWriteable = !var.IsReadOnly;
                        item.TypeName = var.DataType.Name;
                        item.Descr = var.Description;
                        item.Units = var.Units;
                        allItems.Add(item);
                    }
                }

                if (methods)
                {
                    foreach (MethodInfo method in atype.GetMethods(BindingFlags.Instance | BindingFlags.Public))
                    {
                        if (!method.Name.StartsWith("get_") && !method.Name.StartsWith("set_"))
                        {
                            DescriptionAttribute descriptionAttribute = ReflectionUtilities.GetAttribute(atype, typeof(DescriptionAttribute), false) as DescriptionAttribute;
                            NeedContextItemsArgs.ContextItem item = new NeedContextItemsArgs.ContextItem();
                            item.Name = method.Name;
                            item.IsProperty = false;
                            item.IsEvent = true;
                            item.IsWriteable = false;
                            item.TypeName = method.ReturnType.Name;
                            if (descriptionAttribute != null)
                                item.Descr = descriptionAttribute.ToString();
                            item.Units = string.Empty;

                            // build a parameter string representation
                            ParameterInfo[] allparams = method.GetParameters();
                            StringBuilder paramText = new StringBuilder("( ");
                            if (allparams.Count() > 0)
                            {
                                for (int p = 0; p < allparams.Count(); p++)
                                {
                                    ParameterInfo parameter = allparams[p];
                                    paramText.Append(parameter.ParameterType.Name + " " + parameter.Name);
                                    if (p < allparams.Count() - 1)
                                        paramText.Append(", ");
                                }
                            }
                            paramText.Append(" )");
                            item.ParamString = paramText.ToString();

                            allItems.Add(item);
                        }
                    }
                }

                if (events)
                {
                    foreach (EventInfo evnt in atype.GetEvents(BindingFlags.Instance | BindingFlags.Public))
                    {
                        NeedContextItemsArgs.ContextItem item = new NeedContextItemsArgs.ContextItem();
                        item.Name = evnt.Name;
                        item.IsProperty = true;
                        item.IsEvent = true;
                        item.IsWriteable = false;
                        item.TypeName = evnt.ReflectedType.Name;
                        item.Descr = "";
                        item.Units = "";
                        allItems.Add(item);
                    }
                }
            }

            allItems.Sort(delegate(ContextItem c1, ContextItem c2) { return c1.Name.CompareTo(c2.Name); });
            return allItems;
        }