示例#1
0
        private static bool InternalIsDefined(PropertyInfo element, Type attributeType, bool inherit)
        {
            // walk up the hierarchy chain
            if (element.IsDefined(attributeType, inherit))
                return true;
            
            if (inherit)
            {
                AttributeUsageAttribute usage = InternalGetAttributeUsage(attributeType);

                if (!usage.Inherited) 
                    return false;

                PropertyInfo baseProp = GetParentDefinition(element);

                while (baseProp != null)
                {
                    if (baseProp.IsDefined(attributeType, false))
                        return true;

                    baseProp = GetParentDefinition(baseProp);
                }
            }

            return false;
        }
		private static bool InternalIsDefined(PropertyInfo element, Type attributeType, bool inherit)
		{
			if (element.IsDefined(attributeType, inherit))
			{
				return true;
			}
			if (inherit)
			{
				AttributeUsageAttribute attributeUsageAttribute = Attribute.InternalGetAttributeUsage(attributeType);
				if (!attributeUsageAttribute.Inherited)
				{
					return false;
				}
				PropertyInfo parentDefinition = Attribute.GetParentDefinition(element);
				while (parentDefinition != null)
				{
					if (parentDefinition.IsDefined(attributeType, false))
					{
						return true;
					}
					parentDefinition = Attribute.GetParentDefinition(parentDefinition);
				}
			}
			return false;
		}
示例#3
0
        private static bool InternalIsDefined(PropertyInfo element, Type attributeType, bool inherit)
        {
            // walk up the hierarchy chain
            if (element.IsDefined(attributeType, inherit))
                return true;
            
            if (inherit)
            {
                AttributeUsageAttribute usage = InternalGetAttributeUsage(attributeType);

                if (!usage.Inherited) 
                    return false;

                //if this is an index we need to get the parameter types to help disambiguate
                Type[] indexParamTypes = GetIndexParameterTypes(element);

                PropertyInfo baseProp = GetParentDefinition(element, indexParamTypes);

                while (baseProp != null)
                {
                    if (baseProp.IsDefined(attributeType, false))
                        return true;

                    baseProp = GetParentDefinition(baseProp, indexParamTypes);
                }
            }

            return false;
        }
示例#4
0
        public static NameType TryGetName(PythonType dt, PropertyInfo pi, MethodInfo prop, out string name) {
            if (pi.IsDefined(typeof(PythonHiddenAttribute), false)) {
                name = null;
                return NameType.None;
            }

            name = pi.Name;

            return GetNameFromMethod(dt, prop, NameType.Property, ref name);
        }
        /// <summary>
        /// Create a new map based on the PropertyInfo provided
        /// </summary>
        /// <param name="property">The object property to create a map for</param>
        /// <exception cref="ArgumentNullException">Thrown when the supplied property is null</exception>
        public ColumnPropertyMap(PropertyInfo property)
        {
            if (property == null)
                throw new ArgumentNullException("The property provided was null");

            if (property.IsDefined(typeof(System.Data.Linq.Mapping.ColumnAttribute), true))
            {
                System.Data.Linq.Mapping.ColumnAttribute column = (System.Data.Linq.Mapping.ColumnAttribute)property.GetCustomAttributes(typeof(System.Data.Linq.Mapping.ColumnAttribute), true)[0];
                this.ColumnName = column.Name.ToUpper();
            }
            else if (property.IsDefined(typeof(System.ComponentModel.DataAnnotations.Schema.ColumnAttribute), true))
            {
                System.ComponentModel.DataAnnotations.Schema.ColumnAttribute column = (System.ComponentModel.DataAnnotations.Schema.ColumnAttribute)property.GetCustomAttributes(typeof(System.ComponentModel.DataAnnotations.Schema.ColumnAttribute), true)[0];
                this.ColumnName = column.Name.ToUpper();
            }

            this.Property = property;
            this.ObjectPropertyType = property.PropertyType;
            this.GetMethod = this.CreateGetMethod();
            this.SetMethod = this.CreateSetMethod();
            this.SQLExists = false;
        }
示例#6
0
 private static bool InternalIsDefined(PropertyInfo element, Type attributeType, bool inherit)
 {
   if (element.IsDefined(attributeType, inherit))
     return true;
   if (inherit && Attribute.InternalGetAttributeUsage(attributeType).Inherited)
   {
     for (PropertyInfo parentDefinition = Attribute.GetParentDefinition(element); parentDefinition != null; parentDefinition = Attribute.GetParentDefinition(parentDefinition))
     {
       if (parentDefinition.IsDefined(attributeType, false))
         return true;
     }
   }
   return false;
 }
        /// <summary>
        /// A property is serializable if:
        /// - it's not marked with any of the 'DontSerializeMember' attributes
        /// - it's an auto-property
        /// - has a public getter or setter, otherwise must be annotated with any of the 'SerializeMember' attributes
        /// - its type is serializable
        /// - static properties that meet the previous requirements are always serialized in Better[Behaviour|ScriptableObject],
        ///   and in System.Objects if the serializer of use supports it (FullSerialier doesn't)
        /// </summary>
        public override bool IsSerializableProperty(System.Reflection.PropertyInfo property)
        {
            foreach (System.Type v_type in DontSerializeMember)
            {
                if (property.IsDefined(v_type, false))
                {
                    return(false);
                }
            }

            if (!property.IsAutoProperty())
            {
                return(false);
            }

            bool v_isSerializableDefined = false;

            foreach (System.Type v_type in SerializeMember)
            {
                if (property.IsDefined(v_type, false))
                {
                    v_isSerializableDefined = true;
                    break;
                }
            }

            if (!(property.GetGetMethod(true).IsPublic ||
                  property.GetSetMethod(true).IsPublic ||
                  v_isSerializableDefined))
            {
                return(false);
            }

            bool serializable = IsSerializableType(property.PropertyType);

            return(serializable);
        }
