Esempio n. 1
0
        private static bool ComputePropertyVisibility(PropertyInfo propertyInfo, bool bypassParam, VisibilityLevel visibilityLevel)
        {
            bool isVisible = false;
            var hiddenAttribute = propertyInfo.GetCustomAttribute(typeof(HiddenWhenAttribute));
            var visibilityByPassAttribute = propertyInfo.GetCustomAttribute(typeof(VisibilityByPassAttribute));

            if (visibilityByPassAttribute == null && hiddenAttribute == null) // no attribute = keep in any case
            {
                isVisible = true;
            }
            else if (visibilityByPassAttribute != null && bypassParam)  // bypass attribute + bypassParam = keep
            {
                isVisible = true;
            }
            else if (hiddenAttribute != null)
            {
                HiddenWhenAttribute hiddenLevels = hiddenAttribute as HiddenWhenAttribute;
                if (hiddenLevels != null)
                {
                    if (!hiddenLevels.Levels.Contains(visibilityLevel))
                        isVisible = true;
                }
            }
            else
            {
                isVisible = false;
            }
            return isVisible;
        }
Esempio n. 2
0
        public Column(PropertyInfo prop)
        {
            Setter = prop.ToSetter();

            var rowNumberAttr = prop.GetCustomAttribute<RowNumberAttribute>();
            IsRowNumber = rowNumberAttr != null;

            var columnAttr = prop.GetCustomAttribute<ColumnAttribute>();
            Name = columnAttr == null ? prop.Name : columnAttr.Name;
            AccessName = prop.Name;

            NotAllowedEmpty = prop.GetCustomAttribute<AllowedEmptyAttribute>() == null;

            var indexedAttr = prop.GetCustomAttribute<IndexedColumnAttribute>();
            if (indexedAttr != null)
            {
                IndexedNames = indexedAttr.Indexes.Select(x => Name + x).ToList();
            }

            if (IndexedNames == null) ColumnType = Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType;
            else
            {
                var type = Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType;
                ColumnType = type.GenericTypeArguments[0];
            }
        }
        /// <summary>
        /// Initializes a new instance of the TsProperty class with the specific CLR property.
        /// </summary>
        /// <param name="memberInfo">The CLR property represented by this instance of the TsProperty.</param>
        public TsProperty(PropertyInfo memberInfo)
        {
            this.MemberInfo = memberInfo;
            this.Name = memberInfo.Name;

            var propertyType = memberInfo.PropertyType;
            if (propertyType.IsNullable()) {
                propertyType = propertyType.GetNullableValueType();
            }

            this.GenericArguments = propertyType.IsGenericType ? propertyType.GetGenericArguments().Select(o => new TsType(o)).ToArray() : new TsType[0];

            this.PropertyType = propertyType.IsEnum ? new TsEnum(propertyType) : new TsType(propertyType);

            var attribute = memberInfo.GetCustomAttribute<TsPropertyAttribute>(false);
            if (attribute != null) {
                if (!string.IsNullOrEmpty(attribute.Name)) {
                    this.Name = attribute.Name;
                }

                this.IsOptional = attribute.IsOptional;
            }

            this.IsIgnored = (memberInfo.GetCustomAttribute<TsIgnoreAttribute>(false) != null);

            // Only fields can be constants.
            this.ConstantValue = null;
        }
 public OptionPropertyValue(PropertyInfo propertyInfo, object owner)
 {
     _propertyInfo = propertyInfo;
     _owner = owner;
     _displayName = _propertyInfo.GetCustomAttribute<DisplayNameAttribute>();
     _description = _propertyInfo.GetCustomAttribute<DescriptionAttribute>();
 }
