Inheritance: System.Collections.IList, System.Collections.IDictionary, System.Collections.ICollection, System.Collections.IEnumerable
Example #1
0
 /// <summary>Initializes a new instance of the MatrixConverter class.</summary>
 public MatrixConverter()
 {
     var componentType = typeof(Matrix);
     var properties = TypeDescriptor.GetProperties(componentType);
     var descriptors =
         new PropertyDescriptorCollection(new PropertyDescriptor[]
         {
             properties.Find("Translation", true), new FieldPropertyDescriptor(componentType.GetField("M11")),
             new FieldPropertyDescriptor(componentType.GetField("M12")),
             new FieldPropertyDescriptor(componentType.GetField("M13")),
             new FieldPropertyDescriptor(componentType.GetField("M14")),
             new FieldPropertyDescriptor(componentType.GetField("M21")),
             new FieldPropertyDescriptor(componentType.GetField("M22")),
             new FieldPropertyDescriptor(componentType.GetField("M23")),
             new FieldPropertyDescriptor(componentType.GetField("M24")),
             new FieldPropertyDescriptor(componentType.GetField("M31")),
             new FieldPropertyDescriptor(componentType.GetField("M32")),
             new FieldPropertyDescriptor(componentType.GetField("M33")),
             new FieldPropertyDescriptor(componentType.GetField("M34")),
             new FieldPropertyDescriptor(componentType.GetField("M41")),
             new FieldPropertyDescriptor(componentType.GetField("M42")),
             new FieldPropertyDescriptor(componentType.GetField("M43")),
             new FieldPropertyDescriptor(componentType.GetField("M44"))
         });
     propertyDescriptions = descriptors;
     supportStringConvert = false;
 }
 internal WorkflowDataContext(ActivityExecutor executor, ActivityInstance activityInstance, bool includeLocalVariables)
 {
     this.executor = executor;
     this.activityInstance = activityInstance;
     this.IncludesLocalVariables = includeLocalVariables;
     this.properties = CreateProperties();
 }
        public static DataTable ConvertToDataTableMethod <T>(this IEnumerable <T> data)
        {
            List <IDataRecord> list = data.Cast <IDataRecord>().ToList();

            System.ComponentModel.PropertyDescriptorCollection props = null;
            DataTable table = new DataTable();

            if (list != null && list.Count > 0)
            {
                props = TypeDescriptor.GetProperties(list[0]);
                for (int i = 0; i < props.Count; i++)
                {
                    PropertyDescriptor prop = props[i];
                    table.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);
                }
            }
            if (props != null)
            {
                object[] values = new object[props.Count];
                foreach (T item in data)
                {
                    for (int i = 0; i < values.Length; i++)
                    {
                        values[i] = props[i].GetValue(item) ?? DBNull.Value;
                    }
                    table.Rows.Add(values);
                }
            }
            return(table);
        }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MatrixConverter"/> class.
        /// </summary>
        public MatrixConverter()
        {
            Type type = typeof(Matrix);
            Properties = new PropertyDescriptorCollection(new[] 
            { 
                new FieldPropertyDescriptor(type.GetField("M11")), 
                new FieldPropertyDescriptor(type.GetField("M12")),
                new FieldPropertyDescriptor(type.GetField("M13")),
                new FieldPropertyDescriptor(type.GetField("M14")),

                new FieldPropertyDescriptor(type.GetField("M21")), 
                new FieldPropertyDescriptor(type.GetField("M22")),
                new FieldPropertyDescriptor(type.GetField("M23")),
                new FieldPropertyDescriptor(type.GetField("M24")),

                new FieldPropertyDescriptor(type.GetField("M31")), 
                new FieldPropertyDescriptor(type.GetField("M32")),
                new FieldPropertyDescriptor(type.GetField("M33")),
                new FieldPropertyDescriptor(type.GetField("M34")),

                new FieldPropertyDescriptor(type.GetField("M41")), 
                new FieldPropertyDescriptor(type.GetField("M42")),
                new FieldPropertyDescriptor(type.GetField("M43")),
                new FieldPropertyDescriptor(type.GetField("M44")),
            });
        }
        public override PropertyDescriptorCollection GetProperties()
        {
            if (_properties == null) {
                // Get properties from our parent
                var originalCollection = base.GetProperties();

                // Set _properties to avoid a stack overflow when CreateProjectionProperties
                // ends up recursively calling TypeDescriptor.GetProperties on a type.
                _properties = originalCollection;

                var customDescriptorsCreated = false;
                var tempPropertyDescriptors = new List<PropertyDescriptor>();

                // for every property exposed by our parent, see if we have additional metadata to add,
                // and if we do we need to add a wrapper PropertyDescriptor to add the new attributes
                foreach (var propDescriptor in _properties.OfType<PropertyDescriptor>()) {
                    var newMetadata = GetAdditionalAttributes(propDescriptor);
                    if (newMetadata.Length > 0) {
                        tempPropertyDescriptors.Add(new DataControllerPropertyDescriptor(propDescriptor, newMetadata));
                        customDescriptorsCreated = true;
                    }
                    else
                        tempPropertyDescriptors.Add(propDescriptor);
                }

                if (customDescriptorsCreated)
                    _properties = new PropertyDescriptorCollection(tempPropertyDescriptors.ToArray(), true);
            }

            return _properties;
        }
Example #6
0
        public static async Task <int> AddUpdateRecord <T>(WebApiProxy proxy, T ModelObject, bool IsNewObject = false) where T : class
        {
            Dictionary <string, string> ProcedureInfo = GetProcedureInfo(ModelObject);

            System.ComponentModel.PropertyDescriptorCollection pdc = System.ComponentModel.TypeDescriptor.GetProperties(ModelObject);
            Dictionary <string, object> dicParams = pdc.Cast <PropertyDescriptor>().Where(item => ProcedureInfo.ContainsKey(item.Name)).ToDictionary(key => ProcedureInfo[key.Name], value => value.GetValue(ModelObject));

            if (IsNewObject)
            {
                dicParams["@Id"] = -1;
            }

            if (dicParams.ContainsKey("@Logo"))
            {
                dicParams["@Logo"] = 1014;
            }
            DataSet dataSet = await proxy.ExecuteDataset(ProcedureInfo["ProcedureName"], dicParams);

            if (dataSet != null && dataSet.Tables != null && dataSet.Tables.Count > 0)
            {
                if (dataSet.Tables[0].Rows != null && dataSet.Tables[0].Rows.Count > 0)
                {
                    int ID = Convert.ToInt32(dataSet.Tables[0].Rows[0][0].ToString());
                    return(ID);
                }
            }
            return(-1);
        }
