public static object GetXpMemberInfoValue(string propertyName, XPBaseObject o) { if (propertyName.IndexOf(".") > -1) { XPMemberInfo info = o.ClassInfo.GetMember(propertyName.Split(".".ToCharArray())[0]); object value = info.GetValue(o); if (typeof(XPBaseObject).IsAssignableFrom(info.MemberType)) { o = value as XPBaseObject; return(o == null ? null : GetXpMemberInfoValue(propertyName.Substring(propertyName.IndexOf(".") + 1), o)); } return (value != null ? GetPropertyInfoValue(propertyName.Substring(propertyName.IndexOf(".") + 1), info.GetValue(o)) : null); } XPMemberInfo xpMemberInfo = o.ClassInfo.GetMember(propertyName); if (xpMemberInfo == null) { throw new PropertyMissingException(o.GetType().FullName, propertyName); } return(xpMemberInfo.GetValue(o)); }
private CriteriaOperatorCollection GetOperatorCollection(string fields, DataTable dataTable) { var operatorCollection = new CriteriaOperatorCollection(); foreach (string property in fields.Split(';')) { if (property != "" && property.IndexOf("!") == -1 && property != "This") { XPMemberInfo xpMemberInfo = ReflectorHelper.GetXpMemberInfo(Session, ObjectType, property); if (xpMemberInfo.IsPersistent) { operatorCollection.Add(CriteriaOperator.Parse(property, new object[0])); var dataColumn = new DataColumn(property) { DataType = xpMemberInfo.MemberType }; if (typeof(XPBaseObject).IsAssignableFrom(dataColumn.DataType)) { dataColumn.DataType = Session.GetClassInfo(dataColumn.DataType).KeyProperty.MemberType; } dataTable.Columns.Add(dataColumn); if (property == ObjectClassInfo.KeyProperty.Name) { dataTable.PrimaryKey = new[] { dataColumn } } ; } } } return(operatorCollection); }
static PersistentBase PopulateObjectProperties(PersistentBase persistentObject, Dictionary <string, object> propertyValues, UnitOfWork uow, XPClassInfo classInfo) { object keyValue; if (persistentObject == null && propertyValues.TryGetValue(classInfo.KeyProperty.Name, out keyValue)) { persistentObject = (PersistentBase)uow.GetObjectByKey(classInfo, keyValue); } if (persistentObject == null) { persistentObject = (PersistentBase)classInfo.CreateNewObject(uow); } foreach (KeyValuePair <string, object> pair in propertyValues) { XPMemberInfo memberInfo = classInfo.FindMember(pair.Key); if (memberInfo.IsReadOnly) { continue; } if (memberInfo.ReferenceType != null) { PopulateReferenceProperty(persistentObject, uow, pair.Value, memberInfo); } else { PopulateScalarProperty(persistentObject, pair.Value, memberInfo); } } return(persistentObject); }
void CreateMemberCore(XPClassInfo inputClassInfo, string propertyName, XPMemberInfo xpMemberInfo, bool caseInSensitive) { var dbColumn = ColumnExists(propertyName, caseInSensitive); if (xpMemberInfo != null && dbColumn != null) { var referenceType = xpMemberInfo.ReferenceType; var dbColumnType = dbColumn.ColumnType; if (referenceType == null) { new InputMemberInfo(inputClassInfo, propertyName, dbColumnType, xpMemberInfo.MemberType, !xpMemberInfo.IsPersistent, xpMemberInfo, xpMemberInfo.Attributes); } else if (xpMemberInfo.IsPersistent) { var attributeInfo = (InitialDataAttribute)referenceType.FindAttributeInfo(typeof(InitialDataAttribute)); if (attributeInfo != null) { var classInfo = inputClassInfo.Dictionary.QueryClassInfo(null, attributeInfo.Name ?? referenceType.ClassType.Name); new InputMemberInfo(inputClassInfo, propertyName, classInfo, false, xpMemberInfo, xpMemberInfo.Attributes); } else { new InputMemberInfo(inputClassInfo, propertyName, dbColumnType, xpMemberInfo.ReferenceType.KeyProperty.MemberType, false, xpMemberInfo, xpMemberInfo.Attributes); } } } }
public override string ToString() { if (!BaseObject.IsXpoProfiling) { if (!isDefaultPropertyAttributeInit) { var memberName = string.Empty; var attribute1 = XafTypesInfo.Instance.FindTypeInfo(GetType()).FindAttribute <XafDefaultPropertyAttribute>(); if (attribute1 != null) { memberName = attribute1.Name; } else { var attribute2 = XafTypesInfo.Instance.FindTypeInfo(GetType()).FindAttribute <DefaultPropertyAttribute>(); if (attribute2 != null) { memberName = attribute2.Name; } } if (!string.IsNullOrEmpty(memberName)) { defaultPropertyMemberInfo = ClassInfo.FindMember(memberName); } isDefaultPropertyAttributeInit = true; } var obj = defaultPropertyMemberInfo?.GetValue(this); if (obj != null) { return(obj.ToString()); } } return(base.ToString()); }
public InputMemberInfo(XPClassInfo owner, string propertyName, XPClassInfo referenceType, bool nonPersistent, XPMemberInfo outputMemberInfo, params Attribute[] attributes) : base(owner, propertyName, referenceType.ClassType, referenceType, nonPersistent, false) { Guard.ArgumentNotNull(outputMemberInfo, "outputMemberInfo"); _outputMemberInfo = outputMemberInfo; AddAttributes(attributes); }
void ImportSimpleProperty(UnitOfWork outputUow, UnitOfWork inputUow, InputMemberInfo memberInfo, ImportedMemberInfo importedMemberInfo, object objectToImport, object xpoObject) { XPMemberInfo xpMemberInfo = importedMemberInfo.MemberInfo; if (xpMemberInfo != null) { var value = xpMemberInfo.GetValue(objectToImport); if (memberInfo.ReferenceType != null && memberInfo.ReferenceType.IsPersistent) { var memberType = ((InputObjectClassInfo)memberInfo.ReferenceType).OutputClassInfo.ClassType; bool returnKey; bool returnImportKey; value = GetReferenceMemberValue(outputUow, value, memberType, out returnKey, out returnImportKey); if (returnKey) { AddFillRefInfo(memberInfo, xpoObject, value); return; } if (returnImportKey) { value = inputUow.GetKeyValue(value); AddFillRefAndImportInfo(memberInfo, xpoObject, value); return; } } memberInfo.SetOutputMemberValue(xpoObject, value); } }
static void Main(string[] args) { XpoDefault.DataLayer = new SimpleDataLayer(new DevExpress.Xpo.DB.InMemoryDataStore()); XpoDefault.Session = null; using (UnitOfWork uow = new UnitOfWork()) { uow.ClearDatabase(); TestClass c1 = new TestClass(uow); c1.Name = "aaa"; c1.Email = "*****@*****.**"; TestClass c2 = new TestClass(uow); c2.Name = "bbb"; c2.Email = "*****@*****.**"; c2.Master = c1; uow.CommitChanges(); } XPClassInfo ci = XpoDefault.DataLayer.Dictionary.GetClassInfo(typeof(TestClass)); ci.CreateAliasedMember("DisplayName", typeof(string), "concat([Name],' (',[Email],')',iif([Master] is null,'',Concat(' managed by ',[Master].Name)))"); using (UnitOfWork uow = new UnitOfWork()) { XPCollection <TestClass> xpc = new XPCollection <TestClass>(uow, CriteriaOperator.Parse("Contains([DisplayName],'w3')")); System.Diagnostics.Debug.Assert(xpc.Count == 1); System.Diagnostics.Debug.Assert(xpc[0].Name == "bbb"); XPMemberInfo mi = xpc[0].ClassInfo.FindMember("DisplayName"); System.Diagnostics.Debug.Assert(mi != null && mi.IsReadOnly && mi.IsAliased); System.Diagnostics.Debug.Assert(object.Equals(mi.GetValue(xpc[0]), "bbb ([email protected]) managed by aaa")); } }
public static void SetXpMemberProperty(string propertyName, object value, XPBaseObject dbObject, bool save) { if (propertyName.IndexOf(".") > -1) { XPMemberInfo member = dbObject.ClassInfo.GetMember(propertyName.Split(".".ToCharArray())[0]); object o = member.GetValue(dbObject); if (typeof(XPBaseObject).IsAssignableFrom(member.MemberType)) { dbObject = o as XPBaseObject; SetXpMemberProperty(propertyName.Substring(propertyName.IndexOf(".") + 1), value, dbObject, save); return; } SetPropertyValue(o.GetType().GetProperty(propertyName.Substring(propertyName.IndexOf(".") + 1)), o, value); return; } XPMemberInfo xpMemberInfo = dbObject.ClassInfo.GetMember(propertyName); if (xpMemberInfo == null) { throw new PropertyMissingException(dbObject.GetType().FullName, propertyName); } xpMemberInfo.SetValue(dbObject, xpMemberInfo.Owner.ClassType.GetProperty(propertyName) == null ? value : ChangeType(value, xpMemberInfo.MemberType)); if (save) { dbObject.Save(); } }
public XPMemberInfo GetParentMember(XPClassInfo ci) { XPMemberInfo mi = null; parentMembers.TryGetValue(ci, out mi); return(mi); }
public virtual void MapValueToObjectProperty(XPObjectSpace objectSpace, XPMemberInfo prop, string value, ref IXPSimpleObject newObj) { object convertedValue = null; //if simple property if (prop.ReferenceType == null) { bool isNullable = prop.MemberType.IsGenericType && prop.MemberType.GetGenericTypeDefinition().IsNullableType(); if (prop.MemberType == null) { return; } convertedValue = isNullable ? MapStringToNullable(prop, value) : MapStringToValueType(prop, value); } //if referenced property else if (prop.ReferenceType != null) { convertedValue = MapStringToReferenceType(objectSpace, prop, value); } if (convertedValue != null) { convertedValue = AppllyDoubleValueRounding(convertedValue); } prop.SetValue(newObj, convertedValue); }
private XPMemberInfo CreateMemberInfo(ITypesInfo typesInfo, XPMemberInfo memberInfo, ProvidedAssociationAttribute providedAssociationAttribute, AssociationAttribute associationAttribute) { var typeToCreateOn = GetTypeToCreateOn(memberInfo, associationAttribute); if (typeToCreateOn == null) throw new NotImplementedException(); XPMemberInfo xpCustomMemberInfo; if (!(memberInfo.IsCollection) || (memberInfo.IsCollection && providedAssociationAttribute.RelationType == RelationType.ManyToMany)) { xpCustomMemberInfo = typesInfo.CreateCollection( typeToCreateOn, memberInfo.Owner.ClassType, associationAttribute.Name, XpandModuleBase.Dictiorary, providedAssociationAttribute.ProvidedPropertyName ?? memberInfo.Owner.ClassType.Name + "s", false); } else { xpCustomMemberInfo = typesInfo.CreateMember( typeToCreateOn, memberInfo.Owner.ClassType, associationAttribute.Name, XpandModuleBase.Dictiorary, providedAssociationAttribute.ProvidedPropertyName ?? memberInfo.Owner.ClassType.Name, false); } if (!string.IsNullOrEmpty(providedAssociationAttribute.AssociationName) && !memberInfo.HasAttribute(typeof(AssociationAttribute))) memberInfo.AddAttribute(new AssociationAttribute(providedAssociationAttribute.AssociationName)); typesInfo.RefreshInfo(typeToCreateOn); return xpCustomMemberInfo; }
public static Type GetObjectKeyType(this IObjectSpace objectSpace, Type objectType) { Type result = null; var xpClassInfo = objectSpace.FindXPClassInfo(objectType); if (xpClassInfo != null) { Type queryableType = xpClassInfo.ClassType; if (queryableType.IsInterface) { queryableType = PersistentInterfaceHelper.GetPersistentInterfaceDataType(queryableType); xpClassInfo = ((XPObjectSpace)objectSpace).Session.GetClassInfo(queryableType); } XPMemberInfo keyMember = xpClassInfo.KeyProperty; if (keyMember != null) { if (!keyMember.IsStruct) { if (keyMember.ReferenceType != null) { result = objectSpace.GetObjectKeyType(keyMember.ReferenceType.ClassType); } else { return(keyMember.MemberType); } } else { throw new NotImplementedException(); } } } return(result); }
private void View_OnControlsCreated(object sender, EventArgs e) { var view = (ListView)View; var listEditor = (DevExpress.ExpressApp.TreeListEditors.Win.CategorizedListEditor)view.Editor; ListView categoriesListView = listEditor.CategoriesListView; IObsoleteTreeNode obsoleteTreeNode = null; var propertyName = obsoleteTreeNode.GetPropertyName(node => node.Obsolete); categoriesListView.CollectionSource.Criteria[propertyName] = new GroupOperator(GroupOperatorType.Or, new BinaryOperator(propertyName, true)); var ids = new ArrayList(); XPMemberInfo keyProperty = null; foreach (ITreeNode treeNode in categoriesListView.CollectionSource.List) { var baseObject = (XPBaseObject)treeNode; keyProperty = baseObject.ClassInfo.KeyProperty; ids.Add(keyProperty.GetValue(baseObject)); for (int i = treeNode.Children.Count - 1; i > -1; i--) { baseObject = (XPBaseObject)treeNode.Children[i]; ids.Add(keyProperty.GetValue(baseObject)); } } categoriesListView.CollectionSource.Criteria[propertyName] = keyProperty != null ? new NotOperator(new InOperator(keyProperty.Name, ids)) : null; }
static void UpdateMember(IModelRuntimeMember modelRuntimeMember, XPMemberInfo xpMemberInfo) { var modelRuntimeCalculatedMember = modelRuntimeMember as IModelRuntimeCalculatedMember; if (modelRuntimeCalculatedMember != null) { ((XpandCalcMemberInfo)xpMemberInfo).SetAliasExpression(modelRuntimeCalculatedMember.AliasExpression); XpandModuleBase.TypesInfo.RefreshInfo(xpMemberInfo.Owner.ClassType); } }
private Type GetTypeToCreateOn(XPMemberInfo memberInfo, AssociationAttribute associationAttribute) { return !memberInfo.MemberType.IsGenericType ? (string.IsNullOrEmpty(associationAttribute.ElementTypeName) ? memberInfo.MemberType : Type.GetType(associationAttribute.ElementTypeName)) : memberInfo.MemberType.GetGenericArguments()[0]; }
protected override List <MemberInfo> GetSerializableMembers(Type objectType) { XPClassInfo classInfo = dictionary.QueryClassInfo(objectType); if (classInfo != null && classInfo.IsPersistent) { var allSerializableMembers = base.GetSerializableMembers(objectType); var serializableMembers = new List <MemberInfo>(allSerializableMembers.Count); foreach (MemberInfo member in allSerializableMembers) { XPMemberInfo mi = classInfo.FindMember(member.Name); if (!(mi.IsPersistent || mi.IsAliased || mi.IsCollection || mi.IsManyToManyAlias) || ((mi.IsCollection || mi.IsManyToManyAlias) && !SerializeCollections) || (mi.ReferenceType != null && !SerializeReferences) || (mi.MemberType == typeof(byte[]) && !SerializeByteArrays)) { continue; } serializableMembers.Add(member); } return(serializableMembers); } return(base.GetSerializableMembers(objectType)); }
public override string ToString() { if (!_isDefaultPropertyAttributeInit) { string defaultPropertyName = string.Empty; var xafDefaultPropertyAttribute = XafTypesInfo.Instance.FindTypeInfo(GetType()).FindAttribute<XafDefaultPropertyAttribute>(); if (xafDefaultPropertyAttribute != null) { defaultPropertyName = xafDefaultPropertyAttribute.Name; } else { var defaultPropertyAttribute = XafTypesInfo.Instance.FindTypeInfo(GetType()).FindAttribute<DefaultPropertyAttribute>(); if (defaultPropertyAttribute != null) { defaultPropertyName = defaultPropertyAttribute.Name; } } if (!string.IsNullOrEmpty(defaultPropertyName)) { _defaultPropertyMemberInfo = ClassInfo.FindMember(defaultPropertyName); } _isDefaultPropertyAttributeInit = true; } if (_defaultPropertyMemberInfo != null) { object obj = _defaultPropertyMemberInfo.GetValue(this); if (obj != null) { return obj.ToString(); } } return base.ToString(); }
private void ProcessSingleRow(XPObjectSpace objectSpace, Type type, string keyPropertyName, Row excelRow, List <XPMemberInfo> props, int i, out string message, Action <string> notify) { IXPSimpleObject newObj = GetExistingOrCreateNewObject(objectSpace, keyPropertyName, excelRow, type); message = null; if (newObj == null) { message = string.Format(Resources.newObjectError, i); return; } foreach (Mapping mapping in ImportMap.Mappings) { XPMemberInfo prop = props.First(p => p.Name == mapping.MapedTo); try{ Cell val = excelRow[mapping.Column]; if (val != null) { _propertyValueMapper(objectSpace, prop, val.Value, ref newObj); } } catch (Exception ee) { message = string.Format(Resources.ErrorProcessingRecord, i - 1, ee); notify(message); } } objectSpace.Session.Save(newObj); }
public static bool IsProrpotyChanged(XPClassInfo ClassInfo, object Obj, string ProportName, out object OldValue) { XPMemberInfo memberInfo = ClassInfo.GetMember(ProportName); OldValue = PersistentBase.GetModificationsStore(Obj).GetPropertyOldValue(memberInfo); return(OldValue != null); }
void HideMemberInDetailView(XPMemberInfo xpMemberInfo) { if (!xpMemberInfo.HasAttribute(typeof(VisibleInDetailViewAttribute))) { xpMemberInfo.AddAttribute(new VisibleInDetailViewAttribute(false)); } }
public override string ToString() { if (!_isDefaultPropertyAttributeInit) { string defaultPropertyName = string.Empty; var xafDefaultPropertyAttribute = XafTypesInfo.Instance.FindTypeInfo(GetType()).FindAttribute <XafDefaultPropertyAttribute>(); if (xafDefaultPropertyAttribute != null) { defaultPropertyName = xafDefaultPropertyAttribute.Name; } else { var defaultPropertyAttribute = XafTypesInfo.Instance.FindTypeInfo(GetType()).FindAttribute <DefaultPropertyAttribute>(); if (defaultPropertyAttribute != null) { defaultPropertyName = defaultPropertyAttribute.Name; } } if (!string.IsNullOrEmpty(defaultPropertyName)) { _defaultPropertyMemberInfo = ClassInfo.FindMember(defaultPropertyName); } _isDefaultPropertyAttributeInit = true; } object obj = _defaultPropertyMemberInfo?.GetValue(this); return(obj?.ToString() ?? base.ToString()); }
protected virtual XPCollection <T> CreateCollection <T>(XPMemberInfo property) { XPCollection <T> xps = new XPCollection <T>(base.Session, this, property); GC.SuppressFinalize(xps); return(xps); }
protected override XPCollection CreateCollection(XPMemberInfo property) { XPCollection result = base.CreateCollection(property); if (property.Name == "Resources") { result.CollectionChanged += Resources_CollectionChanged; } return result; }
public override void CopyMemberValue(XPMemberInfo memberInfo, IXPSimpleObject sourceObject, IXPSimpleObject targetObject) { if (!memberInfo.IsAssociation) { base.CopyMemberValue(memberInfo, sourceObject, targetObject); } }
IList CreateCollection(Object parent) { XPBaseCollection collection; if (parent == null) { collection = new XPCollection(session, root); XPMemberInfo parentMemberInfo = hdict.GetParentMember(root); if (parentMemberInfo != null) { collection.Criteria = new NullOperator(new OperandProperty(parentMemberInfo.Name)); } } else { XPClassInfo classInfo = session.GetClassInfo(parent); XPMemberInfo childrenMemberInfo = hdict.GetChildrenMember(classInfo); if (childrenMemberInfo == null) { return(new object[0]); } collection = new XPCollection(session, childrenMemberInfo.CollectionElementType); XPMemberInfo parentMemberInfo = hdict.GetParentMember(childrenMemberInfo.CollectionElementType); System.Diagnostics.Debug.Assert(parentMemberInfo != null); collection.Criteria = new BinaryOperator(new OperandProperty(parentMemberInfo.Name), new OperandValue(parent), BinaryOperatorType.Equal); } /* without a sotring the order of objects might differ */ collection.Sorting.Add(new SortProperty(root.KeyProperty.Name, DevExpress.Xpo.DB.SortingDirection.Ascending)); return(collection); }
public static List <XPMemberInfo> CreateBothPartMembers(this ITypesInfo typesinfo, Type typeToCreateOn, Type otherPartMember, bool isManyToMany, string association) { var infos = new List <XPMemberInfo>(); XPMemberInfo member = isManyToMany ? CreateCollection(typesinfo, typeToCreateOn, otherPartMember, association, false) : CreateMember(typesinfo, otherPartMember, typeToCreateOn, association, false); if (member != null) { infos.Add(member); member = isManyToMany ? CreateCollection(typesinfo, otherPartMember, typeToCreateOn, association, false) : CreateCollection(typesinfo, typeToCreateOn, otherPartMember, association, false); if (member != null) { infos.Add(member); } } typesinfo.RefreshInfo(typeToCreateOn); typesinfo.RefreshInfo(otherPartMember); return(infos); }
public override void CopyMemberValue(XPMemberInfo memberInfo, IXPSimpleObject sourceObject, IXPSimpleObject targetObject) { if (!((memberInfo.MappingField == "Correlativo") || (memberInfo.MappingField == "CodigoDeActivo"))) { base.CopyMemberValue(memberInfo, sourceObject, targetObject); } }
public XPMemberInfo GetChildrenMember(XPClassInfo ci) { XPMemberInfo mi = null; childrenMembers.TryGetValue(ci, out mi); return(mi); }
static XPMemberInfo CreateCollection(this ITypesInfo typeInfo, Type typeToCreateOn, Type typeOfCollection, string associationName, XPDictionary dictionary, string collectionName, bool refreshTypesInfo, bool isManyToMany) { XPMemberInfo member = null; if (TypeIsRegister(typeInfo, typeToCreateOn)) { XPClassInfo xpClassInfo = dictionary.GetClassInfo(typeToCreateOn); member = xpClassInfo.FindMember(collectionName); if (member == null) { member = xpClassInfo.CreateMember(collectionName, typeof(XPCollection), true); member.AddAttribute(new AssociationAttribute(associationName, typeOfCollection) { UseAssociationNameAsIntermediateTableName = isManyToMany }); if (refreshTypesInfo) { typeInfo.RefreshInfo(typeToCreateOn); } } } return(member); }
static void PopulateReferenceProperty(JObject jobject, object obj, XPMemberInfo memberInfo, Session session) { JObject refJObject = (JObject)jobject[memberInfo.Name]; object refObject = memberInfo.GetValue(obj); if (refJObject != null) { XPMemberInfo keyMemberInfo = memberInfo.ReferenceType.KeyProperty; JToken keyToken = refJObject[memberInfo.ReferenceType.KeyProperty.Name]; object keyValue = ((JValue)keyToken).Value; if (keyValue != null) { if (keyValue.GetType() != keyMemberInfo.MemberType) { keyValue = Convert.ChangeType(keyValue, keyMemberInfo.MemberType, CultureInfo.InvariantCulture); } refObject = session.GetObjectByKey(memberInfo.ReferenceType, keyValue); } } else { refObject = null; } if (refObject != null) { PopulateObject(refJObject, session, memberInfo.ReferenceType, refObject); } memberInfo.SetValue(obj, refObject); }
public CriteriaOperator Parse(string propertyPath, string parameters) { string path = null; string criteria = ""; foreach (string split in propertyPath.Split('.')) { path += split; criteria += split; XPMemberInfo memberInfo = XpandReflectionHelper.GetXpMemberInfo(_xpClassInfo, path); if (memberInfo.IsCollection) { criteria = criteria.TrimEnd('.'); criteria += "["; } if (criteria.LastIndexOf('[') != criteria.Length - 1) { criteria += "."; } path += "."; } var count = criteria.Count(c => c == '['); criteria += parameters; for (int i = 0; i < count; i++) { criteria = criteria + "]"; } return(_session.ParseCriteria(criteria)); }
public string Validate(string property) { XPMemberInfo member = fValidatedObject.ClassInfo.FindMember(property); if (member == null) { return(string.Empty); } CustomAttribute attribute = (CustomAttribute)member.FindAttributeInfo("Validation"); if (attribute == null) { return(string.Empty); } string[] rules = attribute.Value.Substring(0, attribute.Value.IndexOf('|')).Split(';'); string[] messages = attribute.Value.Substring(attribute.Value.IndexOf('|') + 1).Split(';'); for (int i = 0; i < rules.Length; i++) { if (!ValidateRule(member, rules[i])) { return(messages[i]); } } return(string.Empty); }
string GetDisplayText(TObject obj) { if (string.IsNullOrWhiteSpace(DisplayMember)) { DefaultPropertyAttribute attr = (DefaultPropertyAttribute)GetClassInfo(obj).FindAttributeInfo(typeof(DefaultPropertyAttribute)); if (attr != null) { XPMemberInfo defaultMember = GetClassInfo(obj).FindMember(attr.Name); if (defaultMember != null) { return(defaultMember.GetValue(obj)?.ToString()); } } return(obj.ToString()); } else { XPMemberInfo member = GetClassInfo(obj).FindMember(DisplayMember); if (member == null) { return(obj.ToString()); } else { return(member.GetValue(obj)?.ToString()); } } }
string GetCaption(XPMemberInfo propertyInfo) { var value = propertyInfo.GetValue(this); return(!string.IsNullOrEmpty(value?.ToString()) ? $"{propertyInfo.Name}: {value}" + ", " : null); }
AssociationAttribute GetAssociationAttribute(XPMemberInfo memberInfo, ProvidedAssociationAttribute providedAssociationAttribute) { var associationAttribute = memberInfo.FindAttributeInfo(typeof(AssociationAttribute)) as AssociationAttribute; if (associationAttribute == null && !string.IsNullOrEmpty(providedAssociationAttribute.AssociationName)) associationAttribute = new AssociationAttribute(providedAssociationAttribute.AssociationName); else if (associationAttribute == null) throw new NullReferenceException(memberInfo + " has no association attribute"); return associationAttribute; }
static DBColumnType GetDbColumnType(XPMemberInfo xpMemberInfo) { Type type = xpMemberInfo.StorageType; var xpClassInfo = xpMemberInfo.Owner.Dictionary.QueryClassInfo(type); if (xpClassInfo != null) { type = xpClassInfo.KeyProperty.StorageType; } return DBColumn.GetColumnType(type); }
static void CreateColumnCore(XPMemberInfo xpMemberInfo, bool throwUnableToCreateDBObjectException, ConnectionProviderSql sql, DBColumn column) { try { sql.CreateColumn(xpMemberInfo.Owner.Table, column); } catch (UnableToCreateDBObjectException) { if (throwUnableToCreateDBObjectException) throw; } }
public static IEnumerable<ObjectOperationPermission> ObjectOperationPermissions(this ISecurityRole securityRole, XPMemberInfo member) { var collection = ((XPBaseCollection)member.GetValue(securityRole)).OfType<object>(); var securityOperation = GetSecurityOperation(securityRole, member); if (!string.IsNullOrEmpty(securityOperation)) { foreach (var operation in securityOperation.Split(ServerPermissionRequestProcessor.Delimiters, StringSplitOptions.RemoveEmptyEntries)) { foreach (var obj in collection) { yield return ObjectOperationPermissions(member, obj, operation); } } } }
/// <summary> /// Defines how string is converted into NOT nullable value type /// </summary> /// <param name="prop">property that needs the converted value</param> /// <param name="value">string value to be converted</param> /// <param name="numberFormatInfo">Number formatting info</param> /// <returns>Converted value</returns> protected virtual object MapStringToValueType(XPMemberInfo prop, string value, NumberFormatInfo numberFormatInfo = null){ object result = null; if (prop.MemberType.IsEnum) result = Enum.Parse(prop.MemberType, value); else if (prop.MemberType == typeof (char)) result = Convert.ChangeType(ImportUtils.GetQString(value), prop.MemberType); else if (prop.StorageType == typeof (int)){ int number; if (value != String.Empty && Int32.TryParse(value, out number)) result = number; else result = 0; } else if (prop.MemberType == typeof (Guid)) result = new Guid(ImportUtils.GetQString(value)); else if (prop.StorageType == typeof (DateTime)){ if (value != string.Empty){ //Include validate DateTime dt = DateTime.FromOADate(Convert.ToDouble(value)); result = dt; } } else if (prop.MemberType == typeof (double)){ double number; if (Double.TryParse(value, NumberStyles.Number, numberFormatInfo ?? new NumberFormatInfo{NumberDecimalSeparator = "."}, out number)) result = number; } else if (prop.MemberType == typeof (bool)){ if (value != string.Empty && (value.Length == 1 || value.ToLower() == @"true" || value.ToLower() == @"false")) { bool truefalse; if (value.ToLower() == @"true" || value.ToLower() == @"false") truefalse = Convert.ToBoolean(value); else truefalse = Convert.ToBoolean(Convert.ToInt32(value)); result = truefalse; } } else result = Convert.ChangeType(value, prop.MemberType); return result; }
public override string ToString() { if (!_isDefaultPropertyAttributeInit) { var attrib = ClassInfo.FindAttributeInfo(typeof(DefaultPropertyAttribute)) as DefaultPropertyAttribute; if (attrib != null) { _defaultPropertyMemberInfo = ClassInfo.FindMember(attrib.Name); } _isDefaultPropertyAttributeInit = true; } if (_defaultPropertyMemberInfo != null) { object obj = _defaultPropertyMemberInfo.GetValue(this); if (obj != null) { return obj.ToString(); } } return base.ToString(); }
/// <contentfrom cref="ISecurityRule.GetSelectMemberExpression" /> public bool GetSelectMemberExpression(DevExpress.Xpo.SecurityContext context, XPClassInfo classInfo, XPMemberInfo memberInfo, out CriteriaOperator expression) { CriteriaOperator subExpression; expression = null; foreach (ISecurityRule rule in rules) if (rule.GetSelectMemberExpression(context, classInfo, memberInfo, out subExpression)) { if (ReferenceEquals(expression, null)) expression = subExpression; else if (!CriteriaOperator.CriterionEquals(expression, subExpression)) { expression = new OperandValue(null); return true; } } return !ReferenceEquals(expression, null); }
public virtual void MapValueToObjectProperty(XPObjectSpace objectSpace, XPMemberInfo prop, string value, ref IXPSimpleObject newObj){ object convertedValue = null; //if simple property if (prop.ReferenceType == null){ bool isNullable = prop.MemberType.IsGenericType && prop.MemberType.GetGenericTypeDefinition().IsNullableType(); if (prop.MemberType == null) return; convertedValue = isNullable ? MapStringToNullable(prop, value) : MapStringToValueType(prop, value); } //if referenced property else if (prop.ReferenceType != null) convertedValue = MapStringToReferenceType(objectSpace, prop, value); if (convertedValue != null) convertedValue = AppllyDoubleValueRounding(convertedValue); prop.SetValue(newObj, convertedValue); }
public InputMemberInfo(XPClassInfo owner, string propertyName, DBColumnType dbColumnType, Type propertyType, bool nonPersistent, XPMemberInfo outputMemberInfo, params Attribute[] attributes) : base(owner, propertyName, PropertyType(propertyType, dbColumnType), null, nonPersistent, false) { Guard.ArgumentNotNull(outputMemberInfo, "outputMemberInfo"); _outputMemberInfo = outputMemberInfo; _conversionType = propertyType; AddAttributes(attributes); }
void CreateMemberCore(XPClassInfo inputClassInfo, string propertyName, XPMemberInfo xpMemberInfo) { var dbColumn = ColumnExists(propertyName); if (xpMemberInfo != null && dbColumn != null) { var referenceType = xpMemberInfo.ReferenceType; var dbColumnType = dbColumn.ColumnType; if (referenceType == null) { new InputMemberInfo(inputClassInfo, propertyName, dbColumnType, xpMemberInfo.MemberType, !xpMemberInfo.IsPersistent, xpMemberInfo, xpMemberInfo.Attributes); } else if (xpMemberInfo.IsPersistent) { var attributeInfo = (InitialDataAttribute)referenceType.FindAttributeInfo(typeof(InitialDataAttribute)); if (attributeInfo != null) { var classInfo = inputClassInfo.Dictionary.QueryClassInfo(null, attributeInfo.Name ?? referenceType.ClassType.Name); new InputMemberInfo(inputClassInfo, propertyName, classInfo, !xpMemberInfo.IsPersistent, xpMemberInfo, xpMemberInfo.Attributes); } else { new InputMemberInfo(inputClassInfo, propertyName, dbColumnType, xpMemberInfo.ReferenceType.KeyProperty.MemberType, !xpMemberInfo.IsPersistent, xpMemberInfo, xpMemberInfo.Attributes); } } } }
public ImportedMemberInfo(XPClassInfo classInfo, XPMemberInfo memberInfo) { _classInfo = classInfo; _memberInfo = memberInfo; }
object GetValue(XElement simpleElement, XPMemberInfo xpMemberInfo) { var valueConverter = xpMemberInfo.Converter; if (valueConverter != null) { var value = GetValue(valueConverter.StorageType, simpleElement); return valueConverter.ConvertFromStorageType(value); } return GetValue(GetMemberType(xpMemberInfo), simpleElement); }
void ImportRefs(XPClassInfo classInfo, ICollection objects, FillRefList fillRefsList, UnitOfWork outputUow, UnitOfWork inputUow, List<InputMemberInfo> memberList, XPMemberInfo memberInfo) { int counter = 0; var memberObjectDictionary = GetObjectDictionary(classInfo.ClassType); foreach (object importObj in objects) { object owner = fillRefsList.OwnerList[counter]; object refKey = fillRefsList.RefKeyList[counter]; counter++; object obj; if (!memberObjectDictionary.ContainsKey(refKey)) { obj = ImportSingle(refKey, importObj, outputUow, inputUow, classInfo, memberList); } else { bool returnKey; obj = GetCachedObject(memberObjectDictionary, outputUow, refKey, classInfo.ClassType, true, out returnKey); } if (memberInfo.IsAssociationList) { var list = memberInfo.GetValue(owner) as IList; if (list == null) continue; list.Add(obj); } else { memberInfo.SetValue(owner, obj); } } }
bool MemberHasChanged(ISupportChangedMembers supportChangedMembers, XPMemberInfo m) { return m.HasAttribute(typeof(PersistentAttribute)) || m.IsKey || m is ServiceField || supportChangedMembers.ChangedProperties.Contains(m.Name); }
public static XPMemberInfo[] GetXpMemberInfos(XPClassInfo classInfo) { PropertyInfo[] propertyInfos = classInfo.ClassType.GetProperties(); var memberInfos = new XPMemberInfo[propertyInfos.Length]; int i = 0; foreach (PropertyInfo propertyInfo in propertyInfos) { XPMemberInfo memberInfo = classInfo.GetMember(propertyInfo.Name); if (memberInfo != null) memberInfos[i] = memberInfo; i++; } return memberInfos; }
void CreateMemberFromAttribute(XPClassInfo classInfo, XPMemberInfo memberInfo) { var initialDataAttribute = (InitialDataAttribute)memberInfo.FindAttributeInfo(typeof(InitialDataAttribute)); if (initialDataAttribute != null) { CreateMemberCore(classInfo, initialDataAttribute.Name ?? memberInfo.Name, memberInfo); } }
/// <summary> /// Specifies the rules and actions how to convert string to a referenced type /// </summary> /// <param name="objectSpace">OS used to lookup refecenced object</param> /// <param name="prop">property that needs the converted value</param> /// <param name="value">string value to be converted</param> protected virtual object MapStringToReferenceType(XPObjectSpace objectSpace, XPMemberInfo prop, string value){ //if other referenced type if (prop.MemberType.IsSubclassOf(typeof (XPBaseObject))){ string text = value; Type type = prop.MemberType; try{ XPBaseObject mval = Helper.GetXpObjectByKeyValue(objectSpace, text, type); return objectSpace.GetObject(mval); } catch (Exception e){ Trace.TraceWarning(Resources.RefTypeConversionError, value, prop.MemberType.Name, e); } } return null; }
private bool IsCollection(XPMemberInfo memberInfo) { return memberInfo.IsCollection || memberInfo.IsAssociationList; }
static void AddMember(XPMemberInfo memberInfo, List<XPMemberInfo> result) { Type memberType = memberInfo.MemberType; XPClassInfo memberClassInfo = XpandModuleBase.Dictiorary.QueryClassInfo(memberType); if (memberClassInfo != null && !memberClassInfo.IsPersistent) { return; } result.Add(memberInfo); }
Type GetMemberType(XPMemberInfo xpMemberInfo) { return xpMemberInfo is ServiceField ? typeof (Nullable<>).MakeGenericType(new[] {xpMemberInfo.MemberType}) : xpMemberInfo.MemberType; }
void CreateIntermediateClassInfo(XPDictionary outputDictionary, XPDictionary inputDictionary, string className, InitialDataAttribute importDataAttribute, XPMemberInfo memberInfo) { var info = new IntermediateClassInfo(inputDictionary, className); info.CreateMember("Oid_" + importDataAttribute.DataProviderQueryColumnName, typeof(int)).AddAttribute(new KeyAttribute(true)); info.CreateMember(importDataAttribute.DataProviderQueryColumnName, memberInfo.Owner.KeyProperty.MemberType); var collectionElementType = memberInfo.CollectionElementType.ClassType; var memberType = outputDictionary.QueryClassInfo(collectionElementType).KeyProperty.MemberType; info.CreateMember(importDataAttribute.DataProviderResultColumnName, memberType); }
/// <contentfrom cref="ISecurityRule.ValidateMemberOnSave" /> public ValidateMemberOnSaveResult ValidateMemberOnSave(DevExpress.Xpo.SecurityContext context, XPMemberInfo memberInfo, object theObject, object realObjectOnLoad, object value, object valueOnLoad, object realValueOnLoad) { ValidateMemberOnSaveResult result = ValidateMemberOnSaveResult.DoSaveMember, subResult; foreach (ISecurityRule rule in rules) { if (result == ValidateMemberOnSaveResult.DoRaiseException) break; subResult = rule.ValidateMemberOnSave(context, memberInfo, theObject, realObjectOnLoad, value, valueOnLoad, realValueOnLoad); switch (subResult) { case ValidateMemberOnSaveResult.DoRaiseException: result = subResult; break; case ValidateMemberOnSaveResult.DoNotSaveMember: if (result == ValidateMemberOnSaveResult.DoSaveMember) result = subResult; break; } } return result; }
void HideMemberInDetailView(XPMemberInfo xpMemberInfo) { if (!xpMemberInfo.HasAttribute(typeof(VisibleInDetailViewAttribute))) xpMemberInfo.AddAttribute(new VisibleInDetailViewAttribute(false)); }
/// <summary> /// Defines how string is converted into NULLABLE VALUE (like int?) type /// </summary> /// <param name="prop">property that needs the converted value</param> /// <param name="value">string value to be converted</param> /// <param name="numberFormatInfo">Number formatting info</param> /// <returns>Converted value</returns> protected virtual object MapStringToNullable(XPMemberInfo prop, string value, NumberFormatInfo numberFormatInfo = null){ object result = null; //TODO: Test this !!! if (prop.MemberType.IsEnum) result = Enum.Parse(prop.StorageType, value, true); else if (prop.StorageType == typeof (int)){ int number; if (value != String.Empty && Int32.TryParse(value, out number)) result = number; } else if (prop.StorageType == typeof (DateTime)){ if (value != string.Empty){ //Include validate DateTime dt = DateTime.FromOADate(Convert.ToDouble(value)); result = dt; } } else if (prop.StorageType == typeof (double)){ double number; if (Double.TryParse(value, NumberStyles.Number, numberFormatInfo ?? new NumberFormatInfo{NumberDecimalSeparator = "."}, out number)) result = number; } else result = Convert.ChangeType(value, prop.StorageType); return result; }