Esempio n. 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BooleanFieldMetadata"/> class.
 /// </summary>
 /// <param name="declaringProcess">
 /// The declaring process.
 /// </param>
 /// <param name="editProperty">
 /// The editable root property info.
 /// </param>
 /// <param name="infoProperty">
 /// The info class property info.
 /// </param>
 public BooleanFieldMetadata(IProcessMetadata declaringProcess, PropertyInfo editProperty, PropertyInfo infoProperty)
     : base(declaringProcess, editProperty, infoProperty)
 {
     var isSwitchToggleAttribute = editProperty.GetCustomAttribute<IsSwitchToggleAttribute>(false);
     _isSwitchToggle = isSwitchToggleAttribute != null && true.Equals(isSwitchToggleAttribute.Value);
     _undefinedLabelAttribute = editProperty.GetCustomAttribute<UndefinedLabelAttribute>(false);
     _falseLabelAttribute = editProperty.GetCustomAttribute<FalseLabelAttribute>(false);
     _trueLabelAttribute = editProperty.GetCustomAttribute<TrueLabelAttribute>(false);
     _mainLabelAttribute = editProperty.GetCustomAttribute<MainLabelAttribute>(false);
 }
            public PropertyProxy(PropertyInfo pi, object target)
            {
                Name = pi.GetCustomAttribute<DisplayNameAttribute>(false)?.DisplayName ?? pi.Name;
                Description = pi.GetCustomAttribute<DescriptionAttribute>(false)?.Description ?? "";
                Order = pi.GetCustomAttribute<OrderAttribute>(false)?.Order ?? int.MaxValue;
                Visible = pi.GetCustomAttribute<VisibleAttribute>(false)?.Visible ?? true;

                Property = pi;
                Target = target;
                RegisterPropertyChanged();
            }
Esempio n. 7
0
        public PropertyMap(PropertyInfo propertyInfo)
        {
            this.PropertyInfo = propertyInfo;
            this.Ignored = propertyInfo.GetCustomAttribute<NotMappedAttribute>() != null;
            this.IsKey = propertyInfo.GetCustomAttribute<KeyAttribute>() != null;

            var columnAttribute = propertyInfo.GetCustomAttribute<ColumnAttribute>();
            this.ColumnName = columnAttribute?.Name ?? PropertyInfo.Name;

            var databaseGeneratedAttribute = propertyInfo.GetCustomAttribute<DatabaseGeneratedAttribute>();
            this.DatabaseGeneratedOption = databaseGeneratedAttribute?.DatabaseGeneratedOption ?? DatabaseGeneratedOption.None;
        }
Esempio n. 8
0
        public static Property CreatePropertyObject(PropertyInfo propInfo, out Dictionary<string, Structure> structures)
        { 
            structures = new Dictionary<string, Structure>();

            Property result = new VSPlugin.Property();

            string itemsType = "";
            Structure structure = null;

            // we need to verify if we have a structure in this property
            StructureAttribute structureAttribute = propInfo.GetCustomAttribute<StructureAttribute>();
            if (structureAttribute != null)
                result.Type = structureAttribute.Type;
            else
                result.Type = Utility.HandleProperty(propInfo, out itemsType, out structure);

            if (!string.IsNullOrEmpty(itemsType))
            {
                result.Items = new ArraySchema();
                result.Items.Type = itemsType;
            }
            if (structure != null)
                structures.Add(propInfo.PropertyType.Name, structure);

            PropertyAttribute propAttrib = propInfo.GetCustomAttribute<PropertyAttribute>();
            if (propAttrib == null)
                return result;

            result.Description = propAttrib.Description;
            result.Required = propAttrib.Required;
            result.Readonly = propAttrib.ReadOnly;
            result.Final = propAttrib.Final;
            result.Encrypted = propAttrib.Encrypted;
            result.Unit = propAttrib.Unit;
            result.Default = propAttrib.Default;
            result.Format = propAttrib.Format;
            result.Pattern = propAttrib.Pattern;
            result.Title = propAttrib.Title;
            result.Headline = propAttrib.Headline;
            result.MinLength = propAttrib.MinLength;
            result.MaxLength = propAttrib.MaxLength;
            result.MinItems = propAttrib.MinItems;
            result.MaxItems = propAttrib.MaxItems;
            result.UniqueItems = propAttrib.UniqueItems;
            result.EnumValues = propAttrib.Enum;
            result.EnumTitles = propAttrib.EnumTitles;

            result.Access = Access.GetAccess(propInfo);

            return result;
        }
        /// <summary>Gets the name of the property for JSON serialization.</summary>
        /// <param name="property">The property.</param>
        /// <returns>The name.</returns>
        public static string GetPropertyName(PropertyInfo property)
        {
            var jsonPropertyAttribute = property.GetCustomAttribute<JsonPropertyAttribute>();
            if (jsonPropertyAttribute != null && !string.IsNullOrEmpty(jsonPropertyAttribute.PropertyName))
                return jsonPropertyAttribute.PropertyName;

            if (property.DeclaringType.GetTypeInfo().GetCustomAttribute<DataContractAttribute>() != null)
            {
                var dataMemberAttribute = property.GetCustomAttribute<DataMemberAttribute>();
                if (dataMemberAttribute != null && !string.IsNullOrEmpty(dataMemberAttribute.Name))
                    return dataMemberAttribute.Name;
            }

            return property.Name;
        }
