示例#1
0
文件: OHInfo.cs 项目: yek13/Audit-Log
        private bool InspectObject_UsingXmlConfig(Type objType)
        {
            bool retval = false;

            XMLTypeConfiguration cfg = Target.XmlConfiguration().GetTypeConfiguration(objType);

            if (cfg == null)
            {
                IsLoggable = false;
            }
            else
            {
                IsLoggable = true;
                retval     = true;

                ObjectName = objType.FullName;
                AppendType = AppendTypes.Differential;


                if (!string.IsNullOrEmpty(cfg.KeyProperty))
                {
                    KeyPropertyName = cfg.KeyProperty;
                    if (!cfg.Properties.Contains(KeyPropertyName))
                    {
                        cfg.Properties.Add(KeyPropertyName);
                    }
                }

                for (int i = 0; i < cfg.Properties.Count; i++)
                {
                    PropertyInfo prop = objType.GetProperty(cfg.Properties[i]);
                    if (prop != null)
                    {
                        string propValue = string.Empty;
                        if (_obj != null)
                        {
                            object _v = prop.GetValue(_obj, null);
                            propValue = _v == null ? null : _v.ToString();
                        }

                        LoggableProperties.Add(new OHPropertyInfo(prop.Name, propValue, prop, this));
                    }
                }
            }

            return(retval);
        }
示例#2
0
文件: OHInfo.cs 项目: yek13/Audit-Log
        private bool InspectObject_UsingAttributesConfig(Type objType)
        {
            bool retval = false;

            foreach (var attr in objType.GetCustomAttributes(true))
            {
                if (attr is LogAttribute)
                {
                    retval = true;

                    IsLoggable = true;
                    ObjectName = ((LogAttribute)attr).MappedName;
                    if (string.IsNullOrEmpty(ObjectName))
                    {
                        ObjectName = objType.FullName;
                    }

                    AppendType = ((LogAttribute)attr).AppendType;


                    var props = objType.GetProperties();
                    foreach (var prop in props)
                    {
                        foreach (var pAttr in prop.GetCustomAttributes(true))
                        {
                            if (pAttr is LogKeyAttribute)
                            {
                                KeyPropertyName = prop.Name;
                            }

                            if (pAttr is LogPropertyAttribute)
                            {
                                string propName = ((LogPropertyAttribute)pAttr).MappedName;
                                if (string.IsNullOrEmpty(propName))
                                {
                                    propName = prop.Name;
                                }


                                string propValue = string.Empty;
                                if (_obj != null)
                                {
                                    object _v = prop.GetValue(_obj, null);
                                    propValue = _v == null ? null : _v.ToString();
                                }


                                LoggableProperties.Add(new OHPropertyInfo(propName, propValue, prop, this));
                            }
                        }
                    }


                    if (string.IsNullOrEmpty(KeyPropertyName))
                    {
                        throw new MissingLogKeyAttributeException(objType);
                    }
                }
            }

            return(retval);
        }