Example #7
0
 /// <summary>
 ///   Initializes a new instance of the <see cref = "T:SiliconStudio.Core.TypeConverters.Half2Converter" /> class.
 /// </summary>
 public Half2Converter()
 {
     Type type = typeof (Half2);
     PropertyDescriptor[] propArray = new PropertyDescriptor[]
                                          {new FieldPropertyDescriptor(type.GetField("X")), new FieldPropertyDescriptor(type.GetField("Y"))};
     properties = new PropertyDescriptorCollection(propArray);
 }
        public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            var cols = base.GetProperties();
            var props = new PropertyDescriptorCollection(null);

            foreach (FieldInfo fi in _instance.GetType().GetFields())
            {
                var prop = new MyPropertyDesciptor(fi, attributes);
                props.Add(prop);

                if (fi.FieldType.Namespace == "System.Collections.Generic")
                {
                    Type[] args = fi.FieldType.GetGenericArguments();
                    foreach (Type arg in args)
                        modifyNonSystemTypes(arg);
                }
                else
                {
                    modifyNonSystemTypes(fi.FieldType);
                }

            }
            // Return the computed properties
            return props;
        }
 public ComponentImporter(Type type, ICustomTypeDescriptor typeDescriptor) : base(type)
 {
     if (typeDescriptor == null)
     {
         typeDescriptor = new Maticsoft.Json.Conversion.CustomTypeDescriptor(type);
     }
     int num = 0;
     PropertyDescriptorCollection properties = typeDescriptor.GetProperties();
     IObjectMemberImporter[] importerArray = new IObjectMemberImporter[properties.Count];
     for (int i = 0; i < properties.Count; i++)
     {
         IServiceProvider provider = properties[i] as IServiceProvider;
         if (provider != null)
         {
             IObjectMemberImporter service = (IObjectMemberImporter) provider.GetService(typeof(IObjectMemberImporter));
             if (service != null)
             {
                 importerArray[i++] = service;
                 num++;
             }
         }
     }
     this._properties = properties;
     if (num > 0)
     {
         this._importers = importerArray;
     }
 }
Example #10
0
        public ComponentImporter(Type type, ICustomTypeDescriptor typeDescriptor) :
            base(type)
        {
            if (typeDescriptor == null)
                typeDescriptor = new CustomTypeDescriptor(type);
            
            int count = 0;
            PropertyDescriptorCollection properties = typeDescriptor.GetProperties();
            IObjectMemberImporter[] importers = new IObjectMemberImporter[properties.Count];
            
            for (int i = 0; i < properties.Count; i++)
            {
                IServiceProvider sp = properties[i] as IServiceProvider;
                
                if (sp == null)
                    continue;
                
                IObjectMemberImporter importer = (IObjectMemberImporter) sp.GetService(typeof(IObjectMemberImporter));
                
                if (importer == null)
                    continue;
                
                importers[i++] = importer;
                count++;
            }

            _properties = properties;

            if (count > 0)
                _importers = importers;
        }
		public static PropertyDescriptorCollection GetProperties(Type memberType)
		{
			if (memberType == null)
				return PropertyDescriptorCollection.Empty;

			PropertyDescriptorCollection pdc;
			if ((pdc = (PropertyDescriptorCollection) collections[memberType]) != null)
				return (pdc);
 
			PropertyInfo[] allProps = memberType.GetProperties();
			int l = allProps.Length;
			for (int i = 0; i < allProps.Length; i++)
			{
				PropertyInfo pi = allProps[i];
				if (!IsAllowedProperty(pi.Name))
				{
					allProps[i] = null;
					l--;
				}
			}

			PropertyDescriptor[] descriptors = new PropertyDescriptor[l];
			
			int j = 0;
			foreach(PropertyInfo pinfo in allProps)
			{
				if (pinfo != null)
				{
					descriptors[j++] = new ExtendedPropertyDescriptor(pinfo.Name, memberType, pinfo.PropertyType);
				}		
			}								 
			PropertyDescriptorCollection result = new PropertyDescriptorCollection(descriptors);
			collections.Add(memberType, result);
			return result;			
		}
 public override PropertyDescriptorCollection GetProperties() {
     if (_properties == null) {
         var dictionaryProps = _values.Keys.Select(propName => new DictionaryPropertyDescriptor(propName));
         _properties = new PropertyDescriptorCollection(dictionaryProps.ToArray());
     }
     return _properties;
 }
Example #13
0
 // copy all runtime data information
 internal DataRecordInternal(object[] values, PropertyDescriptorCollection descriptors, FieldNameLookup fieldNameLookup)
 {
     Debug.Assert(null != values, "invalid attempt to instantiate DataRecordInternal with null value[]");
     _values = values;
     _propertyDescriptors = descriptors;
     _fieldNameLookup = fieldNameLookup;
 }
		public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
		{
			PropertyDescriptorCollection descriptorCollection = new PropertyDescriptorCollection((PropertyDescriptor[])null);
			foreach (ScriptProperty property in this.settings.ScriptProperties.Values)
				descriptorCollection.Add((PropertyDescriptor)new ScriptPropertyDescriptor(property));
			return descriptorCollection;
		}
Example #15
0
		public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
		{
			PropertyDescriptorCollection descriptorCollection = new PropertyDescriptorCollection((PropertyDescriptor[])null);
			foreach (PropertyDescriptor parent in TypeDescriptor.GetProperties(this.component, attributes, false))
				descriptorCollection.Add((PropertyDescriptor)new ReadOnlyPropertyDescriptor(parent));
			return descriptorCollection;
		}
 private ComponentExporter(Type inputType, PropertyDescriptorCollection properties) : 
     base(inputType)
 {
     Debug.Assert(properties != null);
     
     _properties = properties;
 }
        protected override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            var props = base.GetProperties(attributes);

            var thisType = GetType();
            var properties = new ArrayList();
            foreach (PropertyDescriptor prop in props)
            {
                var collection = prop.Attributes;

                var displayNameAttribute =
                    (SettingDisplayNameAttribute)(collection[typeof(SettingDisplayNameAttribute)]);

                if (displayNameAttribute != null)
                {
                    var newDisplayNameAttribute =
                        GetDisplayNameAttribute(displayNameAttribute.FriendlyName, displayNameAttribute.ConfigPropertyName);

                    properties.Add(TypeDescriptor.CreateProperty(thisType, prop, newDisplayNameAttribute));
                }
                else
                {
                    properties.Add(prop);
                }
            }

            props = new PropertyDescriptorCollection((PropertyDescriptor[])properties.ToArray(typeof(PropertyDescriptor)));
            return props;
        }
