Beispiel #1
0
        internal void SetValue(string propertyName, string value)
        {
            CustomMemberInfo <PropertyInfo> info = inProperty[propertyName];

            if (info != null)
            {
                var formatter = TypeFormatterManager.GetFormatter(info.MemberInfo.PropertyType);
                if (formatter.Format(value, out object convert))
                {
                    SetPropertyValue(propertyName, convert);
                }
            }
        }
Beispiel #2
0
        private static InnerData ParseInnerData(FlowSourceObjectBase source, Type type)
        {
            string summary = "", flowToolTipText = "", flowToolTipTextKey = "", warningKey = "", warning = "";

#if DEBUG
            bool attributeFound = false;
#endif
            var attributes = type.GetCustomAttributes(true);
            foreach (Object attribute in attributes)
            {
                if (attribute is IToolTipText)
                {
                    summary            = ((IToolTipText)attribute).Summary;
                    flowToolTipText    = ((IToolTipText)attribute).Text;
                    flowToolTipTextKey = ((IToolTipText)attribute).TextKey;
#if DEBUG
                    attributeFound = true;
                    if (String.IsNullOrEmpty(flowToolTipText))
                    {
                        Console.WriteLine("[{0}]'s summary is null or empty", type);
                    }
#endif
                }
                else if (attribute is IWarning)
                {
                    warningKey = ((IWarning)attribute).TextKey;
                    warning    = ((IWarning)attribute).Text;
                }
            }

#if DEBUG
            if (!attributeFound)
            {
                Console.WriteLine("[{0}]'s summary is not implemented", type);
            }
#endif

            var inProperty  = new Dictionary <string, CustomMemberInfo <PropertyInfo> >();
            var outProperty = new Dictionary <string, CustomMemberInfo <PropertyInfo> >();
            var methodList  = new Dictionary <string, CustomMemberInfo <MethodInfo> >();
            var eventList   = new Dictionary <string, CustomMemberInfo <EventInfo> >();

            string   toolTipText, toolTipTextKey;
            string[] replacedNames;
            foreach (PropertyInfo propertyinfo in type.GetProperties())
            {
                if (propertyinfo.Name == "Name")
                {
                    continue;
                }
                if (propertyinfo.CanRead && propertyinfo.GetGetMethod() != null && propertyinfo.GetGetMethod().IsPublic)
                {
                    if (CheckAttribute(source, propertyinfo, out toolTipText, out toolTipTextKey, out replacedNames))
                    {
                        outProperty.Add(propertyinfo.Name, new CustomMemberInfo <PropertyInfo>(propertyinfo, toolTipText, toolTipTextKey, replacedNames));
                    }
                }
                if (propertyinfo.CanWrite && propertyinfo.GetSetMethod() != null && propertyinfo.GetSetMethod().IsPublic)
                {
                    if (CheckAttribute(source, propertyinfo, out toolTipText, out toolTipTextKey, out replacedNames))
                    {
                        inProperty.Add(propertyinfo.Name, new CustomMemberInfo <PropertyInfo>(propertyinfo, toolTipText, toolTipTextKey, replacedNames));
                    }
                }
            }
            foreach (MethodInfo methodinfo in type.GetMethods())
            {
                if (methodinfo.IsPublic && !methodinfo.IsAbstract && methodinfo.ReturnType == typeof(void))
                {
                    var parameterinfos = methodinfo.GetParameters();
                    if (parameterinfos.Length == 1 && parameterinfos[0].ParameterType == typeof(FlowEventArgs))
                    {
                        if (CheckAttribute(source, methodinfo, out toolTipText, out toolTipTextKey, out replacedNames))
                        {
                            methodList.Add(methodinfo.Name, new CustomMemberInfo <MethodInfo>(methodinfo, toolTipText, toolTipTextKey, replacedNames));
                        }
                    }
                }
            }
            foreach (EventInfo eventinfo in type.GetEvents())
            {
                if (eventinfo.EventHandlerType == typeof(FlowEventHandler) && eventinfo.GetAddMethod() != null && eventinfo.GetAddMethod().IsPublic &&
                    eventinfo.GetRemoveMethod() != null && eventinfo.GetRemoveMethod().IsPublic)
                {
                    if (CheckAttribute(source, eventinfo, out toolTipText, out toolTipTextKey, out replacedNames))
                    {
                        eventList.Add(eventinfo.Name, new CustomMemberInfo <EventInfo>(eventinfo, toolTipText, toolTipTextKey, replacedNames));
                    }
                }
            }

            // copy to innerlist
            CustomMemberInfo <PropertyInfo>[] inPropertyList = new CustomMemberInfo <PropertyInfo> [inProperty.Count];
            string[] inPropertyNameList = new string[inProperty.Count];
            CustomMemberInfo <PropertyInfo>[] outPropertyList = new CustomMemberInfo <PropertyInfo> [outProperty.Count];
            string[] outPropertyNameList            = new string[outProperty.Count];
            string[] methodNameList                 = new string[methodList.Count];
            CustomMemberInfo <MethodInfo>[] methods = new CustomMemberInfo <MethodInfo> [methodList.Count];
            string[] eventNameList = new string[eventList.Count];
            CustomMemberInfo <EventInfo>[] events = new CustomMemberInfo <EventInfo> [eventList.Count];

            var replacedInPropertyNames  = new Dictionary <string, string>();
            var replacedOutPropertyNames = new Dictionary <string, string>();
            var replacedMethodNames      = new Dictionary <string, string>();
            var replacedEventNames       = new Dictionary <string, string>();
            int iter = 0;
            foreach (string name in inProperty.Keys)
            {
                inPropertyList[iter]     = inProperty[name];
                inPropertyNameList[iter] = name;
                foreach (var replacedName in inPropertyList[iter].ReplacedNames)
                {
                    replacedInPropertyNames[replacedName] = name;
                }
                iter++;
            }
            Array.Sort(inPropertyNameList, inPropertyList, StringComparer.InvariantCulture);

            iter = 0;
            foreach (string name in outProperty.Keys)
            {
                outPropertyList[iter]     = outProperty[name];
                outPropertyNameList[iter] = name;
                foreach (var replacedName in outPropertyList[iter].ReplacedNames)
                {
                    replacedOutPropertyNames[replacedName] = name;
                }
                iter++;
            }
            Array.Sort(outPropertyNameList, outPropertyList, StringComparer.InvariantCulture);

            iter = 0;
            foreach (string name in methodList.Keys)
            {
                methods[iter]        = methodList[name];
                methodNameList[iter] = name;
                foreach (var replacedName in methods[iter].ReplacedNames)
                {
                    replacedMethodNames[replacedName] = name;
                }
                iter++;
            }
            Array.Sort(methodNameList, methods, StringComparer.InvariantCulture);

            iter = 0;
            foreach (string name in eventList.Keys)
            {
                events[iter]        = eventList[name];
                eventNameList[iter] = name;
                foreach (var replacedName in events[iter].ReplacedNames)
                {
                    replacedEventNames[replacedName] = name;
                }
                iter++;
            }
            Array.Sort(eventNameList, events, StringComparer.InvariantCulture);

            return(new InnerData
            {
                EventList = eventList,
                MethodList = methodList,
                InProperty = inProperty,
                OutProperty = outProperty,
                ReplacedEventNames = replacedEventNames,
                ReplacedInPropertyNames = replacedInPropertyNames,
                ReplacedOutPropertyNames = replacedOutPropertyNames,
                ReplacedMethodNames = replacedMethodNames,
                eventList = events,
                eventNameList = eventNameList,
                inPropertyList = inPropertyList,
                inPropertyNameList = inPropertyNameList,
                methodList = methods,
                methodNameList = methodNameList,
                outPropertyList = outPropertyList,
                outPropertyNameList = outPropertyNameList,
                toolTipText = flowToolTipText,
                toolTipTextKey = flowToolTipTextKey,
                summary = summary,
                warningKey = warningKey,
                warning = warning,
                attributes = attributes
            });
        }