Esempio n. 10
0
        private static string GetFieldType(PropertyInfo property)
        {
            var dataTypeAttrib = property.GetCustomAttribute<DataTypeAttribute>();

            if (dataTypeAttrib == null)
                return null;

            switch (dataTypeAttrib.DataType)
            {
                case DataType.Date:
                    return "date";
                case DataType.DateTime:
                    return "datetime";
                case DataType.EmailAddress:
                    return "email";
                case DataType.ImageUrl:
                    return "image";
                case DataType.Password:
                    return "password";
                case DataType.Time:
                    return "time";
                case DataType.Upload:
                    return "file";

                default:
                    return typeof(HttpPostedFileBase).IsAssignableFrom(property.PropertyType) ? "file" : "text";
            }
        }
Esempio n. 11
0
        private static LocalizationInfo GetLocalizationInfo(PropertyInfo prop)
        {
            var attr = prop.GetCustomAttribute<LocalizeAttribute>();
            if(attr == null)
            {
                return null;
            }
            var info = new LocalizationInfo
            {
                ResourceName = attr.ResourceName ?? (prop.DeclaringType.Name + "_" + prop.Name)
            };

            if(info.ResourceType != null)
            {
                info.ResourceType = attr.ResourceType;
            }
            else
            {
                var parent = prop.DeclaringType.GetTypeInfo().GetCustomAttribute<LocalizeAttribute>();
                if(parent == null || parent.ResourceType == null)
                {
                    throw new ArgumentException(String.Format(
                        "The property '{0}' or its parent class '{1}' must define a ResourceType in order to be localized.",
                        prop.Name, prop.DeclaringType.Name));
                }
                info.ResourceType = parent.ResourceType;
            }

            return info;
        }
Esempio n. 12
0
        /// <summary>
        /// Creates one instance of the Relation Object from the PropertyInfo object of the reflected class
        /// </summary>
        /// <param name="propInfo"></param>
        /// <returns></returns>
        public static Relation CreateRelationObject(PropertyInfo propInfo)
        {
            Relation result = new VSPlugin.Relation();

            // get's the Relation Attribute in the class
            RelationAttribute relationAttribute = propInfo.GetCustomAttribute<RelationAttribute>();

            if (relationAttribute== null)
                return result;

            Type elementType = null;
            //we need to discover the id of the relation and if it's a collection
            if (propInfo.PropertyType.IsArray)
            {
                result.Collection = true;

                elementType = propInfo.PropertyType.GetElementType();
            }
            else if(propInfo.PropertyType.IsGenericType && propInfo.PropertyType.GetGenericTypeDefinition() == typeof(List<>))
            {
                result.Collection = true;

                elementType = propInfo.PropertyType.GetGenericArguments().Single();
            }
            else
                elementType = propInfo.PropertyType;

            result.Type = GetResourceType(elementType);
            result.Required = relationAttribute.Required;
            result.Requirement = relationAttribute.Requirement;
            result.Allocate = relationAttribute.Allocate.ToString();

            return result;
        }
Esempio n. 13
0
 public static TableFieldInfo Build(string tableName, PropertyInfo pi, IFieldHandlerFactory fieldHandlerFactory)
 {
     var fieldHandler = fieldHandlerFactory.CreateFromType(pi.PropertyType, FieldHandlerOptions.None);
     if (fieldHandler == null) throw new BTDBException(string.Format("FieldHandlerFactory did not build property {0} of type {2} in {1}", pi.Name, tableName, pi.PropertyType.FullName));
     var a = pi.GetCustomAttribute<PersistedNameAttribute>();
     return new TableFieldInfo(a != null ? a.Name : pi.Name, fieldHandler);
 }