Example #18
0
        internal void AddProperties(System.ComponentModel.PropertyDescriptorCollection properties)
        {
            foreach (System.ComponentModel.PropertyDescriptor propertyDescriptor in properties)
            {
                object defaultValue = null;
                // If this is a string, default it to an empty string (instead of the system default of null)
                if (propertyDescriptor.PropertyType == typeof(string))
                {
                    defaultValue = string.Empty;
                }
                // Otherwise, if it's value type, default it to whatever the default of that object is.
                else if (propertyDescriptor.PropertyType.IsValueType)
                {
                    defaultValue = Activator.CreateInstance(propertyDescriptor.PropertyType);
                }

                // If the user specified a default, then use that.
                DefaultValueAttribute defaultAttribute = propertyDescriptor.Attributes[typeof(DefaultValueAttribute)] as DefaultValueAttribute;
                if (defaultAttribute != null)
                {
                    defaultValue = defaultAttribute.Value;
                }

                if (defaultValue != null && defaultValue.GetType().IsEnum)
                {
                    //throw new NotSupportedException("Component configuration that contain enumerations are not supported.");
                    //string value = defaultValue.GetType().GetEnumName(defaultValue);
                    //string[] names = defaultValue.GetType().GetEnumNames();
                }

                Properties.Add(propertyDescriptor.Name, new ConfigPropertyObject(propertyDescriptor.Name, defaultValue, propertyDescriptor.PropertyType, propertyDescriptor.DisplayName, propertyDescriptor.Description));
            }
        }
        private ComponentExporter(Type inputType, PropertyDescriptorCollection properties) : 
            base(inputType)
        {
            Debug.Assert(properties != null);
            
            _properties = properties;

            int index = 0;
            int count = 0;
            IObjectMemberExporter[] exporters = new IObjectMemberExporter[properties.Count];

            foreach (PropertyDescriptor property in properties)
            {
                IServiceProvider sp = property as IServiceProvider;
                
                if (sp == null)
                    continue;
                
                IObjectMemberExporter exporter = (IObjectMemberExporter) sp.GetService(typeof(IObjectMemberExporter));
                
                if (exporter == null)
                    continue;
                
                exporters[index++] = exporter;
                count++;
            }
            
            if (count > 0)
                _exporters = exporters;
        }
		public IEnumerable<AbstractField> Index(object val, PropertyDescriptorCollection properties, Field.Store defaultStorage)
		{
			return from property in properties.Cast<PropertyDescriptor>()
			       where property.Name != Constants.DocumentIdFieldName
			       from field in CreateFields(property.Name, property.GetValue(val), defaultStorage)
			       select field;
		}
