示例#1
0
        public PocoFeatureAttributeDefinition(PropertyInfo propertyInfo, FeatureAttributeAttribute att)
        {
            AttributeName = propertyInfo.Name;
            if (!string.IsNullOrEmpty(att.AttributeName))
            {
                AttributeName = att.AttributeName;
            }

            AttributeDescription = att.AttributeDescription;

            AttributeType = propertyInfo.PropertyType;
            if (propertyInfo.CanRead)
            {
                _getMethod = propertyInfo.GetGetMethod();
                _static    = _getMethod.IsStatic;
            }
            if (propertyInfo.CanWrite)
            {
                _setMethod = propertyInfo.GetSetMethod();
            }
            else
            {
                _readonly = true;
            }

            /*
             * var att = propertyInfo.GetCustomAttributes(typeof (FeatureAttributeAttribute), true);
             * if (att.Length > 0) CorrectByAttribute((FeatureAttributeAttribute)att[0]);
             */

            CorrectByAttribute(att);
        }
        private static FeatureAttributeAttribute Copy(FeatureAttributeAttribute att)
        {
            if (att == null)
            {
                return(null);
            }

            return(new FeatureAttributeAttribute
            {
                AttributeName = att.AttributeName,
                AttributeDescription = att.AttributeDescription,
                Ignore = att.Ignore,
                Readonly = att.Readonly
            });
        }
示例#3
0
        public void CorrectByAttribute(FeatureAttributeAttribute attribute)
        {
            if (attribute.Ignore)
            {
                Ignore = true;
                return;
            }

            if (!string.IsNullOrEmpty(attribute.AttributeName))
            {
                AttributeName = attribute.AttributeName;
            }
            if (!string.IsNullOrEmpty(attribute.AttributeName))
            {
                AttributeName = attribute.AttributeName;
            }

            _readonly |= attribute.Readonly;
            Ignore     = attribute.Ignore;
        }
        private static IEnumerable <Tuple> Verify(List <InterfaceMapping> mappings,
                                                  IEnumerable <PropertyInfo> propertyInfos)
        {
            foreach (var propertyInfo in propertyInfos)
            {
                FeatureAttributeAttribute fatt = null;
                // Check if this property has a FeatureAttributeAttribute attached to it.
                var att = propertyInfo.GetCustomAttributes(typeof(FeatureAttributeAttribute), true);

                if (att.Length > 0)
                {
                    fatt = (FeatureAttributeAttribute)att[0];
                    // Does it say ignore?
                    if (fatt.Ignore)
                    {
                        continue;
                    }
                }

                // See if we can find some interface that defines this property
                var foundInInterfaces = false;
                foreach (var interfaceMapping in mappings)
                {
                    var index = Array.IndexOf(interfaceMapping.TargetMethods, propertyInfo.GetGetMethod());
                    if (index >= 0)
                    {
                        // yes, here it is
                        foundInInterfaces = true;

                        var interfaceType = interfaceMapping.InterfaceType;
                        var pi            = interfaceType.GetProperty(interfaceMapping.InterfaceMethods[index].Name.Substring(4));

                        // Check if this property has a FeatureAttributeAttribute attached to it.
                        var attTmp = pi.GetCustomAttributes(typeof(FeatureAttributeAttribute), true);
                        if (attTmp.Length > 0)
                        {
                            // Does it say don't ignore it
                            if (!((FeatureAttributeAttribute)attTmp[0]).Ignore)
                            {
                                yield return(new Tuple(propertyInfo, Copy((FeatureAttributeAttribute)attTmp[0])));
                            }
                        }

                        /* this does not work
                         *
                         * // Check if this property has a FeatureAttributeAttribute attached to it.
                         * att = interfaceMapping.InterfaceMethods[index].GetCustomAttributes(
                         *      typeof (FeatureAttributeAttribute), true);
                         * if (att.Length > 0)
                         * {
                         *  // Does it say don't ignore it
                         *  if (!((FeatureAttributeAttribute)att[0]).Ignore)
                         *      yield return propertyInfo;
                         * }
                         */

                        // Won't find it in another interface
                        break;
                    }
                }

                if (!foundInInterfaces)
                {
                    yield return(new Tuple(propertyInfo, Copy(fatt)));
                }
            }
        }