Esempio n. 1
0
 /// <inheritdoc/>
 public override TValue GetValue(ref TContainer container)
 {
     if (m_IsStructContainerType)
     {
         return(m_GetStructValueAction == null
             ? (TValue)m_Info.GetValue(container)      // boxing
             : m_GetStructValueAction(ref container)); // no boxing
     }
     else
     {
         return(m_GetClassValueAction == null
             ? (TValue)m_Info.GetValue(container) // boxing
             : m_GetClassValueAction(container)); // no boxing
     }
 }
Esempio n. 2
0
        protected override string GetDefaultStringRepresentation(object value)
        {
            if (value == null)
            {
                return(NullValueString);
            }
            if (value is XPWeakReference)
            {
                if (!(value as XPWeakReference).IsAlive)
                {
                    return(NullValueString);
                }
                return((value as XPWeakReference).Target.ToString());
            }
            ITypeInfo   ti            = XafTypesInfo.Instance.FindTypeInfo(value.GetType());
            IMemberInfo defaultMember = (ti != null) ? ti.DefaultMember : null;
            string      result;

            if (defaultMember != null)
            {
                object memberValue = defaultMember.GetValue(value);
                result = memberValue == null ? NullValueString : memberValue.ToString();
            }
            else
            {
                result = value.ToString();
            }
            if (!(value is string) && result.Length > MaxLengthOfValue)
            {
                result = BlobDataString;
            }
            return(result);
        }
        List <UnityObjectReference> GetValueInternal(object container, SerializationMetadata metadata)
        {
            var value = m_MemberInfo.GetValue(container);

            if (value == null)
            {
                return(null);
            }

            // Use typeless IList cast to support reflected private element types
            if (!(value is IList list))
            {
                return(null);
            }

            var result = new List <UnityObjectReference>(list.Count);

            foreach (var element in list)
            {
                if (!(element is UnityObject unityObject))
                {
                    result.Add(UnityObjectReference.NullObjectReference);
                    continue;
                }

                result.Add(UnityObjectReference.GetReferenceForObject(unityObject, metadata));
            }

            return(result);
        }
Esempio n. 4
0
        public static bool TryGetValueByPathDynamic(string prop, object source, out object result, out IMemberInfo itemInfo)
        {
            Guard.ArgumentNotNull(source, "from");
            Guard.ArgumentNotNull(prop, "propertyPath");
            result = null;
            string[] items   = prop.Split('.');
            object   currObj = source;

            itemInfo = null;
            foreach (string item in items)
            {
                if (currObj == null)
                {
                    return(true);
                }
                ITypeInfo   objType  = XafTypesInfo.Instance.FindTypeInfo(currObj.GetType());
                IMemberInfo curritem = objType.FindMember(item);
                if (curritem == null)
                {
                    return(false);
                }
                currObj  = curritem.GetValue(currObj);
                itemInfo = curritem;
            }
            result = currObj;
            return(true);
        }
Esempio n. 5
0
        protected override string GetPredefinedValues(IModelMember wrapper)
        {
            IMemberInfo memberInfo = View.ObjectTypeInfo.FindMember(GetPropertyName(workflow => workflow.TargetObjectType));
            var         value      = memberInfo.GetValue(View.CurrentObject) as Type;

            return(value != null?string.Join(";", Application.TypesInfo.FindTypeInfo(value).Members.Select(info => info.Name))
                       : string.Join(";", ""));
        }