Example #21
0
		public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
		{
			PropertyDescriptorCollection descriptorCollection = new PropertyDescriptorCollection((PropertyDescriptor[])null);
			foreach (PropertyDescriptor parent in TypeDescriptor.GetProperties((object) this.provider.UserProvider, attributes, false))
				descriptorCollection.Add((PropertyDescriptor)new FQProviderPropertyDescriptor(parent));
			return descriptorCollection;
		}
        public PropertyDescriptorCollection AddProperty(PropertyDescriptorCollection pdc, string propertyName, Type propertyType, TypeConverter converter,
            Attribute[] attributes)
        {
            List<PropertyDescriptor> properties = new List<PropertyDescriptor>(pdc.Count);

            for (int i = 0; i < pdc.Count; i++)
            {
                PropertyDescriptor pd = pdc[i];

                if (pd.Name != propertyName)
                {
                    properties.Add(pd);
                }
            }

            InstanceSavePropertyDescriptor ppd = new InstanceSavePropertyDescriptor(
                propertyName, propertyType, attributes);

            ppd.TypeConverter = converter;

            properties.Add(ppd);

            //PropertyDescriptor propertyDescriptor;

            return new PropertyDescriptorCollection(properties.ToArray());
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="T:DescriptorBase"/> class.
 /// </summary>
 /// <param name="provider">The provider.</param>
 /// <param name="parentdescriptor">The parentdescriptor.</param>
 /// <param name="objectType">Type of the object.</param>
 public DescriptorBase(ShapeProvider provider, ICustomTypeDescriptor parentdescriptor, Type objectType)
     : base(parentdescriptor)
 {
     this.provider = provider;
     this.type = objectType;
     mProperties = new PropertyDescriptorCollection(null);
 }
 protected PropertyDescriptorCollection _EnsureProperties()
 {
     if (properties == null) {
         properties = TypeDescriptor.GetProperties(this.objectContext);
     }
     return properties;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="T:DescriptorBase"/> class.
 /// </summary>
 /// <param name="provider">The provider.</param>
 /// <param name="objectType">Type of the object.</param>
 public DescriptorBase(TypeDescriptionProvider provider, Type objectType)
     : base()
 {
     this.provider = provider;
     this.type = objectType;
     mProperties = new PropertyDescriptorCollection(null);
 }
        /*
         * Does the property filtering...
         */
        private PropertyDescriptorCollection FilterProperties(PropertyDescriptorCollection pdc)
        {
            ArrayList toRemove = new ArrayList();

            PropertyDescriptor pd = pdc.Find("fileAction", true);
            if (pd != null)
            {
                object val = pd.GetValue(this);
                if (val != null)
                {
                    if ((PGPFileAction)val == PGPFileAction.Decrypt)
                        foreach (string s in invalidDecrypt)
                            toRemove.Add(s);
                    else if ((PGPFileAction)val == PGPFileAction.Encrypt)
                        foreach (string s in invalidEncrypt)
                            toRemove.Add(s);
                }
            }

            PropertyDescriptorCollection adjustedProps = new PropertyDescriptorCollection(new PropertyDescriptor[] { });
            foreach (PropertyDescriptor p in pdc)
                if (!toRemove.Contains(p.Name))
                    adjustedProps.Add(p);

            return adjustedProps;
        }
		public void Find ()
		{
			PropertyDescriptor descA = new MockPropertyDescriptor ("hehe_\u0061\u030a", 2);
			PropertyDescriptor descB = new MockPropertyDescriptor ("heh_\u00e5", 3);
			PropertyDescriptor descC = new MockPropertyDescriptor ("Foo", 5);
			PropertyDescriptor descD = new MockPropertyDescriptor ("FOo", 6);
			PropertyDescriptor descE = new MockPropertyDescriptor ("Aim", 1);
			PropertyDescriptor descF = new MockPropertyDescriptor ("Bar", 4);

			PropertyDescriptorCollection col = new PropertyDescriptorCollection (
				new PropertyDescriptor [] { descA, descB, descC, descD, descE, descF });

			Assert.IsNull (col.Find ("heh_\u0061\u030a", false), "#1");
			Assert.IsNull (col.Find ("hehe_\u00e5", false), "#2");
			Assert.AreSame (descA, col.Find ("hehe_\u0061\u030a", false), "#3");
			Assert.AreSame (descB, col.Find ("heh_\u00e5", false), "#4");
			Assert.IsNull (col.Find ("foo", false), "#5");
			Assert.AreSame (descC, col.Find ("foo", true), "#6");
			Assert.AreSame (descD, col.Find ("FOo", false), "#7");
			Assert.AreSame (descC, col.Find ("FOo", true), "#8");
			Assert.IsNull (col.Find ("fOo", false), "#9");
			Assert.AreSame (descC, col.Find ("fOo", true), "#10");
			Assert.IsNull (col.Find ("AIm", false), "#11");
			Assert.AreSame (descE, col.Find ("AIm", true), "#12");
			Assert.IsNull (col.Find ("AiM", false), "#13");
			Assert.AreSame (descE, col.Find ("AiM", true), "#14");
			Assert.AreSame (descE, col.Find ("Aim", false), "#15");
			Assert.AreSame (descE, col.Find ("Aim", true), "#16");
		}
 public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
 {
     var pdl = propertyDescriptorList.FindAll(pd => pd.Attributes.Contains(attributes));
     PreProcess(pdl);
     var pdcReturn = new PropertyDescriptorCollection(pdl.ToArray());
     return pdcReturn;
 }
Example #29
0
        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
        {
            //var cols = base.GetProperties();
            var props = new PropertyDescriptorCollection(null);

            foreach (FieldInfo fi in value.GetType().GetFields())
            {
                var prop = new MyPropertyDesciptor(fi, attributes);
                props.Add(prop);
                if (fi.FieldType.Namespace == "System.Collections.Generic")
                {
                    Type[] args = fi.FieldType.GetGenericArguments();
                    foreach (Type arg in args)
                        MyCustomTypeDescriptor.modifyNonSystemTypes(arg);
                }

                {
                    MyCustomTypeDescriptor.modifyNonSystemTypes(fi.FieldType);
                }
            }

            if (props.Count > 0)
                return props;

            return base.GetProperties(context, value, attributes);
        }
Example #30
0
        public MatrixConverter()
        {
            Type type = typeof(Matrix);

            PropertyDescriptor[] propArray = new PropertyDescriptor[]
            {
                new FieldPropertyDescriptor(type.GetField("M11")),
                new FieldPropertyDescriptor(type.GetField("M12")),
                new FieldPropertyDescriptor(type.GetField("M13")),
                new FieldPropertyDescriptor(type.GetField("M14")),

                new FieldPropertyDescriptor(type.GetField("M21")),
                new FieldPropertyDescriptor(type.GetField("M22")),
                new FieldPropertyDescriptor(type.GetField("M23")),
                new FieldPropertyDescriptor(type.GetField("M24")),

                new FieldPropertyDescriptor(type.GetField("M31")),
                new FieldPropertyDescriptor(type.GetField("M32")),
                new FieldPropertyDescriptor(type.GetField("M33")),
                new FieldPropertyDescriptor(type.GetField("M34")),

                new FieldPropertyDescriptor(type.GetField("M41")),
                new FieldPropertyDescriptor(type.GetField("M42")),
                new FieldPropertyDescriptor(type.GetField("M43")),
                new FieldPropertyDescriptor(type.GetField("M44")),
            };

            m_Properties = new PropertyDescriptorCollection(propArray);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ConfigurationTypeDescriptor"/> class.
        /// </summary>
        /// <param name="value">The value.</param>
        public ConfigurationTypeDescriptor(object value)
        {
            this.value = value;
            var descriptors = new List<PropertyDescriptor>();

            if (value != null)
            {
                var type = this.value.GetType();

                // Get all the fields
                var fields = type.GetFields();
                foreach (var field in fields)
                {
                    var name = this.GetReflectionName(field);
                    if (name != null)
                    {
                        descriptors.Add(new FieldPropertyDescriptor(name, field, this.value));
                    }
                }

                // Get all the properties
                var properties = type.GetProperties();
                foreach (var property in properties)
                {
                    var name = this.GetReflectionName(property);
                    if (name != null)
                    {
                        descriptors.Add(new PropertyPropertyDescriptor(name, property, this.value));
                    }
                }
            }

            this.properties = new PropertyDescriptorCollection(descriptors.ToArray(), true);
        }
Example #32
0
        public FFTypeDescriptor([NotNull]object targetObject)
        {
            _WrappedObject = targetObject;

            Type type = targetObject.GetType();
            PropertyDescriptorCollection pdc;
            if (!__TypedDescriptorCollection.TryGetValue(type, out pdc))
            {
                pdc = new PropertyDescriptorCollection(null);
                foreach (PropertyDescriptor pd in TypeDescriptor.GetProperties(type))
                {
                    var desc = new MyPropDesc(pd);
                    desc.ValueChanging += Property_ValueChanging;
                    pdc.Add(desc);
                }
                foreach (BindPropertyAttribute a in type.GetCustomAttributes<BindPropertyAttribute>())
                {
                    var childProp = a.GetSourcePropertyInfo(type);
                    var v = childProp.GetValue(targetObject, null);
                    var pdcs = TypeDescriptor.GetProperties(v, false);
                    var bpd = new BindPropertyDescriptor(pdcs[a.Property], childProp, a.DisplayName, a.Description, a.Category);
                    bpd.ValueChanging += Property_ValueChanging;
                    pdc.Add(bpd);
                }
   
                __TypedDescriptorCollection.Add(type, pdc);
            }
            _DescriptorCollection = pdc;
        }
        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
        {
            //var cols = base.GetProperties();
            var props = new PropertyDescriptorCollection(null);

            foreach (FieldInfo fi in value.GetType().GetFields())
            {
                var prop = new WsdlFieldDescriptor(fi, attributes);
                props.Add(prop);
                if (fi.FieldType.BaseType.FullName == "System.Array")
                {
                    TypeDescriptor.AddAttributes(fi.FieldType, new TypeConverterAttribute(typeof(ArrayConverter)));
                    Type elemType = fi.FieldType.GetElementType();
                    TypeDescriptorModifier.modifyType(elemType);
                }
                else if (fi.FieldType.BaseType.FullName == "System.Enum")
                {
                }
                else
                {
                    TypeDescriptorModifier.modifyType(fi.FieldType);
                }
            }

            if (props.Count > 0)
                return props;

            return base.GetProperties(context, value, attributes);
        }
    /// <summary>
    /// Retourne la collection des propriétés à afficher pour l'objet
    /// </summary>
    /// <remarks>
    /// Cette méthode ajoute le descripteur de la propriété "Name" uniquement pour les objets qui sont au moins <see cref="Control"/>.
    /// </remarks>
    /// <param name="component">objet dont les propriétés sont à afficher</param>
    /// <param name="attributes">null ou tableau de filtrage selon les attributs</param>
    /// <returns>la collection des descripteurs des propriétés à afficher</returns>
    public override PropertyDescriptorCollection GetProperties( object component, System.Attribute[] attributes ) {
      PropertyDescriptorCollection properties;

      // récupérer le propriétés à partir du descripteur de type
      if ( attributes == null ) attributes = DefaultFilter ;
      properties = TypeDescriptor.GetProperties( component, attributes );

      // l'objet dont les propriétés sont à afficher n'est pas Control --> rien d'autre à faire
      if (! (component is Control) ) return properties;

      // si la propriété Name figure déjà dans la collection --> rien d'autre à faire
      PropertyDescriptor oldDescriptorOfName = properties.Find( "Name", false ) ;
      if (oldDescriptorOfName != null) return properties ;

      // rechercher le descripteur de la propriété Name dans la collection de tous les descripteurs de propriétés
      PropertyDescriptorCollection allProperties = TypeDescriptor.GetProperties( component );
      oldDescriptorOfName = allProperties.Find( "Name", false );
      if ( oldDescriptorOfName == null ) return properties;

      // composer le nouveau descripteur de la propriété Name
      PropertyDescriptor newDescriptorOfName = TypeDescriptor.CreateProperty( oldDescriptorOfName.ComponentType, oldDescriptorOfName, new ParenthesizePropertyNameAttribute( true ), CategoryAttribute.Design );
      //PropertyDescriptor newDescriptorOfName = TypeDescriptor.CreateProperty( oldDescriptorOfName.ComponentType, oldDescriptorOfName, BrowsableAttribute.Yes, new ParenthesizePropertyNameAttribute( true ), CategoryAttribute.Design );
      
      // composer la collection des descripteurs de propriétés obtenu en ajoutant le descripteur de la propriété Name
      PropertyDescriptor[] propertiesArray = new PropertyDescriptor[ properties.Count ];
      properties.CopyTo( propertiesArray, 0 );
      properties = new PropertyDescriptorCollection( propertiesArray );
      properties.Add( newDescriptorOfName );
      return properties;
    }
Example #35
0
        private void getModel <TModel>(TModel result, System.ComponentModel.PropertyDescriptorCollection props, string parentContext) where TModel : class, new()
        {
            // loop each property in the passed in model
            foreach (var p in props.Cast <PropertyDescriptor>())
            {
                // get the property name... if we are in a hierarchal model structure, prepend the parent's name and seperate with an underscore
                var propName = string.IsNullOrEmpty(parentContext) ? p.Name : parentContext + '_' + p.Name;

                try
                {
                    // test to see if this is a nested model of base type "DnsPluginModel"
                    if ((p.PropertyType.BaseType != null) && (p.PropertyType.BaseType.Name.Equals("DnsPluginModel")))
                    {
                        // yes, get its child properties
                        var childProps = p.GetChildProperties();
                        if (childProps.Count > 0)
                        {
                            // get the actual instance (NOT the type!) of the current result's named (parentContext) child model that we just
                            // got child properties for so we can pass it in as the "subresult"
                            DnsPluginModel childInstanceSubresult = result.GetType().GetProperty(p.Name).GetValue(result, null) as DnsPluginModel;

                            if (childInstanceSubresult != null)
                            {
                                getModel <DnsPluginModel>(childInstanceSubresult, childProps, propName);
                            }
                        }
                    }
                }
                catch { continue; }

                // pull out the named (propName) value from the response's values, also determine if validation should be skipped for the property.
                //skipping validation should only be done when the field contains html fragments.

                bool skipValidation = false;
                foreach (var att in p.Attributes)
                {
                    if (att is Lpp.Objects.ValidationAttributes.SkipHttpValidationAttribute)
                    {
                        skipValidation = true;
                        break;
                    }
                }

                var v = ((System.Web.Mvc.ValueProviderCollection)Values).GetValue(propName, skipValidation);

                if (v == null)
                {
                    continue;
                }

                // convert the value v to the target result's property's type
                object value;
                try { value = v.ConvertTo(p.PropertyType); }
                catch { continue; }

                // given the property p, plug the value into the result (into the result's property)
                p.SetValue(result, value);
            }
        }
Example #36
0
        public Vector3Converter()
        {
            Type type = typeof(Vector3);

            PropertyDescriptor[] propArray = new PropertyDescriptor[3];
            propArray[0] = new FieldPropertyDescriptor(type.GetField("X"));
            propArray[1] = new FieldPropertyDescriptor(type.GetField("Y"));
            propArray[2] = new FieldPropertyDescriptor(type.GetField("Z"));

            m_Properties = new PropertyDescriptorCollection(propArray);
        }
Example #37
0
        public BoundingSphereConverter()
        {
            Type type = typeof(BoundingSphere);

            PropertyDescriptor[] propArray = new PropertyDescriptor[]
            {
                new FieldPropertyDescriptor(type.GetField("Center")),
                new FieldPropertyDescriptor(type.GetField("Radius")),
            };

            m_Properties = new PropertyDescriptorCollection(propArray);
        }
Example #38
0
        public RayConverter()
        {
            Type type = typeof(Ray);

            PropertyDescriptor[] propArray = new PropertyDescriptor[]
            {
                new FieldPropertyDescriptor(type.GetField("Position")),
                new FieldPropertyDescriptor(type.GetField("Direction")),
            };

            m_Properties = new PropertyDescriptorCollection(propArray);
        }
Example #39
0
        public PlaneConverter()
        {
            Type type = typeof(Plane);

            PropertyDescriptor[] propArray = new PropertyDescriptor[]
            {
                new FieldPropertyDescriptor(type.GetField("Normal")),
                new FieldPropertyDescriptor(type.GetField("D")),
            };

            m_Properties = new PropertyDescriptorCollection(propArray);
        }
Example #40
0
        public Vector2Converter()
        {
            Type type = typeof(Vector2);

            PropertyDescriptor[] propArray = new PropertyDescriptor[]
            {
                new FieldPropertyDescriptor(type.GetField("X")),
                new FieldPropertyDescriptor(type.GetField("Y")),
            };

            m_Properties = new PropertyDescriptorCollection(propArray);
        }
Example #41
0
        /// <summary>
        /// Перевести атрибуты заданного типа
        /// </summary>
        /// <remarks>Используется словарь с ключём, совпадающим с полным именем типа</remarks>
        public void TranslateAttrs(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            string dictKey = type.FullName;

            Localization.Dict dict;

            if (Localization.Dictionaries.TryGetValue(dictKey, out dict))
            {
                Dictionary <string, PropAttrs>  propAttrsDict = GetPropAttrsDict(dict);
                CM.PropertyDescriptorCollection allProps      = CM.TypeDescriptor.GetProperties(type);

                foreach (CM.PropertyDescriptor prop in allProps)
                {
                    PropAttrs propAttrs;

                    if (propAttrsDict.TryGetValue(prop.Name, out propAttrs))
                    {
                        CM.AttributeCollection attrs = prop.Attributes;

                        foreach (Attribute attr in attrs)
                        {
                            if (attr is DisplayNameAttribute)
                            {
                                if (!string.IsNullOrEmpty(propAttrs.DisplayName))
                                {
                                    ((DisplayNameAttribute)attr).DisplayNameValue = propAttrs.DisplayName;
                                }
                            }
                            else if (attr is CategoryAttribute)
                            {
                                if (!string.IsNullOrEmpty(propAttrs.Category))
                                {
                                    ((CategoryAttribute)attr).CategoryName = propAttrs.Category;
                                }
                            }
                            else if (attr is DescriptionAttribute)
                            {
                                if (!string.IsNullOrEmpty(propAttrs.Description))
                                {
                                    ((DescriptionAttribute)attr).DescriptionValue = propAttrs.Description;
                                }
                            }
                        }
                    }
                }
            }
        }
Example #42
0
        public Color3Converter()
        {
            Type type = typeof(Color3);

            PropertyDescriptor[] propArray = new PropertyDescriptor[]
            {
                new FieldPropertyDescriptor(type.GetField("Red")),
                new FieldPropertyDescriptor(type.GetField("Green")),
                new FieldPropertyDescriptor(type.GetField("Blue")),
            };

            m_Properties = new PropertyDescriptorCollection(propArray);
        }
Example #43
0
        public QuaternionConverter()
        {
            Type type = typeof(Quaternion);

            PropertyDescriptor[] propArray = new PropertyDescriptor[]
            {
                new FieldPropertyDescriptor(type.GetField("X")),
                new FieldPropertyDescriptor(type.GetField("Y")),
                new FieldPropertyDescriptor(type.GetField("Z")),
                new FieldPropertyDescriptor(type.GetField("W")),
            };

            m_Properties = new PropertyDescriptorCollection(propArray);
        }
Example #44
0
        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
        {
            System.ComponentModel.PropertyDescriptorCollection pds
                = TypeDescriptor.GetProperties(value.GetType(), attributes);

            string[] atts = new string[]
            {
                "Index",
                "Name",
                "SomeValue",
                "OtherValue",
            };

            return(pds.Sort(atts));
        }
Example #45
0
        public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors)
        {
            System.ComponentModel.PropertyDescriptorCollection pds
                = TypeDescriptor.GetProperties(typeof(VirtualItem));

            string[] atts = new string[]
            {
                "Index",
                "Name",
                "SomeValue",
                "OtherValue",
            };

            return(pds.Sort(atts));
        }
Example #46
0
        public static int Delete <T>(WebApiProxy proxy, T ModelObject) where T : class
        {
            try
            {
                Dictionary <string, string> ProcedureInfo = GetProcedureInfo(ModelObject, true);
                System.ComponentModel.PropertyDescriptorCollection pdc = System.ComponentModel.TypeDescriptor.GetProperties(ModelObject);
                Dictionary <string, object> dicParams = pdc.Cast <PropertyDescriptor>().Where(item => ProcedureInfo.ContainsKey(item.Name)).ToDictionary(key => ProcedureInfo[key.Name], value => value.GetValue(ModelObject));

                proxy.ExecuteNonQuery(ProcedureInfo["ProcedureName"], dicParams);
                return(1);
            }
            catch (SqlException ex)
            {
                throw new HttpException(500, ex.ToString());
            }
        }
Example #47
0
        /// <summary>
        /// Translates attributes of the specified type.
        /// </summary>
        /// <remarks>A dictionary with a key that matches the full type name is selected.</remarks>
        public static void Translate(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (Locale.Dictionaries.TryGetValue(type.FullName, out LocaleDict localeDict))
            {
                Dictionary <string, PropAttrs>   propAttrsDict = BuildPropAttrsDict(localeDict);
                NCM.PropertyDescriptorCollection allProps      = NCM.TypeDescriptor.GetProperties(type);

                foreach (NCM.PropertyDescriptor prop in allProps)
                {
                    if (propAttrsDict.TryGetValue(prop.Name, out PropAttrs propAttrs))
                    {
                        foreach (Attribute attr in prop.Attributes)
                        {
                            if (attr is SCM.DisplayNameAttribute displayNameAttribute)
                            {
                                if (!string.IsNullOrEmpty(propAttrs.DisplayName))
                                {
                                    displayNameAttribute.DisplayNameValue = propAttrs.DisplayName;
                                }
                            }
                            else if (attr is SCM.CategoryAttribute categoryAttribute)
                            {
                                if (!string.IsNullOrEmpty(propAttrs.Category))
                                {
                                    categoryAttribute.CategoryName = propAttrs.Category;
                                }
                            }
                            else if (attr is SCM.DescriptionAttribute descriptionAttribute)
                            {
                                if (!string.IsNullOrEmpty(propAttrs.Description))
                                {
                                    descriptionAttribute.DescriptionValue = propAttrs.Description;
                                }
                            }
                        }
                    }
                }
            }
        }
Example #48
0
        private object GetAttributeValue(object obj, string attributeName)
        {
            Check.Require(obj != null, string.Format(CommonStrings.XMustNotBeNull, "obj"));

            System.ComponentModel.PropertyDescriptorCollection propertyDescriptorCollection =
                System.ComponentModel.TypeDescriptor.GetProperties(obj);

            System.ComponentModel.PropertyDescriptor property =
                propertyDescriptorCollection.Find(attributeName, true);

            if (property == null)
            {
                return(null);
            }

            object attributeObj = property.GetValue(obj);

            return(attributeObj);
        }
Example #49
0
        private void CopyDataFromDataSource()
        {
            int numColumnsInDataSource = 0;

            if (DataSource is System.ComponentModel.ITypedList)
            {
                System.ComponentModel.PropertyDescriptorCollection columnInfo = ((System.ComponentModel.ITypedList)DataSource).GetItemProperties(null);
                numColumnsInDataSource = columnInfo.Count;
                ColumnsCount           = FixedColumns + columnInfo.Count;
                if (RowHeadersVisible)
                {
                    int colIndex = 0;
                    foreach (System.ComponentModel.PropertyDescriptor columnData in columnInfo)
                    {
                        Columns[colIndex++].HeaderText = columnData.DisplayName;
                    } // foreach
                }     // if
            }         // if
            if (DataSource is IList)
            {
                IList data       = DataSource as IList;
                int   _FixedRows = FixedRows;
                RowsCount = _FixedRows + data.Count;
                //First check if there is data
                if (data.Count > 0 && numColumnsInDataSource > 0)
                {
                    int _FixedColumns = FixedColumns;
                    int rowindex      = _FixedRows;
                    foreach (object rowObj in data)
                    {
                        DataRowView rowView = rowObj as DataRowView;
                        if (rowObj != null)
                        {
                            for (int i = 0; i < numColumnsInDataSource; i++)
                            {
                                this[_FixedColumns + i, rowindex].Value = rowView[i];
                            }
                        } // if
                        rowindex++;
                    }     // foreach
                }         // if
            }             // if
        }
Example #50
0
        public static DataTable AsDataTable <T>(this IEnumerable <T> data)
        {
            System.ComponentModel.PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(T));
            var table = new DataTable();

            foreach (PropertyDescriptor prop in properties)
            {
                table.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);
            }
            foreach (T item in data)
            {
                DataRow row = table.NewRow();
                foreach (PropertyDescriptor prop in properties)
                {
                    row[prop.Name] = prop.GetValue(item) ?? DBNull.Value;
                }
                table.Rows.Add(row);
            }
            return(table);
        }