示例#8
0
        private System.Reflection.PropertyInfo FindStandardValueProperty(object value)
        {
            System.Reflection.PropertyInfo propertyInfo2;

            System.Reflection.PropertyInfo[] propertyInfoArr = StandardType.GetProperties(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
            for (int i = 0; i < propertyInfoArr.Length; i++)
            {
                System.Reflection.PropertyInfo propertyInfo1 = propertyInfoArr[i];
                if (propertyInfo1.IsDefined(typeof(Skybound.ComponentModel.StandardValueAttribute), true) && System.Object.Equals(propertyInfo1.GetValue(null, null), value))
                {
                    return(propertyInfo1);
                }
            }
            return(null);
        }
示例#9
0
 /// <summary>
 /// Set value for a property.
 /// </summary>
 /// <param name="property"></param>
 /// <param name="value"></param>
 private void SetValue(PropertyInfo property, object value)
 {
     //Check for type converter..
     if (property.IsDefined(typeof(TypeConverterAttribute)))
     {
         var converterAttr = property.GetCustomAttribute<TypeConverterAttribute>();
         var converter = Activator.CreateInstance(Type.GetType(converterAttr.ConverterTypeName)) as TypeConverter;
         property.SetValue(this, converter.ConvertFrom(value ?? string.Empty));
     }
     else
     {
         var convert = value.TryConvertTo(property.PropertyType);
         if (convert.Success)
             property.SetValue(this, convert.Result);
     }
 }
示例#10
0
        public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            object obj;

            if (value is string)
            {
                System.Reflection.PropertyInfo[] propertyInfoArr = StandardType.GetProperties(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
                for (int i = 0; i < propertyInfoArr.Length; i++)
                {
                    System.Reflection.PropertyInfo propertyInfo = propertyInfoArr[i];
                    if (propertyInfo.IsDefined(typeof(Skybound.ComponentModel.StandardValueAttribute), true) && GetStandardValueName(propertyInfo) == ((string)value))
                    {
                        return(propertyInfo.GetValue(null, null));
                    }
                }
            }
            return(base.ConvertFrom(context, culture, value));
        }
示例#11
0
 public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context)
 {
     System.Collections.ArrayList     arrayList1      = new System.Collections.ArrayList();
     System.Collections.ArrayList     arrayList2      = new System.Collections.ArrayList();
     System.Reflection.PropertyInfo[] propertyInfoArr = StandardType.GetProperties(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
     for (int i = 0; i < propertyInfoArr.Length; i++)
     {
         System.Reflection.PropertyInfo propertyInfo = propertyInfoArr[i];
         if (propertyInfo.IsDefined(typeof(Skybound.ComponentModel.StandardValueAttribute), true))
         {
             arrayList1.Add(propertyInfo.GetValue(null, null));
             arrayList2.Add(propertyInfo.Name);
         }
     }
     System.Array array = arrayList1.ToArray();
     System.Array.Sort(arrayList2.ToArray(), array);
     return(new System.ComponentModel.TypeConverter.StandardValuesCollection(array));
 }
示例#12
0
        public override object Resolve(PropertyInfo property, object container, MappingContext context)
        {
            var value = base.Resolve(property, container, context);

            if (property.PropertyType != typeof(String))
            {
                return value;
            }

            var localizable = container as ILocalizable;

            if (localizable != null && property.IsDefined(typeof(LocalizableAttribute), false))
            {
                var localizedValue = localizable.GetText(property.Name, context.ApiContext.Culture);
                if (!String.IsNullOrEmpty(localizedValue))
                {
                    return localizedValue;
                }
            }

            return value;
        }
        /// <summary>
        /// This method adds the fields only if they do not already exist in the array
        /// </summary>
        /// <param name="_tableFields"></param>
        /// <param name="propInfo"></param>
        private static void AddDataObjectFieldProperties(List <Adage.EF.Interfaces.BusinessObjectStructure> _tableFields, System.Reflection.PropertyInfo propInfo)
        {
            Adage.EF.Interfaces.BusinessObjectStructure    currStruct;
            System.ComponentModel.DataObjectFieldAttribute dataPropInfo;

            if (propInfo.IsDefined(dataPropType, true))
            {
                bool alreadyContainsProperty = false;
                _tableFields.ForEach(p =>
                                     alreadyContainsProperty = p.Name == propInfo.Name
                    ? true : alreadyContainsProperty);

                if (!alreadyContainsProperty)
                {
                    dataPropInfo = (System.ComponentModel.DataObjectFieldAttribute)Attribute.GetCustomAttribute(propInfo, dataPropType);
                    currStruct   = new Adage.EF.Interfaces.BusinessObjectStructure(
                        propInfo.PropertyType, propInfo.Name, dataPropInfo.IsNullable,
                        dataPropInfo.Length, false, null, propInfo);

                    _tableFields.Add(currStruct);
                }
            }
        }
 /// <inheritdoc/>
 public bool AcceptProperty(PropertyInfo propertyInfo)
 {
     return !propertyInfo.IsDefined(typeof (NonInterceptedAttribute), false);
 }
示例#15
0
        private static Boolean isSkip( PropertyInfo info )
        {
            if (info.IsDefined( typeof( NotSerializeAttribute ), false )) {
                return true;
            }

            if (info.IsDefined( typeof( NotSaveAttribute ), false )) {
                return true;
            }

            return false;
        }
        /// <summary>
        ///     Load the property with scalar property attribute.
        ///     Note that we pass the CLR type in because in the case where the property is declared on a generic
        ///     base class the DeclaringType of propert won't work for us and we need the real entity type instead.
        /// </summary>
        /// <param name="type"> The CLR type of the entity </param>
        /// <param name="property"> Metadata representing the property </param>
        /// <param name="isEntityKeyProperty"> True if the property forms part of the entity's key </param>
        /// <returns> </returns>
        private EdmMember LoadScalarProperty(Type clrType, PropertyInfo property, out bool isEntityKeyProperty)
        {
            Debug.Assert(property.IsDefined(typeof(EdmScalarPropertyAttribute), false), "The property must have a scalar attribute");
            EdmMember member = null;
            isEntityKeyProperty = false;

            // Load the property type and create a new property object
            PrimitiveType primitiveType;

            // If the type could not be loaded it's definitely not a primitive type, so that's an error
            // If it could be loaded but is not a primitive that's an error as well
            if (!TryGetPrimitiveType(property.PropertyType, out primitiveType))
            {
                // This property does not need to be validated further, just add to the errors collection and continue with the next property
                // This failure will cause an exception to be thrown later during validation of all of the types
                SessionData.EdmItemErrors.Add(
                    new EdmItemError(
                        Strings.Validator_OSpace_ScalarPropertyNotPrimitive(
                            property.Name, property.DeclaringType.FullName, property.PropertyType.FullName)));
            }
            else
            {
                var attrs = property.GetCustomAttributes(typeof(EdmScalarPropertyAttribute), false);

                Debug.Assert(attrs.Length == 1, "Every property can exactly have one ScalarProperty Attribute");
                // Expecting EdmScalarPropertyAttribute to have AllowMultiple=False, so only look at first element in the attribute array
                isEntityKeyProperty = ((EdmScalarPropertyAttribute)attrs[0]).EntityKeyProperty;
                var isNullable = ((EdmScalarPropertyAttribute)attrs[0]).IsNullable;

                member = new EdmProperty(
                    property.Name,
                    TypeUsage.Create(
                        primitiveType, new FacetValues
                                           {
                                               Nullable = isNullable
                                           }),
                    property, clrType);
            }
            return member;
        }
        public ProxyOptions GetPropertyMethodOptions( PropertyInfo p, MethodInfo m )
        {
            ProxyOptions opt = new ProxyOptions();
            
            opt.CatchExceptions = _errorCatch == CatchExceptionGeneration.Always 
                || (_errorCatch == CatchExceptionGeneration.HonorIgnoreExceptionAttribute 
                    && !(p.IsDefined( typeof( IgnoreExceptionAttribute ), false ) || m.IsDefined( typeof( IgnoreExceptionAttribute ), false )) );

            if( _isDynamicService )
            {
                bool stopAllowed = p.IsDefined( typeof( IgnoreServiceStoppedAttribute ), false ) || m.IsDefined( typeof( IgnoreServiceStoppedAttribute ), false );
                opt.RuntimeCheckStatus = stopAllowed ? ProxyOptions.CheckStatus.NotDisabled : ProxyOptions.CheckStatus.Running;
            }
            else opt.RuntimeCheckStatus = ProxyOptions.CheckStatus.None;
            return opt;
        }
示例#18
0
		public XmlSetGump( PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, ArrayList list ) : base( GumpOffsetX, GumpOffsetY )
		{
			m_Property = prop;
			m_Mobile = mobile;
			m_Object = o;
			m_Stack = stack;
			m_Page = page;
			m_List = list;

			bool canNull = !prop.PropertyType.IsValueType;
			bool canDye = prop.IsDefined( typeof( HueAttribute ), false );
			bool isBody = prop.IsDefined( typeof( BodyAttribute ), false );

            int xextend = 0;
			if(prop.PropertyType == typeof(string))
			{
			     xextend = 300;
			}

			object val = prop.GetValue( m_Object, null );
			string initialText;

			if ( val == null )
				initialText = "";
			else
				initialText = val.ToString();

			AddPage( 0 );

			AddBackground( 0, 0, BackWidth+xextend, BackHeight + (canNull ? (EntryHeight + OffsetSize) : 0) + (canDye ? (EntryHeight + OffsetSize) : 0) + (isBody ? (EntryHeight + OffsetSize) : 0), BackGumpID );
			AddImageTiled( BorderSize, BorderSize, TotalWidth+xextend - (OldStyle ? SetWidth + OffsetSize : 0), TotalHeight + (canNull ? (EntryHeight + OffsetSize) : 0) + (canDye ? (EntryHeight + OffsetSize) : 0) + (isBody ? (EntryHeight + OffsetSize) : 0), OffsetGumpID );

			int x = BorderSize + OffsetSize;
			int y = BorderSize + OffsetSize;

			AddImageTiled( x, y, EntryWidth+xextend, EntryHeight, EntryGumpID );
			AddLabelCropped( x + TextOffsetX, y, EntryWidth+xextend - TextOffsetX, EntryHeight, TextHue, prop.Name );
			x += EntryWidth+xextend + OffsetSize;

			if ( SetGumpID != 0 )
				AddImageTiled( x, y, SetWidth, EntryHeight, SetGumpID );

			x = BorderSize + OffsetSize;
			y += EntryHeight + OffsetSize;

			AddImageTiled( x, y, EntryWidth+xextend, EntryHeight, EntryGumpID );
			AddTextEntry( x + TextOffsetX, y, EntryWidth+xextend - TextOffsetX, EntryHeight, TextHue, 0, initialText );
			x += EntryWidth+xextend + OffsetSize;

			if ( SetGumpID != 0 )
				AddImageTiled( x, y, SetWidth, EntryHeight, SetGumpID );

			AddButton( x + SetOffsetX, y + SetOffsetY, SetButtonID1, SetButtonID2, 1, GumpButtonType.Reply, 0 );

			if ( canNull )
			{
				x = BorderSize + OffsetSize;
				y += EntryHeight + OffsetSize;

				AddImageTiled( x, y, EntryWidth+xextend, EntryHeight, EntryGumpID );
				AddLabelCropped( x + TextOffsetX, y, EntryWidth+xextend - TextOffsetX, EntryHeight, TextHue, "Null" );
				x += EntryWidth+xextend + OffsetSize;

				if ( SetGumpID != 0 )
					AddImageTiled( x, y, SetWidth, EntryHeight, SetGumpID );

				AddButton( x + SetOffsetX, y + SetOffsetY, SetButtonID1, SetButtonID2, 2, GumpButtonType.Reply, 0 );
			}

			if ( canDye )
			{
				x = BorderSize + OffsetSize;
				y += EntryHeight + OffsetSize;

				AddImageTiled( x, y, EntryWidth+xextend, EntryHeight, EntryGumpID );
				AddLabelCropped( x + TextOffsetX, y, EntryWidth+xextend - TextOffsetX, EntryHeight, TextHue, "Hue Picker" );
				x += EntryWidth+xextend + OffsetSize;

				if ( SetGumpID != 0 )
					AddImageTiled( x, y, SetWidth, EntryHeight, SetGumpID );

				AddButton( x + SetOffsetX, y + SetOffsetY, SetButtonID1, SetButtonID2, 3, GumpButtonType.Reply, 0 );
			}

			if ( isBody )
			{
				x = BorderSize + OffsetSize;
				y += EntryHeight + OffsetSize;

				AddImageTiled( x, y, EntryWidth+xextend, EntryHeight, EntryGumpID );
				AddLabelCropped( x + TextOffsetX, y, EntryWidth+xextend - TextOffsetX, EntryHeight, TextHue, "Body Picker" );
				x += EntryWidth+xextend + OffsetSize;

				if ( SetGumpID != 0 )
					AddImageTiled( x, y, SetWidth, EntryHeight, SetGumpID );

				AddButton( x + SetOffsetX, y + SetOffsetY, SetButtonID1, SetButtonID2, 4, GumpButtonType.Reply, 0 );
			}
		}
示例#19
0
		internal CSSchemaField(PropertyInfo propInfo , CSSchema schema)
		{
			_propertyInfo = propInfo;
			_schema = schema;
            _fieldType = _propertyInfo.PropertyType;
		    _realType = _fieldType.Inspector().RealType;

			RelationAttribute  attRelation = (RelationAttribute) Attribute.GetCustomAttribute(propInfo,typeof(RelationAttribute),true);
			
            _prefetch = propInfo.IsDefined(typeof(PrefetchAttribute), true);

			if (attRelation != null)
			{
				_relation = new CSRelation(schema,attRelation);

 				return;
			}

			_lazy = propInfo.IsDefined(typeof(LazyAttribute) , true);
			_noCreate = propInfo.IsDefined(typeof(NoCreateAttribute) , true);
            _trim = propInfo.IsDefined(typeof(TrimAttribute), true);
            _optimisticLock = propInfo.IsDefined(typeof(OptimisticLockAttribute), true);
		    _clientGenerated = propInfo.IsDefined(typeof(ClientGeneratedAttribute), true);
		    _serverGenerated = propInfo.IsDefined(typeof(ServerGeneratedAttribute), true);
		    _notMapped = propInfo.IsDefined(typeof (NotMappedAttribute), true);


			MapToAttribute     attMapTo = (MapToAttribute)     Attribute.GetCustomAttribute(propInfo,typeof(MapToAttribute),true);
			NullValueAttribute attNull  = (NullValueAttribute) Attribute.GetCustomAttribute(propInfo,typeof(NullValueAttribute),true);
            IdentityAttribute attIdentity = (IdentityAttribute)Attribute.GetCustomAttribute(propInfo, typeof(IdentityAttribute), true);

            if (!_notMapped)
            {
                if (CSConfig.ColumnMappingOverrideMap.ContainsValue(propInfo.DeclaringType.Name + ":" + propInfo.Name))
                    _mappedColumn =
                        schema.Columns[
                            CSConfig.ColumnMappingOverrideMap[propInfo.DeclaringType.Name + ":" + propInfo.Name]];
                else if (attMapTo != null)
                    _mappedColumn = schema.Columns[attMapTo.Name];
                else
                    _mappedColumn = schema.Columns[propInfo.Name];

                if (_mappedColumn != null)
                    _mappedColumn.MappedField = this;
            }


            SequenceAttribute sequenceAttribute = (SequenceAttribute) Attribute.GetCustomAttribute(propInfo,typeof(SequenceAttribute), true);

            if (sequenceAttribute != null && _schema.DB.SupportsSequences)
            {
                _sequenceName = sequenceAttribute.SequenceName;

                if (_mappedColumn != null && sequenceAttribute.Identity)
                {
                    _mappedColumn.Identity = true;
                    _schema.IdentityColumn = _mappedColumn;
                }
            }

            if (attIdentity != null)
            {
                if (_mappedColumn != null)
                {
                    _mappedColumn.Identity = true;
                    _schema.IdentityColumn = _mappedColumn;
                }
            }

		    if (attNull != null)
			{
				_nullValue = attNull.NullValue;
			}
			else
			{
				Type fieldType = FieldType;

				if (fieldType == typeof(string))         
                    _nullValue = String.Empty;
                else if (fieldType.IsValueType)
                    _nullValue = Activator.CreateInstance(fieldType);
			}

			if (_mappedColumn != null && _mappedColumn.ReadOnly)
			{
				if (_propertyInfo.CanWrite)
					throw new CSException("Property [" + Name + "] for class [" + _schema.ClassType.Name + "] should be read-only");
			}
		}
 private bool ShoudBeIgnored(PropertyInfo info)
 {
     foreach (Type attributeType in attributesToIgnore)
      {
     if (info.IsDefined(attributeType, false))
     {
        return true;
     }
      }
      return false;
 }
示例#21
0
            private static bool Filtered(PropertyInfo property)
            {
                if (!property.CanWrite)
                    return false;

                if (property.IsDefined<ScriptIgnoreAttribute>(false))
                    return false;

                if (property.IsDefined<IgnoreDataMemberAttribute>(false))
                    return false;

                return true;
            }
示例#22
0
        private static Type GetArrayItemType(PropertyInfo propInfo)
        {
            if (propInfo.IsDefined(typeof(ArrayParameterAttribute), false))
            {
                ArrayParameterAttribute[] attributes = (ArrayParameterAttribute[])propInfo.GetCustomAttributes(typeof(ArrayParameterAttribute), false);

                return attributes[0].ItemType;
            }
            else
            {
                return null;
            }
        }
        internal static EntityPropertyInfo Get( PropertyInfo property )
        {
            EntityPropertyInfo ep = new EntityPropertyInfo();

            object[] arrAttr = property.GetCustomAttributes( typeof( ValidationAttribute ), true );
            foreach (Object at in arrAttr) {
                ep.ValidationAttributes.Add( at as ValidationAttribute );
            }

            ep.SaveAttribute = ReflectionUtil.GetAttribute( property, typeof( ColumnAttribute ) ) as ColumnAttribute;
            ep.LongTextAttribute = ReflectionUtil.GetAttribute( property, typeof( LongTextAttribute ) ) as LongTextAttribute;
            ep.MoneyAttribute = ReflectionUtil.GetAttribute( property, typeof( MoneyAttribute ) ) as MoneyAttribute;
            ep.DecimalAttribute = ReflectionUtil.GetAttribute( property, typeof( DecimalAttribute ) ) as DecimalAttribute;
            ep.DefaultAttribute = ReflectionUtil.GetAttribute( property, typeof( DefaultAttribute ) ) as DefaultAttribute;

            ep.Property = property;
            ep.Name = property.Name;
            ep.Type = property.PropertyType;
            ep.SaveToDB = !property.IsDefined( typeof( NotSaveAttribute ), false );

            if (property.PropertyType is IList) {
                ep.IsList = true;
                ep.SaveToDB = false;
            }

            return ep;
        }
示例#24
0
 static bool PropertyIsValid(PropertyInfo property)
 {
     return
         !property.DeclaringType.IsValueType &&
         !property.IsSpecialName &&
         property.DeclaringType != typeof(object) &&
         !property.IsDefined(typeof(CompilerGeneratedAttribute), true) &&
         !property.IsDefined(typeof(ObsoleteAttribute), true);
 }
        public bool IsRequired(PropertyInfo property)
        {
            if (property.IsDefined(typeof(RequiredAttribute), true))
                return true;

            if (property.IsDefined(typeof(DefaultValueAttribute), true))
                return false;

            if (property.PropertyType.IsGenericType && property.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
                return false;

            return property.PropertyType.IsValueType;
        }
 private static bool InternalIsDefined(PropertyInfo element, Type attributeType, bool inherit)
 {
     if (element.IsDefined(attributeType, inherit))
     {
         return true;
     }
     if (inherit)
     {
         if (!InternalGetAttributeUsage(attributeType).Inherited)
         {
             return false;
         }
         for (PropertyInfo info = GetParentDefinition(element); info != null; info = GetParentDefinition(info))
         {
             if (info.IsDefined(attributeType, false))
             {
                 return true;
             }
         }
     }
     return false;
 }
 public void PropertiesHasDefaultValuesAttribute(Type optionsClassType, PropertyInfo property)
 {
     Assert.That(property.IsDefined(typeof(DefaultValueAttribute), true), Is.True);
 }
示例#28
0
		public static bool HasSuiteAttribute( PropertyInfo property )
		{
			return property.IsDefined( SuiteType, false );
		}
 /// <summary>
 /// Determines if a specific attribute is defined on a property.
 /// </summary>
 /// <param name="property"></param>
 /// <param name="attributeType">the type of attribute to look for</param>
 /// <param name="inherit"></param>
 /// <returns><c>true</c> if the attribute is defined, otherwise <c>false</c></returns>
 public static bool IsAttributeDefined(PropertyInfo property, Type attributeType, bool inherit)
 {
     #if REFLECTION_V2
     return property.GetCustomAttributes(attributeType, inherit).Any();
     #else
     return property.IsDefined(attributeType, inherit);
     #endif
 }
示例#30
0
            public HairStylistSetGump(PropertyInfo prop, Mobile from, INXHairStylist hairStylist, PropertyInfo[] propertyList, int page)
                : base(PropsConfig.GumpOffsetX, PropsConfig.GumpOffsetY)
            {
                m_Property = prop;
                m_From = from;
                m_HairStylist  = hairStylist;
                
                m_Page = page;
                m_PropertyList = propertyList;

                bool canNull = !prop.PropertyType.IsValueType;
                bool canDye = prop.IsDefined(typeof(HueAttribute), false);
                bool isBody = prop.IsDefined(typeof(BodyAttribute), false);

                object val = prop.GetValue(m_HairStylist , null);
                string initialText;

                if (val == null)
                    initialText = "";
                else
                    initialText = val.ToString();

                AddPage(0);

                AddBackground(0, 0, BackWidth, BackHeight + (canNull ? (PropsConfig.EntryHeight + PropsConfig.OffsetSize) : 0) + (canDye ? (PropsConfig.EntryHeight + PropsConfig.OffsetSize) : 0) + (isBody ? (PropsConfig.EntryHeight + PropsConfig.OffsetSize) : 0), PropsConfig.BackGumpID);
                AddImageTiled(PropsConfig.BorderSize, PropsConfig.BorderSize, TotalWidth - (PropsConfig.OldStyle ? PropsConfig.SetWidth + PropsConfig.OffsetSize : 0), TotalHeight + (canNull ? (PropsConfig.EntryHeight + PropsConfig.OffsetSize) : 0) + (canDye ? (PropsConfig.EntryHeight + PropsConfig.OffsetSize) : 0) + (isBody ? (PropsConfig.EntryHeight + PropsConfig.OffsetSize) : 0), PropsConfig.OffsetGumpID);

                int x = PropsConfig.BorderSize + PropsConfig.OffsetSize;
                int y = PropsConfig.BorderSize + PropsConfig.OffsetSize;

                AddImageTiled(x, y, EntryWidth, PropsConfig.EntryHeight, PropsConfig.EntryGumpID);
                AddLabelCropped(x + PropsConfig.TextOffsetX, y, EntryWidth - PropsConfig.TextOffsetX, PropsConfig.EntryHeight, PropsConfig.TextHue, prop.Name);
                x += EntryWidth + PropsConfig.OffsetSize;

                if (PropsConfig.SetGumpID != 0)
                    AddImageTiled(x, y, PropsConfig.SetWidth, PropsConfig.EntryHeight, PropsConfig.SetGumpID);

                x = PropsConfig.BorderSize + PropsConfig.OffsetSize;
                y += PropsConfig.EntryHeight + PropsConfig.OffsetSize;

                AddImageTiled(x, y, EntryWidth, PropsConfig.EntryHeight, PropsConfig.EntryGumpID);
                AddTextEntry(x + PropsConfig.TextOffsetX, y, EntryWidth - PropsConfig.TextOffsetX, PropsConfig.EntryHeight, PropsConfig.TextHue, 0, initialText);
                x += EntryWidth + PropsConfig.OffsetSize;

                if (PropsConfig.SetGumpID != 0)
                    AddImageTiled(x, y, PropsConfig.SetWidth, PropsConfig.EntryHeight, PropsConfig.SetGumpID);

                AddButton(x + PropsConfig.SetOffsetX, y + PropsConfig.SetOffsetY, PropsConfig.SetButtonID1, PropsConfig.SetButtonID2, 1, GumpButtonType.Reply, 0);

                if (canNull)
                {
                    x = PropsConfig.BorderSize + PropsConfig.OffsetSize;
                    y += PropsConfig.EntryHeight + PropsConfig.OffsetSize;

                    AddImageTiled(x, y, EntryWidth, PropsConfig.EntryHeight, PropsConfig.EntryGumpID);
                    AddLabelCropped(x + PropsConfig.TextOffsetX, y, EntryWidth - PropsConfig.TextOffsetX, PropsConfig.EntryHeight, PropsConfig.TextHue, "Null");
                    x += EntryWidth + PropsConfig.OffsetSize;

                    if (PropsConfig.SetGumpID != 0)
                        AddImageTiled(x, y, PropsConfig.SetWidth, PropsConfig.EntryHeight, PropsConfig.SetGumpID);

                    AddButton(x + PropsConfig.SetOffsetX, y + PropsConfig.SetOffsetY, PropsConfig.SetButtonID1, PropsConfig.SetButtonID2, 2, GumpButtonType.Reply, 0);
                }

                if (canDye)
                {
                    x = PropsConfig.BorderSize + PropsConfig.OffsetSize;
                    y += PropsConfig.EntryHeight + PropsConfig.OffsetSize;

                    AddImageTiled(x, y, EntryWidth, PropsConfig.EntryHeight, PropsConfig.EntryGumpID);
                    AddLabelCropped(x + PropsConfig.TextOffsetX, y, EntryWidth - PropsConfig.TextOffsetX, PropsConfig.EntryHeight, PropsConfig.TextHue, "Hue Picker");
                    x += EntryWidth + PropsConfig.OffsetSize;

                    if (PropsConfig.SetGumpID != 0)
                        AddImageTiled(x, y, PropsConfig.SetWidth, PropsConfig.EntryHeight, PropsConfig.SetGumpID);

                    AddButton(x + PropsConfig.SetOffsetX, y + PropsConfig.SetOffsetY, PropsConfig.SetButtonID1, PropsConfig.SetButtonID2, 3, GumpButtonType.Reply, 0);
                }

                if (isBody)
                {
                    x = PropsConfig.BorderSize + PropsConfig.OffsetSize;
                    y += PropsConfig.EntryHeight + PropsConfig.OffsetSize;

                    AddImageTiled(x, y, EntryWidth, PropsConfig.EntryHeight, PropsConfig.EntryGumpID);
                    AddLabelCropped(x + PropsConfig.TextOffsetX, y, EntryWidth - PropsConfig.TextOffsetX, PropsConfig.EntryHeight, PropsConfig.TextHue, "Body Picker");
                    x += EntryWidth + PropsConfig.OffsetSize;

                    if (PropsConfig.SetGumpID != 0)
                        AddImageTiled(x, y, PropsConfig.SetWidth, PropsConfig.EntryHeight, PropsConfig.SetGumpID);

                    AddButton(x + PropsConfig.SetOffsetX, y + PropsConfig.SetOffsetY, PropsConfig.SetButtonID1, PropsConfig.SetButtonID2, 4, GumpButtonType.Reply, 0);
                }
            }
示例#31
0
 public static bool IsDefinedOn(PropertyInfo property)
 {
     return property.IsDefined(typeof(XmlOptionAttribute), false);
 }
 public void ShouldNotHaveNullableArgumentAttribute(Type type, PropertyInfo property)
 {
     Assert.That(property.IsDefined(typeof(NullableArgumentAttribute), true), Is.False, type.FullName + "." + property.Name + " is collection, should not have NullableArgument attribute, but instead RepeatableArgument");
 }
        internal void ResolveNavigationProperty(StructuralType declaringType, PropertyInfo propertyInfo)
        {
            Debug.Assert(
                propertyInfo.IsDefined(typeof(EdmRelationshipNavigationPropertyAttribute), false),
                "The property must have navigation property defined");

            // EdmScalarPropertyAttribute, EdmComplexPropertyAttribute and EdmRelationshipNavigationPropertyAttribute
            // are all EdmPropertyAttributes that we need to process. If the current property is not an EdmPropertyAttribute
            // we will just ignore it and skip to the next property.
            var relationshipPropertyAttributes = propertyInfo.GetCustomAttributes(typeof(EdmRelationshipNavigationPropertyAttribute), false);

            Debug.Assert(relationshipPropertyAttributes.Length == 1, "There should be exactly one property for every navigation property");

            // The only valid return types from navigation properties are:
            //     (1) EntityType
            //     (2) CollectionType containing valid EntityType

            // If TryGetLoadedType returned false, it could mean that we couldn't validate any part of the type, or it could mean that it's a generic
            // where the main generic type was validated, but the generic type parameter was not. We can't tell the difference, so just fail
            // with the same error message in both cases. The user will have to figure out which part of the type is wrong.
            // We can't just rely on checking for a generic because it can lead to a scenario where we report that the type parameter is invalid
            // when really it's the main generic type. That is more confusing than reporting the full name and letting the user determine the problem.
            EdmType propertyType;
            if (!TryGetLoadedType(propertyInfo.PropertyType, out propertyType)
                ||
                !(propertyType.BuiltInTypeKind == BuiltInTypeKind.EntityType
                  || propertyType.BuiltInTypeKind == BuiltInTypeKind.CollectionType))
            {
                // Once an error is detected the property does not need to be validated further, just add to the errors
                // collection and continue with the next property. The failure will cause an exception to be thrown later during validation of all of the types.
                SessionData.EdmItemErrors.Add(
                    new EdmItemError(
                        Strings.Validator_OSpace_InvalidNavPropReturnType(
                            propertyInfo.Name, propertyInfo.DeclaringType.FullName, propertyInfo.PropertyType.FullName)));
                return;
            }
            // else we have a valid EntityType or CollectionType that contains EntityType. ResolveNonSchemaType enforces that a collection type
            // must contain an EntityType, and if it doesn't, propertyType will be null here. If propertyType is EntityType or CollectionType we know it is valid

            // Expecting EdmRelationshipNavigationPropertyAttribute to have AllowMultiple=False, so only look at first element in the attribute array

            var attribute = (EdmRelationshipNavigationPropertyAttribute)relationshipPropertyAttributes[0];

            EdmMember member = null;
            EdmType type;
            if (SessionData.TypesInLoading.TryGetValue(attribute.RelationshipNamespaceName + "." + attribute.RelationshipName, out type)
                &&
                Helper.IsAssociationType(type))
            {
                var relationshipType = (AssociationType)type;
                if (relationshipType != null)
                {
                    // The return value of this property has been verified, so create the property now
                    var navigationProperty = new NavigationProperty(propertyInfo.Name, TypeUsage.Create(propertyType));
                    navigationProperty.RelationshipType = relationshipType;
                    member = navigationProperty;

                    if (relationshipType.Members[0].Name
                        == attribute.TargetRoleName)
                    {
                        navigationProperty.ToEndMember = (RelationshipEndMember)relationshipType.Members[0];
                        navigationProperty.FromEndMember = (RelationshipEndMember)relationshipType.Members[1];
                    }
                    else if (relationshipType.Members[1].Name
                             == attribute.TargetRoleName)
                    {
                        navigationProperty.ToEndMember = (RelationshipEndMember)relationshipType.Members[1];
                        navigationProperty.FromEndMember = (RelationshipEndMember)relationshipType.Members[0];
                    }
                    else
                    {
                        SessionData.EdmItemErrors.Add(
                            new EdmItemError(
                                Strings.TargetRoleNameInNavigationPropertyNotValid(
                                    propertyInfo.Name, propertyInfo.DeclaringType.FullName, attribute.TargetRoleName,
                                    attribute.RelationshipName)));
                        member = null;
                    }

                    if (member != null
                        &&
                        ((RefType)navigationProperty.FromEndMember.TypeUsage.EdmType).ElementType.ClrType != declaringType.ClrType)
                    {
                        SessionData.EdmItemErrors.Add(
                            new EdmItemError(
                                Strings.NavigationPropertyRelationshipEndTypeMismatch(
                                    declaringType.FullName,
                                    navigationProperty.Name,
                                    relationshipType.FullName,
                                    navigationProperty.FromEndMember.Name,
                                    ((RefType)navigationProperty.FromEndMember.TypeUsage.EdmType).ElementType.ClrType)));
                        member = null;
                    }
                }
            }
            else
            {
                SessionData.EdmItemErrors.Add(
                    new EdmItemError(
                        Strings.RelationshipNameInNavigationPropertyNotValid(
                            propertyInfo.Name, propertyInfo.DeclaringType.FullName, attribute.RelationshipName)));
            }

            if (member != null)
            {
                declaringType.AddMember(member);
            }
        }
示例#34
0
        private static Boolean isSkip( PropertyInfo info, Boolean allowNotSave )
        {
            if (info.CanRead == false) {
                return true;
            }

            if (info.IsDefined( typeof( NotSerializeAttribute ), false )) {
                return true;
            }

            if (allowNotSave && info.IsDefined( typeof( NotSaveAttribute ), false )) {
                return true;
            }

            return false;
        }
		public bool IsIgnored(PropertyInfo p)
		{
			return p.IsDefined(typeof (IgnoreAttribute), true);
		}