Esempio n. 14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NumericFieldMetadata"/> class.
        /// </summary>
        /// <param name="declaringProcess">
        /// The declaring process.
        /// </param>
        /// <param name="editProperty">
        /// The editable root property info.
        /// </param>
        /// <param name="infoProperty">
        /// The info class property info.
        /// </param>
        public NumericFieldMetadata(IProcessMetadata declaringProcess, PropertyInfo editProperty, PropertyInfo infoProperty)
            : base(declaringProcess, editProperty, infoProperty)
        {
            var fieldTypeAttribute = editProperty.GetCustomAttribute<FieldTypeAttribute>(false);
            if (fieldTypeAttribute == null)
                throw new ArgumentException("FieldType attribute not found.");

            _columnType = fieldTypeAttribute.ColumnType;

            var numericAttribute = editProperty.GetCustomAttribute<NumericAttribute>(false);
            if (numericAttribute != null)
            {
                _numericType = numericAttribute.NumericType;
                _decimalDigits = numericAttribute.NumberOfDigits;
            }
        }
        private SchemaInfo FromPropertyInfo(PropertyInfo pi)
        {
            if (!this.IsMapped(pi))
                return null;

            Type propertyType = pi.PropertyType;

            bool nullableTypeDetected = propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == CachedTypes.PureNullableType;

            SchemaInfo schema = new SchemaInfo(pi.Name, nullableTypeDetected ? propertyType.GetGenericArguments()[0] : propertyType);

            //NotMapped gibi bir standart
            KeyAttribute keyAtt = pi.GetCustomAttribute<KeyAttribute>();
            if (null != keyAtt)
                schema.IsKey = true;

            if (nullableTypeDetected)
                schema.IsNullable = true;
            else
            {
                if (propertyType.IsClass)
                    schema.IsNullable = true;
                else if (propertyType.IsValueType)
                    schema.IsNullable = false;
            }

            bool hasSetMethod = pi.GetSetMethod() != null;
            if (!hasSetMethod)
                schema.ReadOnly = true;

            this.SetExtendedSchema(schema, pi);

            return schema;
        }