Example #51
0
    public static DataTable ConvertTo <T>(IList <T> list)
    {
        DataTable table      = CreateTable <T>();
        Type      entityType = typeof(T);

        System.ComponentModel.PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(entityType);

        foreach (T item in list)
        {
            DataRow row = table.NewRow();

            foreach (PropertyDescriptor prop in properties)
            {
                row[prop.Name] = prop.GetValue(item);
            }

            table.Rows.Add(row);
        }

        return(table);
    }
Example #52
0
        public static DataTable ToDataTable <T>(this IList <T> list)
        {
            System.ComponentModel.PropertyDescriptorCollection props = System.ComponentModel.TypeDescriptor.GetProperties(typeof(T));
            DataTable table = new DataTable();

            for (int i = 0; i < props.Count; i++)
            {
                System.ComponentModel.PropertyDescriptor prop = props[i];
                table.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);
            }
            object[] values = new object[props.Count];
            foreach (T item in list)
            {
                for (int i = 0; i < values.Length; i++)
                {
                    values[i] = props[i].GetValue(item) ?? DBNull.Value;
                }
                table.Rows.Add(values);
            }
            return(table);
        }
Example #53
0
 protected PropertyDescriptorCollection SortProperties(PropertyDescriptorCollection props, string[] names)
 {
     throw new NotImplementedException();
 }
