private void EditorOnDataSourceChanged(object sender, EventArgs eventArgs) { if (View?.CollectionSource.List != null && _positionColumn != null) { var orderedObjects = GetObjects(null).ToArray(); for (var index = 0; index < orderedObjects.Length; index++) { var orderedObject = orderedObjects[index]; _memberInfo.SetValue(orderedObject, index); } } }
public void SetValue(ref TContainer container, TElement[] value) { var boxed = (object)container; m_Info.SetValue(boxed, value); container = (TContainer)boxed; }
private static void ParseSimpleProperty(JObject jObject, object obj, IMemberInfo memberInfo) { JValue jValue = (JValue)jObject[memberInfo.Name]; object value = ConvertType(jValue, memberInfo); memberInfo.SetValue(obj, value); }
private void callback_Callback(object source, CallbackEventArgs e) { String[] p = e.Parameter.Split('|'); Object key = TypeDescriptor.GetConverter(ObjectTypeInfo.KeyMember.MemberType).ConvertFromString(p[0]); IMemberInfo member = ObjectTypeInfo.FindMember(p[1]); Object value = null; if (typeof(IXPSimpleObject).IsAssignableFrom(member.MemberType)) { Type memberKeyType = XafTypesInfo.Instance.FindTypeInfo(member.MemberType).KeyMember.MemberType; int index1 = p[2].LastIndexOf("(", StringComparison.Ordinal); int index2 = p[2].LastIndexOf(")", StringComparison.Ordinal); if (index1 > 0 && index2 > index1) { string memberKeyText = p[2].Substring(index1 + 1, index2 - index1 - 1); value = ObjectSpace.GetObjectByKey(member.MemberType, Convert.ChangeType(memberKeyText, memberKeyType)); } } else { value = TypeDescriptor.GetConverter(member.MemberType).ConvertFromString(p[2]); } object obj = ObjectSpace.GetObjectByKey(ObjectTypeInfo.Type, key); member.SetValue(obj, value); ObjectSpace.CommitChanges(); }
private static void ParseAssociationProperty(JObject jObject, object obj, IMemberInfo memberInfo, IObjectSpace objectSpace) { string keyPropertyName = memberInfo.MemberTypeInfo.KeyMember.Name; JToken keyToken = jObject[memberInfo.Name][keyPropertyName]; object keyValue = ConvertType((JValue)keyToken, memberInfo.MemberTypeInfo.KeyMember); object value = objectSpace.GetObjectByKey(memberInfo.MemberType, keyValue); memberInfo.SetValue(obj, value); }
/// <summary> /// Sets the value of the member of targetObj /// </summary> /// <param name="targetObj">Main object whose members are to be assigned a value</param> /// <param name="memberInfo">Information about the member used to determine how the value is converted to the member type</param> /// <param name="value">Value to assigned to the member</param> public void SetMemberValue(IXPObject targetObj, IMemberInfo memberInfo, string value, bool createMember = false, bool cacheObject = false) { if (string.IsNullOrWhiteSpace(value)) { return; } object newValue = GetMemberValue(targetObj.Session, memberInfo, value, createMember, cacheObject); memberInfo.SetValue(targetObj, newValue); }
private void MapReferenceMember(IObjectSpace objectSpace, object value, IMemberInfo memberInfo, object toObject) { if (value != null) { var typeInfo = value.GetType().GetITypeInfo(); if (memberInfo.FindAttribute <SkipTypeMappingAttribute>() == null) { MapTo(objectSpace, value); } memberInfo.SetValue(toObject, GetObject(objectSpace, typeInfo, objectSpace.GetKeyValue(value))); } }
void CreateChildObject(XafGridView masterView, CustomMasterRowEventArgs e) { string relationName = masterView.GetRelationName(e.RowHandle, e.RelationIndex); object masterObject = masterView.GetRow(e.RowHandle); IMemberInfo memberInfo = XafTypesInfo.Instance.FindTypeInfo(masterObject.GetType()).FindMember(relationName); Type listElementType = memberInfo.ListElementType; IMemberInfo referenceToOwner = memberInfo.AssociatedMemberInfo; object obj = GetObjectSpace().CreateObject(listElementType); referenceToOwner.SetValue(obj, masterObject); //if (IsHiddenFrame()) //((NestedObjectSpace)ObjectSpace).ParentObjectSpace.CommitChanges(); }
/// <inheritdoc/> public override void SetValue(ref TContainer container, TValue value) { if (IsReadOnly) { throw new InvalidOperationException("Property is ReadOnly."); } if (m_IsStructContainerType) { if (m_SetStructValueAction == null) { // boxing var boxed = (object)container; m_Info.SetValue(boxed, value); container = (TContainer)boxed; } else { // no boxing m_SetStructValueAction(ref container, value); } } else { if (m_SetClassValueAction == null) { // boxing m_Info.SetValue(container, value); } else { // no boxing m_SetClassValueAction(container, value); } } }
private static void SetUserProperty(ITrackedObject obj, string property) { if (string.IsNullOrEmpty(property)) { return; } IMemberInfo member = XafTypesInfo.Instance.FindTypeInfo(obj.GetType()).FindMember(property); if (member == null) { throw new InvalidPropertyPathException(string.Format("The {0} property does not existing within the {1} type", property, obj.GetType().Name)); } member.SetValue(obj, obj.Session.GetObjectByKey(SecuritySystem.CurrentUser.GetType(), SecuritySystem.CurrentUserId)); }
void treeList_CellValueChanged(object sender, CellValueChangedEventArgs e) { var protocolRecord = (sender as ObjectTreeList).FocusedObject as ProtocolRecord; if (protocolRecord != null) { object newValue = e.Value; if (e.Value is IXPSimpleObject) { newValue = ObjectSpace.GetObject(e.Value); } if (protocolRecord.Type.Type == TypeEnum.Date) { if (e.Value is DateTime) { newValue = ((DateTime)e.Value).ToString("dd.MM.yyyy"); } } if (protocolRecord.Type.Type == TypeEnum.Time) { if (e.Value is DateTime) { newValue = ((DateTime)e.Value).TimeOfDay.ToString(@"hh\:mm\:ss"); } } object focusedObject = treeList.FocusedObject; if (focusedObject != null) { IMemberInfo focusedColumnMemberInfo = ObjectSpace.TypesInfo.FindTypeInfo(focusedObject.GetType()).FindMember(e.Column.FieldName); if (focusedColumnMemberInfo != null) { focusedColumnMemberInfo.SetValue(focusedObject, Convert.ChangeType(newValue, focusedColumnMemberInfo.MemberType)); } ObjectSpace.SetModified(focusedObject); } treeList.FilterNodes(); } }
private void treeList_CellValueChanged(object sender, CellValueChangedEventArgs e) { object newValue = e.Value; if (e.Value is IXPSimpleObject) { newValue = ObjectSpace.GetObject(e.Value); } object focusedObject = treeList.FocusedObject; if (focusedObject != null) { IMemberInfo focusedColumnMemberInfo = ObjectSpace.TypesInfo.FindTypeInfo(focusedObject.GetType()).FindMember(e.Column.FieldName); if (focusedColumnMemberInfo != null) { focusedColumnMemberInfo.SetValue(focusedObject, Convert.ChangeType(newValue, focusedColumnMemberInfo.MemberType)); } } }
void BindMember(IMemberInfo memberInfo) { var pivotedPropertyAttribute = memberInfo.FindAttribute <PivotedPropertyAttribute>(); IAnalysisInfo analysisInfo; if (string.IsNullOrEmpty(pivotedPropertyAttribute.AnalysisCriteria)) { analysisInfo = (IAnalysisInfo)ObjectSpace.CreateObject(memberInfo.MemberType); var pivotedType = View.ObjectTypeInfo.FindMember(pivotedPropertyAttribute.CollectionName).ListElementType; ((XPObjectSpace)ObjectSpace).Session.GetClassInfo(analysisInfo).GetMember(analysisInfo.GetPropertyName(x => x.DataType)).SetValue(analysisInfo, pivotedType); } else { analysisInfo = ObjectSpace.FindObject(memberInfo.MemberType, CriteriaOperator.Parse(pivotedPropertyAttribute.AnalysisCriteria)) as IAnalysisInfo; if (analysisInfo == null) { throw new UserFriendlyException(new Exception("Could not find a " + memberInfo.MemberType.Name + " object that can fit " + pivotedPropertyAttribute.AnalysisCriteria)); } } memberInfo.SetValue(View.CurrentObject, analysisInfo); }
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(); } } }
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); }
protected void SetFileValue(object instance, IMemberInfo member, HttpPostedFileBase file) { if (file == null || string.IsNullOrEmpty(file.FileName)) member.SetValue(instance, null); else if (member.Type == typeof(HttpPostedFile).FullName) member.SetValue(instance, file); else if (member.Type == typeof(String).FullName) member.SetValue(instance, ReadFileText(file)); else if (member.Type == typeof(Stream).FullName) member.SetValue(instance, file.InputStream); else if (member.Type == typeof(byte[]).FullName) member.SetValue(instance, ReadFileBytes(file)); else throw new ApplicationException(Messages.InvalidFormFieldFileType.ToString()); //PropertyInfo pInfo = member as PropertyInfo; //if (pInfo == null) { // FieldInfo fInfo = (FieldInfo)member; // if (file == null || string.IsNullOrEmpty(file.FileName)) // fInfo.SetValue(instance, null); // else if (fInfo.FieldType == typeof(HttpPostedFile)) // fInfo.SetValue(instance, file); // else if (fInfo.FieldType == typeof(String)) // fInfo.SetValue(instance, ReadFileText(file)); // else if (fInfo.FieldType == typeof(Stream)) // fInfo.SetValue(instance, file.InputStream); // else if (fInfo.FieldType == typeof(byte[])) // fInfo.SetValue(instance, ReadFileBytes(file)); // else // throw new ApplicationException(Messages.InvalidFormFieldFileType.ToString()); //} //else // if (file == null || string.IsNullOrEmpty(file.FileName)) // pInfo.SetValue(instance, null, null); // else if (pInfo.PropertyType == typeof(HttpPostedFile)) // pInfo.SetValue(instance, file, null); // else if (pInfo.PropertyType == typeof(String)) // pInfo.SetValue(instance, ReadFileText(file), null); // else if (pInfo.PropertyType == typeof(Stream)) // pInfo.SetValue(instance, file.InputStream, null); // else if (pInfo.PropertyType == typeof(byte[])) // pInfo.SetValue(instance, ReadFileBytes(file), null); // else // throw new ApplicationException(Messages.InvalidFormFieldFileType.ToString()); }
/// <summary> /// Sets the value of a PropertyInfo or FieldInfo represented by member to equal value. /// </summary> /// <param name="instance">The instance.</param> /// <param name="member">The member.</param> /// <param name="value">The value.</param> protected void SetValue(object instance, IMemberInfo member, object value) { // potentially valid - bind parameter with no corresponding field if (member == null) return; try { //PropertyInfo pInfo = member as PropertyInfo; //if (pInfo == null) //{ // FieldInfo fInfo = (FieldInfo)member; // fInfo.SetValue(instance, value == null ? null : Coerce(value, fInfo.FieldType)); //} //else //{ // if (pInfo.CanWrite) // pInfo.SetValue(instance, value == null ? null : Coerce(value, pInfo.PropertyType), null); //} member.SetValue(instance, value == null ? null : Coerce(value, member)); } catch (Exception ex) { // we should never crash here. handle it and move on. logger.Report(Messages.UnableToSetValue, member.Type, member.Name, Convert.ToString(value), ex.Message); } }