Esempio n. 16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ChecklistFieldMapping"/> class.
        /// </summary>
        /// <param name="property">
        /// The property.
        /// </param>
        /// <param name="valueExpression">
        /// The value expression.
        /// </param>
        /// <param name="childMappings">
        /// The child mappings.
        /// </param>
        /// <param name="dynamicTypeManager">
        /// The dynamic type manager.
        /// </param>
        public ChecklistFieldMapping(
            PropertyInfo property,
            MappingExpression valueExpression,
            IEnumerable<IProcessFieldMapping> childMappings,
            IDynamicTypeManager dynamicTypeManager)
        {
            if (property == null)
                throw new ArgumentNullException("property");

            var checklistAttribute = property.GetCustomAttribute<ChecklistFieldAttribute>();
            if (checklistAttribute == null)
                throw new ArgumentException("The specified property is not a checklist field.");

            if (childMappings == null)
                throw new ArgumentNullException("childMappings");

            var childMappingsArray = childMappings.ToArray();
            if (childMappingsArray.All(m => !m.IsKey))
                throw new ArgumentException("At least one key field should be specified.");

            if (dynamicTypeManager == null)
                throw new ArgumentNullException("dynamicTypeManager");

            _property = property;
            _valueExpression = valueExpression;
            _childMappings = childMappingsArray;
            _dynamicTypeManager = dynamicTypeManager;
            _answerProcessName = checklistAttribute.AnswerProcessName;
        }
        private PropertyFormat ConvertToPropertyFormat(PropertyInfo property)
        {
            var getMethod = property.GetGetMethod(false);
            if (getMethod == null) return null;
            var format = property.GetCustomAttribute<FormatInfoAttribute>(true);
            PropertyFormat result = null;

            if (formatInfoProvider != null)
                result = formatInfoProvider.GetFormat(property);

            if (result == null) result = new PropertyFormat();

            if (string.IsNullOrEmpty(result.Title)) result.Title = property.Name;
            if (string.IsNullOrEmpty(result.Format)) result.Format = "{0}";
            if (result.Order <= 0) result.Order = int.MaxValue;
            if (!Enum.IsDefined(typeof(PropertyDisplay), result.Display)) result.Display = PropertyDisplay.Inline;

            if (format != null)
            {
                if (!string.IsNullOrEmpty(format.Title)) result.Title = format.Title;
                if (!string.IsNullOrEmpty(format.Format)) result.Format = format.Format;
                if (format.Order > 0) result.Order = format.Order;
                if (Enum.IsDefined(typeof(PropertyDisplay), format.Display)) result.Display = format.Display;
            }
            result.Get = getMethod;
            return result;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MultiCrossReferenceFieldMapping"/> class.
        /// </summary>
        /// <param name="property">
        /// The property.
        /// </param>
        /// <param name="valueExpression">
        /// The value expression.
        /// </param>
        /// <param name="childMappings">
        /// The child mappings.
        /// </param>
        /// <param name="dynamicTypeManager">
        /// The dynamic type manager.
        /// </param>
        /// <param name="runtimeDatabase">
        /// The runtime database.
        /// </param>
        public MultiCrossReferenceFieldMapping(
            PropertyInfo property,
            MappingExpression valueExpression,
            IEnumerable<IProcessFieldMapping> childMappings,
            IDynamicTypeManager dynamicTypeManager,
            IRuntimeDatabase runtimeDatabase)
        {
            if (property == null)
                throw new ArgumentNullException("property");

            var crAttribute = property.GetCustomAttribute<CrossRefFieldAttribute>();
            if (crAttribute == null || !crAttribute.AllowMultiple)
                throw new ArgumentException("The specified property is not a multi cross reference field.");

            if (childMappings == null)
                throw new ArgumentNullException("childMappings");

            var childMappingsArray = childMappings.ToArray();
            if (childMappingsArray.All(m => !m.IsKey))
                throw new ArgumentException("At least one key field should be specified.");

            if (dynamicTypeManager == null)
                throw new ArgumentNullException("dynamicTypeManager");

            if (runtimeDatabase == null)
                throw new ArgumentNullException("runtimeDatabase");

            _property = property;
            _valueExpression = valueExpression;
            _childMappings = childMappingsArray;
            _dynamicTypeManager = dynamicTypeManager;
            _runtimeDatabase = runtimeDatabase;
            _referencedProcessName = crAttribute.ReferenceTableName;
        }
Esempio n. 19
0
        /// <summary>
        /// .ctor
        /// </summary>
        /// <param name="owner">Metadata of the owning entity.</param>
        /// <param name="propertyInfo">PropertyInfo of the accessed  entity property.</param>
        public TikEntityPropertyAccessor(TikEntityMetadata owner, PropertyInfo propertyInfo)
        {
            _owner = owner;

            PropertyInfo = propertyInfo;

            //From property code
            PropertyName = propertyInfo.Name;
            PropertyType = propertyInfo.PropertyType;

            //From TikPropertyAttribute attribute
            var propertyAttribute = propertyInfo.GetCustomAttribute<TikPropertyAttribute>(true);
            if (propertyAttribute == null)
                throw new ArgumentException("Property must be decorated by TikPropertyAttribute.", "propertyInfo");
            FieldName = propertyAttribute.FieldName;
            _isReadOnly = (propertyInfo.GetSetMethod() == null) || (!propertyInfo.CanWrite) || (propertyAttribute.IsReadOnly);
            IsMandatory = propertyAttribute.IsMandatory;
            if (propertyAttribute.DefaultValue != null)
                DefaultValue = propertyAttribute.DefaultValue;
            else
            {
                if (PropertyType.IsValueType)
                    DefaultValue = ConvertToString(Activator.CreateInstance(PropertyType)); //default value of value type. for example: (default)int
                else
                    DefaultValue = "";
            }
            UnsetOnDefault = propertyAttribute.UnsetOnDefault;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SingleCrossReferenceFieldMapping"/> class.
        /// </summary>
        /// <param name="property">
        /// The property.
        /// </param>
        /// <param name="valueExpression">
        /// The value expression.
        /// </param>
        /// <param name="isKey">
        /// Specifies whether this is a key mapping.
        /// </param>
        /// <param name="typeConverter">
        /// The type converter.
        /// </param>
        /// <param name="dynamicTypeManager">
        /// The dynamic type manager.
        /// </param>
        /// <param name="runtimeDatabase">
        /// The runtime database.
        /// </param>
        /// <param name="childMappings">
        /// The child mappings.
        /// </param>
        public SingleCrossReferenceFieldMapping(
            PropertyInfo property,
            MappingExpression valueExpression,
            bool isKey,
            ITypeConverter typeConverter,
            IDynamicTypeManager dynamicTypeManager,
            IRuntimeDatabase runtimeDatabase,
            IEnumerable<IProcessFieldMapping> childMappings)
        {
            if (property == null)
                throw new ArgumentNullException("property");

            var crAttribute = property.GetCustomAttribute<CrossRefFieldAttribute>();
            if (crAttribute == null || crAttribute.AllowMultiple || !typeof(int?).IsAssignableFrom(property.PropertyType))
                throw new ArgumentException("The specified property is not a single cross reference field.");

            if (typeConverter == null)
                throw new ArgumentNullException("typeConverter");

            if (dynamicTypeManager == null)
                throw new ArgumentNullException("dynamicTypeManager");

            if (runtimeDatabase == null)
                throw new ArgumentNullException("runtimeDatabase");

            _property = property;
            _valueExpression = valueExpression;
            _isKey = isKey;
            _typeConverter = typeConverter;
            _dynamicTypeManager = dynamicTypeManager;
            _runtimeDatabase = runtimeDatabase;
            _childMappings = (childMappings ?? Enumerable.Empty<IProcessFieldMapping>()).ToArray();
            _referencedProcessName = crAttribute.ReferenceTableName;
        }
Esempio n. 21
0
        public Tuple <bool, string> IsValid(object value, object instance, System.Reflection.PropertyInfo property)
        {
            string strValue = String.Empty;

            if (value != null)
            {
                strValue = value.ToString();
            }


            var validName = property.GetCustomAttribute <ValidNameAttribute>();

            if (validName != null && !String.IsNullOrWhiteSpace(this.ErrorMessage))
            {
                this.ErrorMessage = String.Format(this.ErrorMessage, validName.Name);
            }

            var isMatch = this._regex.IsMatch(strValue);

            if (isMatch)
            {
                return(this.ReturnTrue());
            }
            return(this.ReturnFalse());
        }
        public Tuple <bool, string> IsValid(object value, object instance, System.Reflection.PropertyInfo property)
        {
            if (value == null)
            {
                return(this.ReturnTrue());
            }


            var validName = property.GetCustomAttribute <ValidNameAttribute>();

            if (validName != null && !String.IsNullOrWhiteSpace(this.ErrorMessage))
            {
                this.ErrorMessage = String.Format(this.ErrorMessage, validName.Name);
            }
            try
            {
                double dblValue = (double)Convert.ChangeType(value, typeof(double));
                if (dblValue < this._min || dblValue > this._max)
                {
                    return(this.ReturnFalse());
                }
                return(this.ReturnTrue());
            }
            catch { return(this.ReturnFalse()); }
        }
        /// <summary>
        ///     Requires that the bound property has two options in order to bind properly.
        /// </summary>
        public TwoRadioOptionsControl(PropertyInfo property)
        {
            InitializeComponent();

            // Knowing the property info allows us to dynamically generarte the available options based on the class attributes
            // and bind the results to a specified type

            BoundProperty = property;

            var parameterAttribute = BoundProperty.GetCustomAttribute<ItemConditionParameterAttribute>();

            if (parameterAttribute == null)
                throw new Exception(
                    "Invalid Property Type Passed to TwoRadioOptionsControl. Ensure that the property contains an ItemConditionParameterAttribute with two options present.");

            if (parameterAttribute.Options == null || parameterAttribute.Options.Count() != 2)
                throw new Exception(
                    "Invalid Property Type Passed to TwoRadioOptionsControl. Ensure that the property contains an ItemConditionParameterAttribute with two options present.");

            BoundOptions = parameterAttribute.Options;

            ValueLabel.Text = string.IsNullOrEmpty(parameterAttribute.Name) ? property.Name : parameterAttribute.Name;

            OptionOneRadioButton.Text = parameterAttribute.Options[0].Name;
            OptionTwoRadioButton.Text = parameterAttribute.Options[1].Name;
        }
 protected bool IsPropertyIncluded(PropertyInfo property) {
     if (property.GetCustomAttribute<NakedObjectsIgnoreAttribute>() != null) return false;
     var attr = property.DeclaringType.GetCustomAttribute<NakedObjectsTypeAttribute>();
     if (attr == null) return true;
     switch (attr.ReflectionScope) {
         case ReflectOver.All:
             return true; //Because we checked for NakedObjectsIgnore earlier.
         case ReflectOver.TypeOnlyNoMembers:
             return false;
         case ReflectOver.ExplicitlyIncludedMembersOnly:
             return property.GetCustomAttribute<NakedObjectsIncludeAttribute>() != null;
         case ReflectOver.None:
             throw new ReflectionException("Attempting to introspect a class that has been marked with NakedObjectsType with ReflectOver.None");
         default:
             throw new ReflectionException(String.Format("Unhandled value for ReflectOver: {0}", attr.ReflectionScope));
     }
 }
Esempio n. 25
0
        private static object GetPropertyDefaultValue(PropertyInfo property)
        {
            var defaultAttribute = property.GetCustomAttribute<DefaultValueAttribute>();

            return defaultAttribute != null
                       ? ((PowerArgs.DefaultValueAttribute)defaultAttribute).Value
                       : property.PropertyType.IsValueType ? Activator.CreateInstance(property.PropertyType) : null;
        }
Esempio n. 26
0
        private static object GetPropertyDefaultValue(PropertyInfo property)
        {
            var defaultAttribute = property.GetCustomAttribute<DefaultValueAttribute>();

            return defaultAttribute != null
                       ? ((PowerArgs.DefaultValueAttribute)defaultAttribute).Value
                       : property.PropertyType.GetDefaultValue();
        }
Esempio n. 27
0
        public FeatureConfigViewModel(PropertyInfo property, FeatureConfiguration config)
        {
            Property = property;

            var desca = property.GetCustomAttribute<DescriptionAttribute>();
            Description = (desca != null ? desca.Description : "");
            Enabled = (bool)property.GetValue(config);
        }
Esempio n. 28
0
        public static FieldInfo Parse(PropertyInfo prop)
        {
            ColumnAttribute colAttr = prop.GetCustomAttribute<ColumnAttribute>(true);
            if (colAttr == null)
                return new FieldInfo { FieldName = prop.Name, PropertyName = prop.Name };

            return new FieldInfo { FieldName = colAttr.Name, PropertyName = prop.Name };
        }
Esempio n. 29
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GenericFieldMetadata"/> class.
        /// </summary>
        /// <param name="declaringProcess">
        /// The declaring process.
        /// </param>
        /// <param name="editProperty">
        /// The editable root property info.
        /// </param>
        /// <param name="infoProperty">
        /// The info class property info.
        /// </param>
        /// <exception cref="ArgumentException">
        /// The <paramref name="editProperty"/> property doesn't have a <see cref="FieldTypeAttribute"/> attribute.
        /// </exception>
        public GenericFieldMetadata(IProcessMetadata declaringProcess, PropertyInfo editProperty, PropertyInfo infoProperty)
            : base(declaringProcess, editProperty, infoProperty)
        {
            var fieldTypeAttribute = editProperty.GetCustomAttribute<FieldTypeAttribute>(false);
            if (fieldTypeAttribute == null)
                throw new ArgumentException("FieldType attribute not found.");

            _columnType = fieldTypeAttribute.ColumnType;
        }
 public override void Process(IReflector reflector, PropertyInfo property, IMethodRemover methodRemover, ISpecificationBuilder specification) {
     if ((property.PropertyType.IsPrimitive || TypeUtils.IsEnum(property.PropertyType)) && property.GetCustomAttribute<OptionallyAttribute>() != null) {
         Log.Warn("Ignoring Optionally annotation on primitive or un-readable parameter on " + property.ReflectedType + "." + property.Name);
         return;
     }
     if (property.GetGetMethod() != null && !property.PropertyType.IsPrimitive) {
         Process(property, specification);
     }
 }
Esempio n. 31
0
 public static string DisplayName(this System.Reflection.PropertyInfo propertyInfo)
 {
     try
     {
         return(((System.ComponentModel.DisplayNameAttribute)propertyInfo.GetCustomAttribute(
                     typeof(System.ComponentModel.DisplayNameAttribute))).DisplayName);
     }
     catch
     {
         return(propertyInfo.Name);
     }
 }
Esempio n. 32
0
        public static PropsAttribute GetProps(this System.Reflection.PropertyInfo i)
        {
            var attribute = i.GetCustomAttribute <PropsAttribute>();

            if (attribute == null && i.GetGetMethod().IsVirtual)
            {
                return(null);
            }
            var            foregnKey    = i.GetCustomAttribute <ForeignKeyAttribute>();
            var            stringLength = i.GetCustomAttribute <StringLengthAttribute>();
            var            require      = i.GetCustomAttribute <RequiredAttribute>();
            PropsAttribute attr;

            if (attribute == null)
            {
                attr = new PropsAttribute(i.Name);
            }
            else
            {
                attr = attribute;
            }

            if (foregnKey != null)
            {
                attr.ForeignTable = attr.ForeignTable ?? foregnKey.Name;
            }
            if (stringLength != null)
            {
                attr.MaxLength = stringLength.MaximumLength;
                attr.MinLength = stringLength.MinimumLength;
            }
            if (require != null)
            {
                attr.Required = true;
            }
            return(attr);
        }
Esempio n. 33
0
            public DataBinderBase(object target, System.Reflection.PropertyInfo property)
            {
                Target          = target;
                Property        = property;
                Label           = new Label();
                Label.AutoSize  = false;
                Label.TextAlign = ContentAlignment.MiddleRight;
                Label.Width     = 80;
                Label.Text      = property.Name + ":";
                Control         = new CONTROL();
                Control.Left    = 90;
                mLabelAttribute = property.GetCustomAttribute <PropertyLabelAttribute>();
                Control.Width   = 500;
                if (mLabelAttribute != null)
                {
                    Label.Text = mLabelAttribute.Name + ":";
                }

                Height = 30;
            }
Esempio n. 34
-1
        public override void RepairValue(PropertyInfo prop, object entity)
        {
            ParameterAttribute attr = (ParameterAttribute)prop.GetCustomAttribute((Type)typeof(ParameterAttribute), (bool)false);

            FieldName = prop.Name;

            try
            {
                ValueMin = CastToType(ValueMin);
            }
            catch (Exception)
            {
                ValueMin = null;
            }

            if (ValueMin == null)
                ValueMin = prop.GetValue(entity);

            try
            {
                ValueMax = CastToType(ValueMax);
            }
            catch (Exception)
            {
                ValueMax = null;
            }

            if (ValueMax == null)
                ValueMax = prop.GetValue(entity);

            DisplayName = (attr.Name == null) ? prop.Name : attr.Name;
            Description = (attr.Description == null) ? "" : attr.Description;
            TypeName = prop.PropertyType.FullName;
        }
        protected override void ValidateProperty(ITag tag, PropertyInfo propertyInfo)
        {
            if (tag == null || propertyInfo == null)
                return;

            var enumType = propertyInfo.GetCustomAttribute<EnumProperyTypeAttribute>();
            if (enumType == null)
                return;

            var value = propertyInfo.GetValue(tag) as ITagAttribute;
            if (!(value?.IsConstant ?? false))
                return;

            var enumValues = enumType.EnumValues.Cast<object>().Select(v => v.ToString().ToLowerInvariant()).ToList();

            var text = value.ConstantValue.ToString();
            var names = enumType.Multiple ? text.Split(enumType.Separator) : new[] { text };
            foreach (var name in names.Select(n => n?.Trim()))
            {
                if (name == enumType.Wildcard)
                    continue;

                if (!enumValues.Contains(name.ToLowerInvariant()))
                    throw InvalidValueException(name, enumType.EnumValues);
            }
        }