Example #54
0
        private void mcPropertyGrid1_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
        {
            string sid   = string.Empty;
            string value = string.Empty;

            System.ComponentModel.PropertyDescriptorCollection collection = null;

            if (e.ChangedItem.PropertyDescriptor != null)
            {
                if (e.ChangedItem.PropertyDescriptor.Name.Equals("DesigeCaption", StringComparison.OrdinalIgnoreCase) == true)
                {
                    value = (e.ChangedItem.Value == null ? string.Empty : e.ChangedItem.Value.ToString());
                    if (string.IsNullOrWhiteSpace(value) == false)
                    {
                        sid = DesignSetMsgId(value);
                    }
                    else
                    {
                        sid = string.Empty;
                    }

                    foreach (object obj in this.SelectedObjects)
                    {
                        collection = System.ComponentModel.TypeDescriptor.GetProperties(obj);
                        foreach (PropertyDescriptor v in collection)
                        {
                            if (v.Name.Equals("MessageCode", StringComparison.OrdinalIgnoreCase) == true)
                            {
                                v.SetValue(obj, sid);
                            }
                        }
                        if (obj is XmlRow)
                        {
                            ((XmlRow)obj).MessageCode            = sid;
                            ((XmlRow)obj).RowView["MessageCode"] = sid;
                            ((XmlRow)obj).RowView.EndEdit();
                        }
                        else if (obj is KzxLookUpColumnInfo)
                        {
                        }
                    }
                    this.Refresh();
                }
                else if (e.ChangedItem.PropertyDescriptor.Name.Equals("Caption", StringComparison.OrdinalIgnoreCase) == true)
                {
                    value = (e.ChangedItem.Value == null ? string.Empty : e.ChangedItem.Value.ToString());
                    if (string.IsNullOrWhiteSpace(value) == false)
                    {
                        sid = DesignSetMsgId(value);
                    }
                    else
                    {
                        sid = string.Empty;
                    }

                    foreach (object obj in this.SelectedObjects)
                    {
                        collection = System.ComponentModel.TypeDescriptor.GetProperties(obj);
                        foreach (PropertyDescriptor v in collection)
                        {
                            if (v.Name.Equals("MessageCode", StringComparison.OrdinalIgnoreCase) == true)
                            {
                                v.SetValue(obj, sid);
                            }
                        }
                    }

                    this.Refresh();
                }
            }
        }
 public PropertyDescriptorEnumerator(PropertyDescriptorCollection owner)
 {
     this.owner = owner;
 }