Esempio n. 6
0
        private void MapCollectionMember(IObjectSpace objectSpace, IMemberInfo memberInfo, object toObject, object value)
        {
            var list = ((IList)memberInfo.GetValue(toObject));

            foreach (var obj in ((IEnumerable)value).Cast <object>())
            {
                list.Add(MapTo(obj, objectSpace));
            }
        }
 public static IObservable <KeyValuePair <object, string> > WhenCheckedListBoxItems(this ObjectString objectString, IMemberInfo member, object o)
 => objectString.WhenCheckedListBoxItems()
 .SelectMany(t2 => member.FindAttributes <DataSourcePropertyAttribute>()
             .SelectMany(attribute => ((IEnumerable)member.Owner.FindMember(attribute.DataSourceProperty).GetValue(o)).Cast <object>())
             .ToDictionary(o1 => o1, o1 => $"{o1}").ToObservable(Scheduler.Immediate)
             .SwitchIfEmpty(Observable.Defer(() => ((IEnumerable)member.GetValue(o)).Cast <object>()
                                             .ToDictionary(o1 => (object)$"{o1}", o1 => $"{o1}").ToObservable(Scheduler.Immediate)))
             .Where(dict => !t2.e.Objects.ContainsKey(dict.Key))
             .Do(pair => t2.e.Objects.Add(pair.Key, pair.Value)));
        protected override WebControl CreateEditModeControlCore()
        {
            bool flag = false;

            if (base.CurrentObject != null)
            {
                Func <IMemberInfo, bool>    predicate = null;
                DataSourcePropertyAttribute dataSourcePropertyAttribute = base.MemberInfo.FindAttribute <DataSourcePropertyAttribute>();
                if (dataSourcePropertyAttribute != null)
                {
                    FieldInfo info = typeof(ASPxStringPropertyEditor).GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance).FirstOrDefault <FieldInfo>(x => x.Name.Equals("predefinedValues"));
                    if (info != null)
                    {
                        if (predicate == null)
                        {
                            predicate = x => x.Name.Equals(dataSourcePropertyAttribute.DataSourceProperty);
                        }
                        IMemberInfo info2 = base.ObjectTypeInfo.Members.FirstOrDefault <IMemberInfo>(predicate);
                        if (info2 != null)
                        {
                            object obj2 = info2.GetValue(base.CurrentObject);
                            if (obj2 is string)
                            {
                                info.SetValue(this, obj2);
                            }
                            IEnumerable <string> source = obj2 as IEnumerable <string>;
                            if (source != null)
                            {
                                string str = source.Aggregate <string, string>(string.Empty, (current, s) => current + s + ";");
                                if (str.Length > 0)
                                {
                                    str = str.Remove(str.Length - 1);
                                    info.SetValue(this, str);
                                }
                            }
                        }
                    }
                    flag = true;
                }
            }
            WebControl control = base.CreateEditModeControlCore();

            if (flag && (control is ASPxDropDownEditBase))
            {
                ((ASPxDropDownEditBase)control).AllowUserInput  = false;
                ((ASPxDropDownEditBase)control).ShowShadow      = true;
                ((ASPxDropDownEditBase)control).AllowMouseWheel = true;
                if (control is ASPxComboBox)
                {
                    ((ASPxComboBox)control).DropDownStyle = DropDownStyle.DropDownList;
                }
            }
            return(control);
        }
Esempio n. 9
0
        Type GetMemberType()
        {
            string propertyName  = _propertyEditor.MemberInfo.FindAttribute <PropertyEditorProperty>().PropertyName;
            object ownerInstance = _propertyEditor.MemberInfo.GetOwnerInstance(_propertyEditor.CurrentObject);

            if (ownerInstance != null)
            {
                IMemberInfo memberInfo = XafTypesInfo.Instance.FindTypeInfo(ownerInstance.GetType()).FindMember(propertyName);
                return((Type)memberInfo.GetValue(ownerInstance));
            }
            return(null);
        }
        private void Move(bool down, object selectedObject)
        {
            int    currentPosition = (int)_memberInfo.GetValue(selectedObject);
            object otherObject     = GetOtherObject(down, currentPosition, selectedObject);
            var    otherPosition   = _memberInfo.GetValue(otherObject);

            _memberInfo.SetValue(selectedObject, otherPosition);
            _memberInfo.SetValue(otherObject, currentPosition);
            ObjectSpace.CommitChanges();

            currentPosition = (int)_memberInfo.GetValue(selectedObject);
            otherObject     = GetOtherObject(down, currentPosition, selectedObject);
            if (down)
            {
                _positionUpAction.Enabled["Move"]   = true;
                _positionDownAction.Enabled["Move"] = otherObject != null;
            }
            else
            {
                _positionDownAction.Enabled["Move"] = true;
                _positionUpAction.Enabled["Move"]   = otherObject != null;
            }
        }
