示例#1
0
        private static SpecialFieldInfo[] GetSpecialFields(Type instanceType)
        {
            List <SpecialFieldInfo> res = new List <SpecialFieldInfo>();

            foreach (System.Reflection.PropertyInfo i in instanceType.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic))
            {
                SpecialFieldInfo spInfo = SpecialFieldInfo.Create(i);
                if (spInfo != null)
                {
                    res.Add(spInfo);
                }
            }
            return(res.ToArray());
        }
示例#2
0
        public static SpecialFieldInfo Create(System.Reflection.PropertyInfo theProperty)
        {
            SpecialFieldInfo sp = new SpecialFieldInfo();

            sp._RelatedProperty = theProperty;
            SpecialFieldAttribute[] atts = (SpecialFieldAttribute[])(sp.RelatedProperty.GetCustomAttributes(typeof(SpecialFieldAttribute), true));
            if (atts.Length == 0)
            {
                return(null);
            }
            else if (atts.Length > 1)
            {
                throw new MissingSpecialFieldException(theProperty.DeclaringType, theProperty.Name);
            }
            sp._Attribute = atts[0];
            return(sp);
        }