Example #56
0
        public override bool ValidValue(object dataValue)
        {
            Check.Require(dataValue != null, string.Format(CommonStrings.XMustNotBeNull, "dataValue"));
            IRmType rmType = dataValue as IRmType;

            Check.Require(rmType != null, string.Format(AmValidationStrings.ValueMustImplementIRmType, dataValue.GetType().ToString()));

            bool result = true;

            rmType.Constraint = this;

            if (!IsSameRmType(rmType))
            {
                result = false;
                ValidationContext.AcceptValidationError(this, string.Format(AmValidationStrings.IncorrectRmType, RmTypeName, rmType.GetRmTypeName()));
            }

            if (!result || !AnyAllowed())
            {
                OpenEhr.RM.Common.Archetyped.Impl.Locatable locatable = dataValue as OpenEhr.RM.Common.Archetyped.Impl.Locatable;

                if (locatable != null)
                {
                    ValidationUtility.PopulateLocatableAttributes(this, locatable);

                    if (Parent != null && ArchetypeNodeId != locatable.ArchetypeNodeId)
                    {
                        result = false;
                        ValidationContext.AcceptValidationError(this, string.Format(AmValidationStrings.IncorrectNodeId, ArchetypeNodeId, locatable.ArchetypeNodeId));
                    }
                }

                System.ComponentModel.PropertyDescriptorCollection propertyDescriptorCollection = System.ComponentModel.TypeDescriptor.GetProperties(dataValue);

                if (Attributes != null)
                {
                    foreach (CAttribute cAttribute in Attributes)
                    {
                        object attributeObject = null;
                        string attributeName   = RmFactory.GetOpenEhrV1RmName(cAttribute.RmAttributeName);
                        System.ComponentModel.PropertyDescriptor property = propertyDescriptorCollection.Find(attributeName, true);

                        // if the attributeName is not a class property, it must be a class function.
                        if (property == null)
                        {
                            System.Reflection.MethodInfo method = dataValue.GetType().GetMethod(attributeName);

                            if (method == null)
                            {
                                result = false;
                                ValidationContext.AcceptValidationError(this, string.Format(AmValidationStrings.UnexpectedAttributeX, attributeName));
                                continue;
                            }
                            else
                            {
                                attributeObject = method.Invoke(dataValue, null);
                            }
                        }
                        else
                        {
                            attributeObject = property.GetValue(dataValue);
                        }

                        if (attributeObject == null)
                        {
                            if (cAttribute.Existence.Lower > 0)
                            {
                                result = false;
                                ValidationContext.AcceptValidationError(this, string.Format(AmValidationStrings.TmExpectedConstraintMissing, cAttribute.RmAttributeName));
                            }
                        }
                        else if (cAttribute.Existence.Upper == 0)
                        {
                            result = false;
                            ValidationContext.AcceptValidationError(this, string.Format(AmValidationStrings.TmForbiddenConstraint, cAttribute.RmAttributeName));
                        }
                        else if (!cAttribute.ValidValue(attributeObject))
                        {
                            result = false;
                        }
                        else
                        {
                            DvCodedText codedText = dataValue as DvCodedText;

                            if (codedText != null && cAttribute.RmAttributeName == "defining_code")
                            {
                                // validate the code string before validating the coded value
                                if (codedText.DefiningCode.TerminologyId.Value == "local")
                                {
                                    CObject        parentObject   = cAttribute.parent;
                                    CArchetypeRoot cArchetypeRoot = ValidationUtility.GetCArchetypeRoot(parentObject);

                                    if (!cArchetypeRoot.TermDefinitions.HasKey(codedText.DefiningCode.CodeString))
                                    {
                                        result = false;
                                        string code = codedText.DefiningCode == null ? "" : codedText.DefiningCode.CodeString;
                                        ValidationContext.AcceptValidationError(this, string.Format("code {0} is not existing archetype term", code));
                                    }
                                }
                                if (result && !ValidationUtility.ValidValueTermDef(codedText, cAttribute, ValidationContext.TerminologyService))
                                {
                                    result = false;
                                    string code = codedText.DefiningCode == null ? "" : codedText.DefiningCode.CodeString;
                                    ValidationContext.AcceptValidationError(this, string.Format(AmValidationStrings.TextValueXInvalidForCodeY, codedText.Value, code));
                                }
                            }
                        }
                    }
                }
            }

            return(result);
        }