Esempio n. 11
0
        /// <inheritdoc/>
        public override TValue GetValue(ref TContainer container)
        {
            if (m_ExternalContainerType != null)
            {
                var containerValue = GetContainerValue(container);
                if (m_ExternalMemberType != null)
                {
                    return(GetExternalMemberValue(containerValue));
                }

                return((TValue)m_Info.GetValue(containerValue));
            }

            if (m_ExternalMemberType != null)
            {
                return(GetExternalMemberValue(container));
            }

            // Should be unreachable but fall back to default
            return(default);
        private bool TryGetCachedLookupObject(XPCollection cachedObjects, 
            IMemberInfo lookupMemberInfo, 
            string value,  out object newValue)
        {
            newValue = null;

            // assign lookup object to return value
            foreach (var obj in cachedObjects)
            {
                object tmpValue = lookupMemberInfo.GetValue(obj);
                if (Convert.ToString(tmpValue) == value)
                {
                    newValue = obj;
                    break;
                }
            }

            if (newValue == null)
                return false;
            return true;
        }
 void UpdateVersionInXaml(ITypeInfo objectsTypeInfo, Version newVersion)
 {
     if (objectsTypeInfo != null && objectsTypeInfo.IsPersistent)
     {
         IMemberInfo xamlMemberInfo = objectsTypeInfo.FindMember(XamlPropertyName);
         if (xamlMemberInfo == null)
         {
             throw new MemberNotFoundException(objectsTypeInfo.Type, XamlPropertyName);
         }
         foreach (object objectToUpdate in ObjectSpace.GetObjects(objectsTypeInfo.Type))
         {
             var    currentXaml = xamlMemberInfo.GetValue(objectToUpdate) as string;
             string updatedXaml = WorkflowDefinitionsUpdater.UpdateDxAssembliesVersions(currentXaml, newVersion);
             xamlMemberInfo.SetValue(objectToUpdate, updatedXaml);
             ObjectSpace.SetModified(objectToUpdate);
         }
         if (ObjectSpace.IsModified)
         {
             ObjectSpace.CommitChanges();
         }
     }
 }
Esempio n. 14
0
        private bool TryGetCachedLookupObject(XPCollection cachedObjects,
                                              IMemberInfo lookupMemberInfo,
                                              string value, out object newValue)
        {
            newValue = null;

            // assign lookup object to return value
            foreach (var obj in cachedObjects)
            {
                string tmpValue = Convert.ToString(lookupMemberInfo.GetValue(obj));
                if (tmpValue.Trim().ToLower() == value.Trim().ToLower()) // case-insensitive
                {
                    newValue = obj;
                    break;
                }
            }

            if (newValue == null)
            {
                return(false);
            }
            return(true);
        }
Esempio n. 15
0
        public override string ToString()
        {
            if (!_isDefaultPropertyAttributeInit)
            {
                string defaultPropertyName = string.Empty;
                XafDefaultPropertyAttribute xafDefaultPropertyAttribute = XafTypesInfo.Instance.FindTypeInfo(GetType()).FindAttribute <XafDefaultPropertyAttribute>();
                if (xafDefaultPropertyAttribute != null)
                {
                    defaultPropertyName = xafDefaultPropertyAttribute.Name;
                }
                else
                {
                    DefaultPropertyAttribute defaultPropertyAttribute = XafTypesInfo.Instance.FindTypeInfo(GetType()).FindAttribute <DefaultPropertyAttribute>();
                    if (defaultPropertyAttribute != null)
                    {
                        defaultPropertyName = defaultPropertyAttribute.Name;
                    }
                }
                if (!string.IsNullOrEmpty(defaultPropertyName))
                {
                    _defaultPropertyMemberInfo = GetType().ToTypeInfo().FindMember(defaultPropertyName);
                }
                _isDefaultPropertyAttributeInit = true;
            }
            if (_defaultPropertyMemberInfo != null)
            {
                try {
                    return(_defaultPropertyMemberInfo.GetValue(this)?.ToString());
                }
                catch {
                    // ignored
                }
            }

            return(base.ToString());
        }
Esempio n. 16
0
        private static object CloningProcess(object source, Dictionary <object, object> circularReferences, int maxDeph)
        {
            if (circularReferences.ContainsKey(source))
            {
                return(circularReferences[source]);
            }

            Type type = GetRealType(source);

            object clonedObject = Activator.CreateInstance(type);

            if (clonedObject is IEntity)
            {
                var field = type.GetField("instaceId", BindingFlags.FlattenHierarchy | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

                if (field != null)
                {
                    field.SetValue(clonedObject, (source as IEntity).InstaceId);
                }
            }

            circularReferences[source] = clonedObject;

            var membersInfo = TypeHelper.GetPropertiesWithBackfields(type);

            foreach (var item in membersInfo)
            {
                IMemberInfo member = item.Key;

                var objeto = member.GetValue(source);

                if (objeto != null && objeto is Entity)
                {
                    Entity objRef = objeto as Entity;
                    member.SetValue(clonedObject, maxDeph < 0 ? objRef : CloningProcess(objRef, circularReferences, maxDeph - 1));
                    continue;
                }
                else
                {
                    member.SetValue(clonedObject, objeto);
                }

                if (member.MemberType.FullName.ToLower().Equals("system.string") ||
                    member.MemberType.Name.Contains("Byte[]"))
                {
                    continue;
                }

                #region Clonagem de enumerables

                Type IListType = member.MemberType.GetInterface("IEnumerable", true);

                if (IListType != null)
                {
                    try
                    {
                        IEnumerable iListValue = (IEnumerable)member.GetValue(source);

                        if (iListValue == null)
                        {
                            continue;
                        }

                        Type genericTypeList = null;

                        if (iListValue.GetType().IsGenericType&& iListValue.GetType().GetGenericArguments().Length > 0)
                        {
                            if (maxDeph < 0 && iListValue.GetType().GetGenericArguments().Any(c => typeof(IEntity).IsAssignableFrom(c)))
                            {
                                continue;
                            }

                            genericTypeList = typeof(List <>);
                            genericTypeList = genericTypeList.MakeGenericType(iListValue.GetType().GetGenericArguments());
                        }
                        else
                        {
                            genericTypeList = iListValue.GetType();
                        }

                        IList newList = (IList)Activator.CreateInstance(genericTypeList);

                        foreach (object value in iListValue)
                        {
                            if (value is Entity)
                            {
                                Entity clone = value as Entity;
                                newList.Add(CloningProcess(clone, circularReferences, maxDeph - 1));
                            }
                            else
                            {
                                newList.Add(value);
                            }
                        }

                        member.SetValue(clonedObject, newList);
                    }
                    catch
                    {
                        member.SetValue(clonedObject, null);
                    }
                }

                #endregion
            }

            return(clonedObject);
        }
 ReminderInfo GetReminderInfo()
 {
     return((ReminderInfo)_reminderMember.GetValue(View.CurrentObject));
 }
 public TValue GetValue(ref TContainer container) => (TValue)m_Info.GetValue(container);
		/// <summary>
		/// Gets the value of a PropertyInfo or FieldInfo represented by member.
		/// </summary>
		/// <param name="instance">The instance.</param>
		/// <param name="member">The member.</param>
		/// <returns></returns>
		protected object GetValue(object instance, IMemberInfo member)
		{
            return member.GetValue(instance);

		}
Esempio n. 20
0
 /// <summary>
 /// Gets the value.
 /// </summary>
 /// <param name="target">The target to get the value from.</param>
 /// <returns>The value.</returns>
 public object GetValue(object target) => new
 {
     input  = _Member?.GetValue(target),
     weight = _WeightField?.GetValue(target),
 };
Esempio n. 21
0
 public static string[] ToDefaultValues(this IMemberInfo targetMember, object o)
 => ((IEnumerable)targetMember.GetValue(o)).Cast <object>()
 .ToDefaultValues(targetMember.MemberTypeInfo.Type.RealType().ToTypeInfo()).ToArray();
 public TValue GetValue(ref TContainer container)
 {
     return((TValue)m_Info.GetValue(container));
 }
Esempio n. 23
0
 static object GetValue(object currentObject, IMemberInfo info)
 {
     return(info.MemberTypeInfo.IsPersistent ? info.MemberTypeInfo.KeyMember.GetValue(info.GetValue(currentObject)) : info.GetValue(currentObject));
 }
 public TElement[] GetValue(ref TContainer container) => (TElement[])m_Info.GetValue(container);