Example #1
0
        /// <exclude />
        public static bool CompareTo(this IDataId sourceDataId, IDataId targetDataId, bool throwExceptionOnTypeMismathc)
        {
            if (sourceDataId == null) throw new ArgumentNullException("sourceDataId");
            if (targetDataId == null) throw new ArgumentNullException("targetDataId");


            if (sourceDataId.GetType() != targetDataId.GetType())
            {
                if (throwExceptionOnTypeMismathc) throw new ArgumentException(string.Format("Type mismatch {0} and {1}", sourceDataId.GetType(), targetDataId.GetType()));
                return false;
            }

            bool equal = true;
            foreach (PropertyInfo sourcePropertyInfo in sourceDataId.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                PropertyInfo targetPropertyInfo = targetDataId.GetType().GetProperty(sourcePropertyInfo.Name, BindingFlags.Public | BindingFlags.Instance);

                object sourceValue = sourcePropertyInfo.GetValue(sourceDataId, null);
                object targetValue = targetPropertyInfo.GetValue(targetDataId, null);

                if (object.Equals(sourceValue, targetValue) == false)
                {
                    equal = false;
                    break;
                }
            }

            return equal;
        }
Example #2
0
        public object GetKeyValue(IDataId dataId, string keyName)
        {
            if (keyName == null)
            {
                keyName = this.GetDefaultKeyName(dataId.GetType());
                if (keyName == null) throw new InvalidOperationException("Could not find default key for the type: " + dataId.GetType());
            }


            Func<Type, PropertyInfo> valueFactory = f => f.GetProperty(keyName);

            PropertyInfo keyPropertyInfo = _keyPropertyInfoCache.GetOrAdd(dataId.GetType(), valueFactory);

            object keyValue = keyPropertyInfo.GetValue(dataId, null);

            return keyValue;
        }
        /// <exclude />
        public override void OnGetPrettyHtml(EntityTokenHtmlPrettyfier prettifier)
        {
            prettifier.OnWriteId = (token, helper) =>
            {
                IDataId dataId = DataIdSerializer.Deserialize(this.Id, this.VersionId);

                var sb = new StringBuilder();
                sb.Append("<b>DataId</b><br />");
                sb.Append("<b>Type:</b> " + dataId.GetType() + "<br />");
                foreach (PropertyInfo propertyInfo in dataId.GetType().GetPropertiesRecursively())
                {
                    sb.Append("<b>" + propertyInfo.Name + ":</b> " + propertyInfo.GetValue(dataId, null).ToString() + "<br />");
                }

                helper.AddFullRow(new [] { "<b>Id</b>", sb.ToString() });
            };
        }
Example #4
0
        public object GetKeyValue(IDataId dataId, string keyName)
        {
            if (keyName == null)
            {
                keyName = this.GetDefaultKeyName(dataId.GetType());
                if (keyName == null)
                {
                    throw new InvalidOperationException("Could not find default key for the type: " + dataId.GetType());
                }
            }


            Func <Type, PropertyInfo> valueFactory = f => f.GetProperty(keyName);

            PropertyInfo keyPropertyInfo = _keyPropertyInfoCache.GetOrAdd(dataId.GetType(), valueFactory);

            object keyValue = keyPropertyInfo.GetValue(dataId, null);

            return(keyValue);
        }
        /// <exclude />
        public static bool CompareTo(this IDataId sourceDataId, IDataId targetDataId, bool throwExceptionOnTypeMismathc)
        {
            if (sourceDataId == null)
            {
                throw new ArgumentNullException("sourceDataId");
            }
            if (targetDataId == null)
            {
                throw new ArgumentNullException("targetDataId");
            }


            if (sourceDataId.GetType() != targetDataId.GetType())
            {
                if (throwExceptionOnTypeMismathc)
                {
                    throw new ArgumentException(string.Format("Type mismatch {0} and {1}", sourceDataId.GetType(), targetDataId.GetType()));
                }
                return(false);
            }

            bool equal = true;

            foreach (PropertyInfo sourcePropertyInfo in sourceDataId.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                PropertyInfo targetPropertyInfo = targetDataId.GetType().GetProperty(sourcePropertyInfo.Name, BindingFlags.Public | BindingFlags.Instance);

                object sourceValue = sourcePropertyInfo.GetValue(sourceDataId, null);
                object targetValue = targetPropertyInfo.GetValue(targetDataId, null);

                if (object.Equals(sourceValue, targetValue) == false)
                {
                    equal = false;
                    break;
                }
            }

            return(equal);
        }
        public static string Serialize(this IDataId dataId, IEnumerable <string> propertyNames)
        {
            if (dataId == null)
            {
                throw new ArgumentNullException(nameof(dataId));
            }

            var sb = new StringBuilder();

            SerializeKeyValuePair(sb, "_dataIdType_", TypeManager.SerializeType(dataId.GetType()));
            SerializeKeyValuePair(sb, "_dataId_", SerializationFacade.Serialize(dataId, propertyNames));

            return(sb.ToString());
        }
Example #7
0
        /// <exclude />
        public static void FullCopyTo(this IDataId sourceDataId, IDataId targetDataId)
        {
            if (sourceDataId == null) throw new ArgumentNullException("sourceDataId");
            if (targetDataId == null) throw new ArgumentNullException("targetDataId");

            foreach (PropertyInfo sourcePropertyInfo in sourceDataId.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                PropertyInfo targetPropertyInfo = targetDataId.GetType().GetProperty(sourcePropertyInfo.Name, BindingFlags.Public | BindingFlags.Instance);

                object value = sourcePropertyInfo.GetValue(sourceDataId, null);

                targetPropertyInfo.SetValue(targetDataId, value, null);
            }
        }
        /// <exclude />
        public static void FullCopyTo(this IDataId sourceDataId, IDataId targetDataId)
        {
            if (sourceDataId == null)
            {
                throw new ArgumentNullException("sourceDataId");
            }
            if (targetDataId == null)
            {
                throw new ArgumentNullException("targetDataId");
            }

            foreach (PropertyInfo sourcePropertyInfo in sourceDataId.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                PropertyInfo targetPropertyInfo = targetDataId.GetType().GetProperty(sourcePropertyInfo.Name, BindingFlags.Public | BindingFlags.Instance);

                object value = sourcePropertyInfo.GetValue(sourceDataId, null);

                targetPropertyInfo.SetValue(targetDataId, value, null);
            }
        }
Example #9
0
 // Overload
 /// <exclude />
 public static string GetDefaultKeyName(IDataId dataId)
 {
     return(_implementation.GetDefaultKeyName(dataId.GetType()));
 }
Example #10
0
        public static string Serialize(this IDataId dataId)
        {
            if (dataId == null)
            {
                throw new ArgumentNullException("dataId");
            }

            StringBuilder sb = new StringBuilder();

            StringConversionServices.SerializeKeyValuePair(sb, "_dataIdType_", TypeManager.SerializeType(dataId.GetType()));
            StringConversionServices.SerializeKeyValuePair(sb, "_dataId_", SerializationFacade.Serialize(dataId));

            return(sb.ToString());
        }