Example #57
0
        public static object GetPropertyValue(System.ComponentModel.PropertyDescriptorCollection properties, object obj, string property)
        {
            var value = properties.GetPropertyValue(property);

            return(value);
        }
Example #58
0
 protected PropertyDescriptorCollection SortProperties(PropertyDescriptorCollection props, string[] names)
 {
     props.Sort(names);
     return(props);
 }
Example #59
0
//<snippet1>
    private void AddCustomDataTableStyle()
    {
        DataGridTableStyle ts1 = new DataGridTableStyle();

        ts1.MappingName = "Customers";
        // Set other properties.
        ts1.AlternatingBackColor = Color.LightGray;

        /* Add a GridColumnStyle and set its MappingName
         * to the name of a DataColumn in the DataTable.
         * Set the HeaderText and Width properties. */

        DataGridColumnStyle boolCol = new DataGridBoolColumn();

        boolCol.MappingName = "Current";
        boolCol.HeaderText  = "IsCurrent Customer";
        boolCol.Width       = 150;
        ts1.GridColumnStyles.Add(boolCol);

        // Add a second column style.
        DataGridColumnStyle TextCol = new DataGridTextBoxColumn();

        TextCol.MappingName = "custName";
        TextCol.HeaderText  = "Customer Name";
        TextCol.Width       = 250;
        ts1.GridColumnStyles.Add(TextCol);

        // Create the second table style with columns.
        DataGridTableStyle ts2 = new DataGridTableStyle();

        ts2.MappingName = "Orders";

        // Set other properties.
        ts2.AlternatingBackColor = Color.LightBlue;

        // Create new ColumnStyle objects.
        DataGridColumnStyle cOrderDate =
            new DataGridTextBoxColumn();

        cOrderDate.MappingName = "OrderDate";
        cOrderDate.HeaderText  = "Order Date";
        cOrderDate.Width       = 100;
        ts2.GridColumnStyles.Add(cOrderDate);

        /*Use a PropertyDescriptor to create a formatted
         * column. First get the PropertyDescriptorCollection
         * for the data source and data member. */
        System.ComponentModel.PropertyDescriptorCollection pcol =
            this.BindingContext[myDataSet, "Customers.custToOrders"]
            .GetItemProperties();

        /* Create a formatted column using a PropertyDescriptor.
         * The formatting character "c" specifies a currency format. */
        DataGridColumnStyle csOrderAmount =
            new DataGridTextBoxColumn(pcol["OrderAmount"], "c", true);

        csOrderAmount.MappingName = "OrderAmount";
        csOrderAmount.HeaderText  = "Total";
        csOrderAmount.Width       = 100;
        ts2.GridColumnStyles.Add(csOrderAmount);

        /* Add the DataGridTableStyle instances to
         * the GridTableStylesCollection. */
        myDataGrid.TableStyles.Add(ts1);
        myDataGrid.TableStyles.Add(ts2);
    }