Exemple #1
0
 public static void Register()
 {
     foreach (var type in NumericValueParser.Types)
     {
         TypeDescriptor.AddProvider(new NumericTypeDescriptionProvider(type, TypeDescriptor.GetProvider(type)), type);
     }
 }
Exemple #2
0
        private void EditSettingsProperties(object _settings)
        {
            var lang        = WinFormsTranslator.CurrentLanguage;
            var translation = WinFormsTranslator.GetContext(lang);
            var ctd         = new PropertyOverridingTypeDescriptor(TypeDescriptor.GetProvider(_settings).GetTypeDescriptor(_settings));

            foreach (var pd in TypeDescriptor.GetProperties(_settings).OfType <PropertyDescriptor>())
            {
                var s = Array.Find(settings, z => z.SettingName == pd.Name);
                if (s == null)
                {
                    continue;
                }

                var desc = "Property Description needs to be defined. Please raise this issue on GitHub or at the discord: https://discord.gg/tDMvSRv";
                if (s.Description != null)
                {
                    desc = translation.GetTranslatedText($"{s.SettingName}_description", s.Description);
                }

                var category = "Uncategorized Settings";
                if (s.Category != null)
                {
                    category = translation.GetTranslatedText($"{s.SettingName}_category", s.Category);
                }

                PropertyDescriptor pd2 = TypeDescriptor.CreateProperty(_settings.GetType(), pd, new DescriptionAttribute(desc), new CategoryAttribute(category));
                ctd.OverrideProperty(pd2);
            }
            TypeDescriptor.AddProvider(new TypeDescriptorOverridingProvider(ctd), _settings);
        }
        /// <summary>
        /// Constructor
        /// </summary>
        public PropertyPanel(DockingContainer container) : base(container)
        {
            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();

            // TODO: Add any initialization after the InitializeComponent call

            // configure the propertygrid refresh timer
            _refreshTimer.AutoReset = false;
            _refreshTimer.Elapsed  += new ElapsedEventHandler(OnRefresh);
            _refreshTimer.Interval  = 200;
            _refreshTimer.Enabled   = false;

            // Note that this is a global setter (it should be called once) that will work for all property grids.
            // It is set here as we only have one property grid in the code but it could be considered to move the call to a global settings location.
            SingleTypeDescriptionProvider propertyGridSingleProvider = new SingleTypeDescriptionProvider(TypeDescriptor.GetProvider(typeof(Single)));

            TypeDescriptor.AddProvider(propertyGridSingleProvider, typeof(Single));

            // listen to the changes
            EditorScene.PropertyChanged       += new CSharpFramework.PropertyChangedEventHandler(this.OnPropertyChanged);
            EditorManager.SceneChanged        += new SceneChangedEventHandler(this.OnSceneChanged);
            EditorScene.ShapeChanged          += new ShapeChangedEventHandler(this.OnShapeChanged);
            EditorScene.LayerChanged          += new LayerChangedEventHandler(this.OnLayerChanged);
            EditorScene.ZoneChanged           += new ZoneChangedEventHandler(EditorScene_ZoneChanged);
            propertyGrid.PropertyValueChanged += new PropertyValueChangedEventHandler(propertyGrid_PropertyValueChanged);

            EditorManager.ShapeSelectionChanged += new ShapeSelectionChangedEventHandler(OnSelectionChanged);

            UpdateHelpPanel();
        }
        internal static void MakePropertiesReadOnly(IServiceProvider serviceProvider, object topComponent)
        {
            Hashtable hashtable = new Hashtable();
            Queue     queue     = new Queue();

            queue.Enqueue(topComponent);
            while (queue.Count > 0)
            {
                object instance = queue.Dequeue();
                if (hashtable[instance.GetHashCode()] == null)
                {
                    hashtable[instance.GetHashCode()] = instance;
                    TypeDescriptor.AddProvider(new ReadonlyTypeDescriptonProvider(TypeDescriptor.GetProvider(instance)), instance);
                    foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(instance, new Attribute[] { BrowsableAttribute.Yes }))
                    {
                        if (!descriptor.PropertyType.IsPrimitive)
                        {
                            object component = descriptor.GetValue(instance);
                            if (component != null)
                            {
                                TypeConverter converter = TypeDescriptor.GetConverter(component);
                                System.Workflow.ComponentModel.Design.TypeDescriptorContext context = new System.Workflow.ComponentModel.Design.TypeDescriptorContext(serviceProvider, descriptor, instance);
                                if (converter.GetPropertiesSupported(context))
                                {
                                    TypeDescriptor.AddProvider(new ReadonlyTypeDescriptonProvider(TypeDescriptor.GetProvider(component)), component);
                                    queue.Enqueue(component);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #5
0
        static void SettingLight <T>() where T : SettingLightDirect
        {
            List <PropertyAdditionalAttributes> list = new List <PropertyAdditionalAttributes>();

            list.Add(new PropertyAdditionalAttributes
            {
                PropertyName = "LightPosition",
                PropertyType = typeof(Vector3D),
                Attributes   = new Attribute[] {
                    new EditorAttribute(typeof(VectorEditor), typeof(UITypeEditor)),
                    new RangeAttribute(-10, 10, 0.1)
                }
            });
            list.Add(new PropertyAdditionalAttributes
            {
                PropertyName = "SpotDirection",
                PropertyType = typeof(Vector3D),
                Attributes   = new Attribute[] {
                    new EditorAttribute(typeof(VectorEditor), typeof(UITypeEditor)),
                    new RangeAttribute(-10, 10, 0.1)
                }
            });

            PropertyAttributesTypeDescriptionProvider provider = new PropertyAttributesTypeDescriptionProvider(
                typeof(T), list.ToArray());

            TypeDescriptor.AddProvider(provider, typeof(T));
        }
Exemple #6
0
        //Property overriding taken from
        //http://stackoverflow.com/questions/12143650/how-to-add-property-level-attribute-to-the-typedescriptor-at-runtime
        private void OverrideProperty(Type type, string PropertyName, params Attribute[] attributes)
        {
            //Override the KeyValue type descriptors
            // prepare our property overriding type descriptor
            PropertyOverridingTypeDescriptor ctd = new PropertyOverridingTypeDescriptor(TypeDescriptor.GetProvider(type).GetTypeDescriptor(type));

            // iterate through properies in the supplied object/type
            foreach (System.ComponentModel.PropertyDescriptor pd in TypeDescriptor.GetProperties(typeof(KeyValue)))
            {
                // for every property that complies to our criteria
                if (pd.Name == PropertyName)
                {
                    // we first construct the custom PropertyDescriptor with the TypeDescriptor's
                    // built-in capabilities
                    System.ComponentModel.PropertyDescriptor pd2 =
                        TypeDescriptor.CreateProperty(
                            type, // or just _settings, if it's already a type
                            pd,   // base property descriptor to which we want to add attributes
                            // The PropertyDescriptor which we'll get will just wrap that
                            // base one returning attributes we need.
                            attributes
                            // this method really can take as many attributes as you like,
                            // not just one
                            );

                    // and then we tell our new PropertyOverridingTypeDescriptor to override that property
                    ctd.OverrideProperty(pd2);
                }
            }

            // then we add new descriptor provider that will return our descriptor istead of default
            TypeDescriptor.AddProvider(new TypeDescriptorOverridingProvider(ctd), type);
        }
Exemple #7
0
        public void AddProviderToBaseType_GetPropertiesOfDerivedType()
        {
            // Before adding TDP
            var props = TypeDescriptor.GetProperties(typeof(Base)).Cast <PropertyDescriptor>().
                        Select(p => p.Name).ToArray();

            CollectionAssert.AreEquivalent(new[] { "A", "B" }, props);

            props = TypeDescriptor.GetProperties(typeof(Derived)).Cast <PropertyDescriptor>().
                    Select(p => p.Name).ToArray();
            CollectionAssert.AreEquivalent(new[] { "A", "B", "C" }, props);

            TypeDescriptionProvider provider = null;

            try {
                provider = new AssociatedMetadataTypeTypeDescriptionProvider(typeof(Base));
                TypeDescriptor.AddProvider(provider, typeof(Base));

                // After adding TDP
                props = TypeDescriptor.GetProperties(typeof(Base)).Cast <PropertyDescriptor>().
                        Select(p => p.Name).ToArray();
                CollectionAssert.AreEquivalent(new[] { "A", "B" }, props);

                props = TypeDescriptor.GetProperties(typeof(Derived)).Cast <PropertyDescriptor>().
                        Select(p => p.Name).ToArray();
                CollectionAssert.AreEquivalent(new[] { "A", "B", "C" }, props);
            }
            finally {
                // Ensure we remove the provider we attached.
                TypeDescriptor.RemoveProvider(provider, typeof(Base));
            }
        }
Exemple #8
0
        public void AddProviderToTypeAndInstance()
        {
            var instance = new Base();

            // Before adding TDPs
            var props = TypeDescriptor.GetProperties(instance).Cast <PropertyDescriptor>().
                        Select(p => p.Name).ToArray();

            CollectionAssert.AreEquivalent(new[] { "A", "B" }, props);

            TypeDescriptionProvider typeProvider     = null;
            TypeDescriptionProvider instanceProvider = null;

            try {
                typeProvider = new AssociatedMetadataTypeTypeDescriptionProvider(typeof(Base));
                TypeDescriptor.AddProvider(typeProvider, typeof(Base));

                instanceProvider = new TestTypeDescriptionProvider(instance);
                TypeDescriptor.AddProvider(instanceProvider, instance);

                // After adding TDPs
                props = TypeDescriptor.GetProperties(instance).Cast <PropertyDescriptor>().
                        Select(p => p.Name).ToArray();
                CollectionAssert.AreEquivalent(new[] { "A", "B", "CustomProperty1", "CustomProperty2" }, props);
            }
            finally {
                // Ensure we remove the providers we attached.
                TypeDescriptor.RemoveProvider(typeProvider, typeof(Base));
                TypeDescriptor.RemoveProvider(instanceProvider, instance);
            }
        }
Exemple #9
0
        public void MetadataInheritance()
        {
            TypeDescriptionProvider baseProvider              = null;
            TypeDescriptionProvider derivedProvider           = null;
            TypeDescriptionProvider derivedNoMetadataProvider = null;

            try {
                baseProvider = new AssociatedMetadataTypeTypeDescriptionProvider(typeof(Base));
                TypeDescriptor.AddProvider(baseProvider, typeof(Base));
                derivedProvider = new AssociatedMetadataTypeTypeDescriptionProvider(typeof(Derived));
                TypeDescriptor.AddProvider(derivedProvider, typeof(Derived));
                derivedNoMetadataProvider = new AssociatedMetadataTypeTypeDescriptionProvider(typeof(DerivedNoMetadata));
                TypeDescriptor.AddProvider(derivedNoMetadataProvider, typeof(DerivedNoMetadata));

                var attrs = TypeDescriptor.GetProperties(typeof(Base))["A"].Attributes.Cast <Attribute>().
                            Select(a => a.GetType().Name).ToArray();
                CollectionAssert.IsSubsetOf(new[] { "DescriptionAttribute" }, attrs);

                attrs = TypeDescriptor.GetProperties(typeof(Derived))["A"].Attributes.Cast <Attribute>().
                        Select(a => a.GetType().Name).ToArray();
                CollectionAssert.IsSubsetOf(new[] { "DescriptionAttribute", "CategoryAttribute" }, attrs);

                attrs = TypeDescriptor.GetProperties(typeof(DerivedNoMetadata))["A"].Attributes.Cast <Attribute>().
                        Select(a => a.GetType().Name).ToArray();
                CollectionAssert.IsSubsetOf(new[] { "DescriptionAttribute" }, attrs);
            }
            finally {
                // Ensure we remove the providers we attached.
                TypeDescriptor.RemoveProvider(baseProvider, typeof(Base));
                TypeDescriptor.RemoveProvider(derivedProvider, typeof(Derived));
                TypeDescriptor.RemoveProvider(derivedNoMetadataProvider, typeof(DerivedNoMetadata));
            }
        }
        public void SetPackageBuilder(PackageBuilder builder)
        {
            SuspendLayout();
            packageBuilder      = builder;
            metadataSaveVersion = MetadataSpecified && File.Exists(metadataPath) ? 0 : -1;
            TypeDescriptor.AddProvider(descriptionProvider, packageBuilder);
            metadataProperties.SelectedObject = packageBuilder;
            metadataProperties.ExpandAllGridItems();
            var entryPointPath       = Path.GetFileNameWithoutExtension(metadataPath) + Constants.BonsaiExtension;
            var entryPointLayoutPath = entryPointPath + Constants.LayoutExtension;

            foreach (var file in packageBuilder.Files)
            {
                if (file.EffectivePath == entryPointPath)
                {
                    entryPoint = file as PhysicalPackageFile;
                }
                if (file.EffectivePath == entryPointLayoutPath)
                {
                    entryPointLayout = file as PhysicalPackageFile;
                }
                AddPackageFile(file);
            }
            contentView.ExpandAll();
            ResumeLayout();
        }
        public static List <string> ValidateAllProperties(this object source, Type metadataType)
        {
            var targetType   = source.GetType();
            var typeProvider = new AssociatedMetadataTypeTypeDescriptionProvider(targetType, metadataType);

            try
            {
                if (targetType != metadataType)
                {
                    TypeDescriptor.AddProvider(typeProvider, targetType);
                }

                var  validationContext = new ValidationContext(source, null, null);
                var  validationResults = new List <ValidationResult>();
                bool result            = Validator.TryValidateObject(source, validationContext, validationResults, true);
                if (validationResults.Count > 0)
                {
                    return(validationResults.Select(item => item.ErrorMessage).ToList());
                }
                return(null);
            }
            catch
            {
                return(null);
            }
            finally
            {
                TypeDescriptor.RemoveProvider(typeProvider, targetType);
            }
        }
Exemple #12
0
        private static void AddAttributes(Type type, IGrouping <Type, IAttributeProvider> group)
        {
            var provider = new ExtendedTypeDescriptionProvider(type, group);

            TypeDescriptor.AddProvider(provider, type);
            addedProviders[type] = provider;
        }
 public static void DoDialog(MainForm owner, string title)
 {
     if (GlobalWin.Emulator is Emulation.Cores.Waterbox.NymaCore core)
     {
         var desc = new Emulation.Cores.Waterbox.NymaTypeDescriptorProvider(core.SettingsInfo);
         try
         {
             // OH GOD THE HACKS WHY
             TypeDescriptor.AddProvider(desc, typeof(Emulation.Cores.Waterbox.NymaCore.NymaSettings));
             TypeDescriptor.AddProvider(desc, typeof(Emulation.Cores.Waterbox.NymaCore.NymaSyncSettings));
             DoDialog(owner, "Nyma Core", !core.HasSettings, !core.HasSyncSettings);
         }
         finally
         {
             TypeDescriptor.RemoveProvider(desc, typeof(Emulation.Cores.Waterbox.NymaCore.NymaSettings));
             TypeDescriptor.RemoveProvider(desc, typeof(Emulation.Cores.Waterbox.NymaCore.NymaSyncSettings));
         }
     }
     else
     {
         using var dlg = new GenericCoreConfig(owner)
               {
                   Text = title
               };
         dlg.ShowDialog(owner);
     }
 }
Exemple #14
0
        static void Main(string[] args)
        {
            A1 A = new A1();

            Console.WriteLine("Properties of an arbitrary object: A:");
            PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(A);

            foreach (PropertyDescriptor property in properties)
            {
                Console.WriteLine("- " + property.Name);
            }

            Console.WriteLine("\nAdd our useless provider System.Object and chain it with the original one...");
            TypeDescriptor.AddProvider(new UselessTypeDescriptionProvider(TypeDescriptor.GetProvider(typeof(A1))), typeof(A1));

            Console.WriteLine("\nProperties of an arbitrary object: Console.Out:");
            properties = TypeDescriptor.GetProperties(A);
            foreach (PropertyDescriptor property in properties)
            {
                Console.WriteLine("- " + property.Name);
            }
            properties = TypeDescriptor.GetProperties(A);
            foreach (PropertyDescriptor property in properties)
            {
                Console.WriteLine("- " + property.Name);
            }

            foreach (PropertyInfo property in TypeDescriptor.GetReflectionType(A).GetProperties())
            {
                Console.WriteLine("- " + property.Name);
            }
        }
Exemple #15
0
        protected DiagramControlBase()
        {
            //create the provider for all shapy diagram elements
            ShapeProvider provider = new ShapeProvider();

            TypeDescriptor.AddProvider(provider, typeof(SimpleShapeBase));
        }
Exemple #16
0
 /// <summary>
 /// Registers the provider with the
 /// <see cref="System.ComponentModel.TypeDescriptor"/> infrastructure.
 /// </summary>
 /// <remarks>
 /// This method is safe to call multiple times.
 /// </remarks>
 public static void RegisterProvider()
 {
     if (Interlocked.Exchange(ref _registeredProvider, 1) == 0)
     {
         TypeDescriptor.AddProvider(DnsNameTypeDescriptionProvider.Instance, typeof(DnsName));
     }
 }
        static EntityBuilder()
        {
            var      mf     = ConfigurationManager.AppSettings["METADATA_FILE"];
            XElement mdFile = XElement.Load(mf);

            var allDescriptors = new List <EntityPropertyDescriptor>();

            foreach (XElement node in mdFile.Elements())
            {
                var descriptors = new List <EntityPropertyDescriptor>();
                foreach (var e in node.Elements())
                {
                    var pd = new EntityPropertyDescriptor(
                        e.Attribute("Name").Value,
                        Convert.ToBoolean(e.Attribute("ReadOnly").Value),
                        Type.GetType(e.Attribute("Type").Value), null);
                    descriptors.Add(pd);
                    if (!allDescriptors.Contains(pd))
                    {
                        allDescriptors.Add(pd);
                    }
                }
                // add
                AssetType key = (AssetType)Enum.Parse(typeof(AssetType), node.Name.ToString(), true);
                Metadata.Add(key, descriptors.ToArray());
            }
            // register
            var customProvider = new EntityTypeDescriptionProvider(TypeDescriptor.GetProvider(typeof(Entity)),
                                                                   new EntityCustomTypeDescriptor(new PropertyDescriptorCollection(allDescriptors.ToArray(), false)));

            TypeDescriptor.AddProvider(customProvider, typeof(Entity));
        }
Exemple #18
0
        protected ExpressionTestBase()
        {
            this.myValidExpressionsOwner = new ExpressionOwner();
            this.myValidExpressionsOwner = new ExpressionOwner();
            this.myGenericContext        = this.CreateGenericContext(this.myValidExpressionsOwner);
            var context = new ExpressionContext(this.myValidExpressionsOwner);

            context.Options.OwnerMemberAccess = BindingFlags.Public | BindingFlags.NonPublic;
            context.Imports.ImportBuiltinTypes();
            context.Imports.AddType(typeof(Convert), "Convert");
            context.Imports.AddType(typeof(Guid));
            context.Imports.AddType(typeof(Version));
            context.Imports.AddType(typeof(DayOfWeek));
            context.Imports.AddType(typeof(DayOfWeek), "DayOfWeek");
            context.Imports.AddType(typeof(ValueType));
            context.Imports.AddType(typeof(IComparable));
            context.Imports.AddType(typeof(ICloneable));
            context.Imports.AddType(typeof(Array));
            context.Imports.AddType(typeof(Delegate));
            context.Imports.AddType(typeof(AppDomainInitializer));
            context.Imports.AddType(typeof(Encoding));
            context.Imports.AddType(typeof(ASCIIEncoding));
            context.Imports.AddType(typeof(ArgumentException));
            this.myValidCastsContext = context;
            TypeDescriptor.AddProvider(new UselessTypeDescriptionProvider(TypeDescriptor.GetProvider(typeof(int))), typeof(int));
            TypeDescriptor.AddProvider(new UselessTypeDescriptionProvider(TypeDescriptor.GetProvider(typeof(string))),
                                       typeof(string));
            this.Initialize();
        }
Exemple #19
0
        public static void Add(Type type)
        {
            lock (descriptors)
            {
                if (!providers.ContainsKey(type))
                {
                    // determine if the base type was already added
                    // if so, remove it before adding sub-type
                    // (if a sub-type is added after its base type, infinite recursion occurs in GetTypeDescriptor())
                    var baseFound = false;
                    if (type.BaseType != null && providers.ContainsKey(type.BaseType))
                    {
                        baseFound = true;
                        Remove(type.BaseType);
                    }

                    // add the provider for the type
                    var provider = new HyperTypeDescriptionProvider(TypeDescriptor.GetProvider(type));

                    TypeDescriptor.AddProvider(provider, type);
                    providers.Add(type, provider);

                    // initialize descriptor
                    provider.GetTypeDescriptor(type);

                    // if base type was removed, we can now add it back after building the sub-type descriptor
                    if (baseFound)
                    {
                        Add(type.BaseType);
                    }
                }
            }
        }
Exemple #20
0
        public static void ScanAndDefineKeyToEntity(this Type type)
        {
            bool hasIdProperty = ChoTypeDescriptor.GetProperties(type).Where(p => String.Compare(p.Name, "id", true) == 0).Any();

            if (hasIdProperty)
            {
                return;
            }

            bool hasKeyDefined = ChoTypeDescriptor.GetProperties(type).Where(pd => pd.Attributes.OfType <KeyAttribute>().Any()).Any();

            if (hasKeyDefined)
            {
                return;
            }

            PropertyDescriptor firstPd = ChoTypeDescriptor.GetProperties(type).FirstOrDefault();

            if (firstPd == null)
            {
                return;
            }
            PropertyDescriptor      pd2 = TypeDescriptor.CreateProperty(type, firstPd, new KeyAttribute());
            ChoCustomTypeDescriptor ctd = new ChoCustomTypeDescriptor(TypeDescriptor.GetProvider(type).GetTypeDescriptor(type));

            ctd.OverrideProperty(pd2);
            TypeDescriptor.AddProvider(new ChoTypeDescriptionProvider(ctd), type);
        }
Exemple #21
0
        private IField GetFieldTypeDescriptor(IField field)
        {
            var provider = TypeDescriptor.GetProvider(typeof(IField));

            TypeDescriptor.AddProvider(new FieldDescriptionProvider(provider), field);
            return(field);
        }
Exemple #22
0
    public static void Register(Type type, params PropertyDescriptor[] customProperties)
    {
        var baseProvider   = TypeDescriptor.GetProvider(type);
        var typeDescriptor = new CustomPropertyTypeDescriptor(baseProvider.GetTypeDescriptor(type), customProperties);

        TypeDescriptor.AddProvider(new Provider(baseProvider, typeDescriptor), type);
    }
Exemple #23
0
 /// <summary>
 /// Adds the associated metadata providers for each type.
 /// </summary>
 /// <see cref="http://blogs.msdn.com/davidebb/archive/2009/07/24/using-an-associated-metadata-class-outside-dynamic-data.aspx"/>
 /// <param name="typesWhichMayHaveBuddyClasses">The types which may have buddy classes.</param>
 public static void AddAssociatedMetadataProviders(IEnumerable <Type> typesWhichMayHaveBuddyClasses)
 {
     foreach (var typeWithBuddyClass in typesWhichMayHaveBuddyClasses)
     {
         TypeDescriptor.AddProvider(new AssociatedMetadataTypeTypeDescriptionProvider(typeWithBuddyClass), typeWithBuddyClass);
     }
 }
Exemple #24
0
        public DynamicPropertyManager(TTarget target)
        {
            this.target = target;

            provider = new DynamicTypeDescriptionProvider(typeof(TTarget));
            TypeDescriptor.AddProvider(provider, target);
        }
Exemple #25
0
 public BaseRectangleItem()
 {
     this.thickness = 1;
     this.dashStyle = DashStyle.Solid;
     this.Size      = new Size(GlobalValues.PreferedSize.Width, 2 * GlobalValues.PreferedSize.Height);
     TypeDescriptor.AddProvider(new RectangleItemTypeProvider(), typeof(BaseRectangleItem));
 }
Exemple #26
0
        public DynamicPropertyManager()
        {
            Type type = typeof(TTarget);

            provider = new DynamicTypeDescriptionProvider(type);
            TypeDescriptor.AddProvider(provider, type);
        }
Exemple #27
0
        public static void AddAttionalProperty <T, TProperty>(string propName, Func <T, TProperty> func) where T : class
        {
            var dic = new Dictionary <string, Func <T, TProperty> >();

            dic.Add(propName, func);
            TypeDescriptor.AddProvider(new AdditionPropertyTypeDescriptorProvider <T, TProperty>(dic), typeof(T));
        }
Exemple #28
0
        public static void Add(Type type)
        {
            //Avoid some base types!!!!!!
            if (type.FullName == "System.Object" ||
                type.FullName == "System.String" ||
                type.FullName == "System.DateTime" ||
                type.IsPrimitive ||
                type.IsValueType ||
                !type.IsClass
                )
            {
                return;
            }
            int  hc         = type.GetHashCode();
            bool doRegister = false;

            lock (_registeredTypes) {
                if (!_registeredTypes.ContainsKey(hc))
                {
                    _registeredTypes.Add(hc, type);
                    doRegister = true;
                }
            }
            if (doRegister)
            {
                TypeDescriptionProvider parent = TypeDescriptor.GetProvider(type);
                TypeDescriptor.AddProvider(new HyperTypeDescriptionProvider(parent), type);
            }
        }
 public static void RegisterTypes()
 {
     foreach (Type t in new[] { typeof(ModelField), typeof(NavigationProperty), typeof(Association) })
     {
         TypeDescriptor.AddProvider(new TypeDescriptorProvider(TypeDescriptor.GetProvider(t)), t);
     }
 }
Exemple #30
0
        private void SetProperty(ref PropertyDescriptor property, ref string propertyName, string value)
        {
            if (propertyName != value)
            {
                if (value == null)
                {
                    DataMember   = string.Empty;
                    propertyName = string.Empty;
                }
                else
                {
                    var    split = value.Split(_dataMemberFieldSeperator);
                    string temp;
                    if (split.Length > 1)
                    {
                        DataMember = split[0];
                        temp       = split[1];
                    }
                    else
                    {
                        DataMember = string.Empty;
                        temp       = value;
                    }
                    propertyName = null;
                    if (DataSource != null && temp != string.Empty)
                    {
                        var propertyDescriptorCollection = ListBindingHelper.GetListItemProperties(DataSource, DataMember, null);
                        if (propertyDescriptorCollection != null)
                        {
                            if (propertyDescriptorCollection.Count == 0)
                            {
                                propertyName = value;
                            }
                            else
                            {
                                property = propertyDescriptorCollection.Find(temp, true);
                                if (property == null && _fieldsToPropertiesTypeDescriptionProvider == null)
                                {
                                    _fieldsToPropertiesTypeDescriptionProvider = new FieldsToPropertiesTypeDescriptionProvider(propertyDescriptorCollection[0].ComponentType, BindingFlags.Instance | BindingFlags.Public);
                                    TypeDescriptor.AddProvider(_fieldsToPropertiesTypeDescriptionProvider, propertyDescriptorCollection[0].ComponentType);
                                    propertyDescriptorCollection = ListBindingHelper.GetListItemProperties(DataSource, DataMember, null);
                                    property = propertyDescriptorCollection.Find(temp, true);
                                }
                            }
                        }

                        if (property != null)
                        {
                            propertyName = value;
                        }
                    }
                    else
                    {
                        propertyName = value;
                    }
                }
            }
            //  this.ResetData();
        }