public static void AssignPropertiesViaReflection(T poCommand, Hashtable poDataValues)
        {
            PropertyInfo[] Props = poCommand.GetProperties();

            Dictionary <PropertyInfo, WonkaRefAttr> PropMap = poCommand.GetPropertyMap();

            // Set Commentary Attributes
            foreach (PropertyInfo TmpProperty in Props)
            {
                object oPropAttrValue = null;

                Type   oAttrType = TmpProperty.PropertyType;
                string sAttrName = PropMap.ContainsKey(TmpProperty) ? PropMap[TmpProperty].AttrName : string.Empty;

                if (poDataValues.ContainsKey(sAttrName))
                {
                    object oAttrValue = poDataValues[sAttrName];

                    if (!String.IsNullOrEmpty((string)oAttrValue))
                    {
                        var targetType = IsNullableType(oAttrType) ? Nullable.GetUnderlyingType(oAttrType) : oAttrType;

                        oPropAttrValue = Convert.ChangeType(oAttrValue, targetType);

                        TmpProperty.SetValue(poCommand, oPropAttrValue, null);
                    }
                }
            }
        }
示例#2
0
        public IMetadataRetrievable ImportSource(Type poDataStructType, object poDataStructure = null)
        {
            WonkaImportSource NewImportSource = new WonkaImportSource();

            PropertyInfo[] Props = poDataStructType.GetProperties();

            foreach (PropertyInfo TmpProperty in Props)
            {
                Type   AttrType  = TmpProperty.PropertyType;
                string sAttrName = TmpProperty.Name;

                WonkaRefAttr TmpWonkaAttr = new WonkaRefAttr();

                TmpWonkaAttr.AttrId   = GenerateNewAttrId();
                TmpWonkaAttr.AttrName = sAttrName;
                TmpWonkaAttr.ColName  = sAttrName;
                TmpWonkaAttr.TabName  = poDataStructType.FullName;

                if (poDataStructure != null)
                {
                    object oTmpValue = TmpProperty.GetValue(poDataStructure);

                    TmpWonkaAttr.DefaultValue = Convert.ToString(oTmpValue);
                }

                TmpWonkaAttr.Description = "";

                TmpWonkaAttr.IsDate    = IsTypeDate(AttrType.Name);
                TmpWonkaAttr.IsNumeric = IsTypeNumeric(AttrType.Name);
                TmpWonkaAttr.IsDecimal = IsTypeDecimal(AttrType.Name);

                // NOTE: These values are simply defaults and have no real meaning
                if (TmpWonkaAttr.IsNumeric)
                {
                    TmpWonkaAttr.Precision = 9;
                    TmpWonkaAttr.Scale     = 0;
                }
                else if (TmpWonkaAttr.IsDecimal)
                {
                    TmpWonkaAttr.Precision = 9;
                    TmpWonkaAttr.Scale     = 9;
                }

                // TmpWonkaAttr.MaxLength = ?;

                TmpWonkaAttr.FieldId   = TmpWonkaAttr.AttrId + 1000;
                TmpWonkaAttr.GroupId   = CONST_DEFAULT_GROUP_ID;
                TmpWonkaAttr.IsAudited = true;

                TmpWonkaAttr.IsKey = (TmpWonkaAttr.AttrName.EndsWith("ID") || TmpWonkaAttr.AttrName.EndsWith("Id"));

                NewImportSource.AddAttribute(TmpWonkaAttr);
            }

            return(NewImportSource);
        }
        public static void GetPropertiesViaReflection(T poCommand, Hashtable poDataValues)
        {
            PropertyInfo[] Props = poCommand.GetProperties();

            Dictionary <PropertyInfo, WonkaRefAttr> PropMap = poCommand.GetPropertyMap();

            // Set Commentary Attributes
            foreach (PropertyInfo TmpProperty in Props)
            {
                Type   oAttrType  = TmpProperty.PropertyType;
                string sAttrName  = PropMap.ContainsKey(TmpProperty) ? PropMap[TmpProperty].AttrName : string.Empty;
                string sAttrValue = Convert.ToString(TmpProperty.GetValue(poCommand));

                if (!String.IsNullOrEmpty(sAttrValue))
                {
                    poDataValues[sAttrName] = sAttrValue;
                }
            }
        }
        public static WonkaProduct GetWonkaProductViaReflection(T poCommand)
        {
            PropertyInfo[] Props = poCommand.GetProperties();

            Dictionary <PropertyInfo, WonkaRefAttr> PropMap = poCommand.GetPropertyMap();

            WonkaProduct TransformedProduct = new WonkaProduct();

            // Set Commentary Attributes
            foreach (PropertyInfo TmpProperty in Props)
            {
                Type   oAttrType  = TmpProperty.PropertyType;
                string sAttrName  = PropMap.ContainsKey(TmpProperty) ? PropMap[TmpProperty].AttrName : string.Empty;
                string sAttrValue = Convert.ToString(TmpProperty.GetValue(poCommand));

                if (!String.IsNullOrEmpty(sAttrValue))
                {
                    SetAttribute(TransformedProduct, PropMap[TmpProperty], sAttrValue);
                }
            }

            return(TransformedProduct);
        }