Beispiel #1
0
        private bool mbAllowPromoteFromMetadata = false; //add this to hl?


        private HighLevelProperty GetHighLevelProperty(INamedTypedProperty b, string parentTypeName)
        {
            HighLevelProperty p = null;

            if (false)
            {
            }
            else if (b.MetaData.ContainsKey("ComplexType") == true)
            {
                p = new ComplexTypeProperty(b);
            }
            else if (mbAllowPromoteFromMetadata == true /* && has promotable metadata??? */)
            {
            }
            else if (mSpecificTypeEditor.ContainsKey(parentTypeName) && mSpecificTypeEditor[parentTypeName].ContainsKey(b.GetName()))
            {
                p = (HighLevelProperty)(mSpecificTypeEditor[parentTypeName][b.GetName()].GetConstructor(new Type[] { typeof(INamedTypedProperty) }).Invoke(new object[] { b }));
            }
            else if (mInternalTypeEditors.ContainsKey(b.GetTypeName()) == true)
            {
                p = (HighLevelProperty)(mInternalTypeEditors[b.GetTypeName()].GetConstructor(new Type[] { typeof(INamedTypedProperty) }).Invoke(new object[] { b }));
            }
            else if (b.MetaData.ContainsKey("BaseType") && mBaseTypeEditors.ContainsKey(b.MetaData["BaseType"].ToString()))
            {
                string baseTypeName = b.MetaData["BaseType"] as string;
                p = (HighLevelProperty)(mBaseTypeEditors[baseTypeName].GetConstructor(new Type[] { typeof(INamedTypedProperty) }).Invoke(new object[] { b }));
            }
            //   //is this good???
            //else if (b.MetaData.ContainsKey("BaseType") && mInternalTypeEditors.ContainsKey(b.MetaData["BaseType"].ToString()))
            //{
            //   string baseTypeName = b.MetaData["BaseType"] as string;
            //   p = (HighLevelProperty)(mInternalTypeEditors[baseTypeName].GetConstructor(new Type[] { typeof(INamedTypedProperty) }).Invoke(new object[] { b }));
            //}
            else //default
            {
                p = new HighLevelProperty(b);
            }
            return(p);
        }
Beispiel #2
0
        public IEnumerable<ComplexTypeProperty> GetKnownProperties(string typeName)
        {
            if (!string.IsNullOrWhiteSpace(typeName))
            {
                // Remove the List<> if exists
                typeName = typeName.Replace("List<", "").Replace(">", "");

                // Check if the type matches a ParsedClass
                var parsedClass = _cachedTypes.ProjectClasses
                                              .FirstOrDefault(x => string.Concat(x.Namespace, ".", x.Name).Equals(typeName, StringComparison.OrdinalIgnoreCase));
                if (parsedClass != null)
                {
                    return parsedClass.ParsedProperties
                                      .Select(x =>
                                      {
                                          var toReturn = new ComplexTypeProperty
                                          {
                                              Name = x.Name,
                                              Type = x.Type.Name,
                                          };

                                          toReturn.Attributes.AddRange(x.Attributes);

                                          return toReturn;
                                      })
                                      .ToArray();
                }
                else
                {

                    var foundType = _cachedTypes.AssemblyClasses
                        .FirstOrDefault(x => x.FullName.Equals(typeName, StringComparison.OrdinalIgnoreCase));

                    if (foundType != null)
                    {
                        List<ComplexTypeProperty> toReturn = new List<ComplexTypeProperty>();

                        foreach (var field in foundType.GetFields().Where(
                            (f) =>
                            {
                                return f.IsStatic == false && f.IsPublic == true;
                            }))
                        {
                            ComplexTypeProperty toAdd = new ComplexTypeProperty();
                            toAdd.Name = field.Name;
                            toAdd.Type = field.FieldType.Name;
                            toReturn.Add(toAdd);
                        }

                        foreach (var property in foundType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
                        {
                            var found = property.GetCustomAttributes(typeof(BrowsableAttribute), true);
                            bool shouldSkip = false;
                            foreach (BrowsableAttribute attribute in found)
                            {
                                if (attribute != null && attribute.Browsable == false)
                                {
                                    shouldSkip = true;
                                }
                            }
                            if (shouldSkip == false)
                            {
                                ComplexTypeProperty toAdd = new ComplexTypeProperty();

                                toAdd.Name = property.Name;
                                toAdd.Type = property.PropertyType.Name;
                                toReturn.Add(toAdd);
                            }
                        }

                        return toReturn;

                    }
                }
            }

            return new ComplexTypeProperty[0];
        }
        private void IncludeComplexProperty(ComplexTypeProperty property)
        {
            string propertyName = property.Name;
            if (!string.IsNullOrWhiteSpace(property.Type))
            {
                propertyName = string.Concat(propertyName, " (", property.Type, ")");
            }

            // Setup events
            Func<object> getter = () => property.Value;
            MemberChangeEventHandler setter = (sender, args) =>
            {
                property.Value = args.Value as string;
                CallOnUpdate();
            };

            // Setup type converter
            var knownValues = _csvData.GetKnownValuesForType(property.Type);
            TypeConverter converter = null;
            var enumerable = knownValues as string[] ?? knownValues.ToArray();
            if (enumerable.Any())
            {
                converter = new AvailableKnownValuesTypeConverter(enumerable);
            }

            IncludeMember(propertyName, typeof(string), setter, getter, converter, new Attribute[] { mPropertyCategory });
        }