Exemple #1
0
        /// <summary>
        /// Can this attribute be assigned from another?   Checks for type compatibility ...
        /// e.g., string is assignable from everyting, double from any int, etc.
        /// </summary>
        /// <param name="oRhs"></param>
        /// <returns></returns>
        public bool CanBeAssignedFrom(AttributeDef oRhs)
        {
            const string fn = "AttributeDef.CanBeAssignedFrom()";
            try
            {
                if (null == oRhs) { return (false); }
                if (DataType.IsAssignableFrom(typeof(string))) { return (true); }
                if (DataType.IsAssignableFrom(oRhs.DataType)) { return (true); }
                if (typeof(double).Name == DataType.Name)
                {
                    if (typeof(Int64).IsAssignableFrom(oRhs.DataType)) { return (true); }
                }
                if (typeof(Int64).IsAssignableFrom(DataType))
                {
                    if (typeof(Int64).IsAssignableFrom(oRhs.DataType)) { return (true); }
                    if (typeof(double).IsAssignableFrom(oRhs.DataType)) { return (true); }
                }
                if (typeof(Int32).IsAssignableFrom(DataType))
                {
                    if (typeof(Int32).IsAssignableFrom(oRhs.DataType)) { return (true); }
                    if (typeof(Int64).IsAssignableFrom(oRhs.DataType)) { return (true); }
                }
                return (false);

            }
            catch (Exception exc)
            {
                Util.HandleExc(this, fn, exc);
                return (false);
            }
        }
Exemple #2
0
        /// <summary>
        /// This function retrieves attribute definition data relevant to a specific type.
        /// </summary>
        /// <param name="oType"></param>
        /// <returns></returns>
        public static List<AttributeDef> GetAttributesForType(Type oType,string sRelatesTo)
        {
            const string fn = "AttributeDef.GetAttributesForType()";
            List<AttributeDef> retlist = new List<AttributeDef>();
            try
            {
                int index = 0;
                foreach (FieldInfo fi in oType.GetFields())
                {
                    if (!fi.IsPublic) { continue;  }
                    Type ftype = fi.FieldType;
                    if (!AttributeDef.IsValidAtomicType(ftype)) { continue;  }
                    AttributeDef adef = new AttributeDef(oType, fi);
                    adef.DataType = fi.FieldType;
                    adef.Ordinal = index++;
                    if (!string.IsNullOrEmpty(sRelatesTo)) { adef.RelatesTo = sRelatesTo; }
                    retlist.Add(adef);
                }

                foreach (PropertyInfo pi in oType.GetProperties())
                {
                    if (!(pi.GetMethod.IsPublic&&pi.SetMethod.IsPublic)) { continue;  }
                    Type ptype = pi.PropertyType;
                    if (!AttributeDef.IsValidAtomicType(ptype)) { continue;  }
                    AttributeDef adef = new AttributeDef(oType, pi);
                    adef.Ordinal = index++;
                    if (!string.IsNullOrEmpty(sRelatesTo)) { adef.RelatesTo = sRelatesTo; }
                    retlist.Add(adef);
                }

                return (retlist);
            }
            catch (Exception exc)
            {
                Util.HandleExc(typeof(AttributeDef), fn, exc);
                return (retlist);
            }
        }