static string GetMemberCaption(IMemberInfo memberInfo) { string memberCaption = null; var displayNameAttr = memberInfo.FindAttribute <DisplayNameAttribute>(); if (displayNameAttr != null) { memberCaption = displayNameAttr.DisplayName; } if (string.IsNullOrEmpty(memberCaption)) { var attribute = memberInfo.FindAttribute <XafDisplayNameAttribute>(); if (attribute != null) { memberCaption = attribute.DisplayName; } } if (string.IsNullOrEmpty(memberCaption)) { memberCaption = memberInfo.DisplayName; } if (string.IsNullOrEmpty(memberCaption)) { memberCaption = CaptionHelper.ConvertCompoundName(memberInfo.Name); } return(memberCaption); }
private XPCustomMemberInfo CreateMemberInfo(ITypesInfo typesInfo, IMemberInfo memberInfo, ProvidedAssociationAttribute providedAssociationAttribute, AssociationAttribute associationAttribute) { var typeToCreateOn = getTypeToCreateOn(memberInfo, associationAttribute); if (typeToCreateOn == null) throw new NotImplementedException(); XPCustomMemberInfo xpCustomMemberInfo; if (!(memberInfo.IsList) || (memberInfo.IsList && providedAssociationAttribute.RelationType == RelationType.ManyToMany)) { xpCustomMemberInfo = typesInfo.CreateCollection( typeToCreateOn, memberInfo.Owner.Type, associationAttribute.Name, XpandModuleBase.Dictiorary, providedAssociationAttribute.ProvidedPropertyName ?? memberInfo.Owner.Type.Name + "s", false); } else { xpCustomMemberInfo = typesInfo.CreateMember( typeToCreateOn, memberInfo.Owner.Type, associationAttribute.Name, XpandModuleBase.Dictiorary, providedAssociationAttribute.ProvidedPropertyName ?? memberInfo.Owner.Type.Name, false); } if (!string.IsNullOrEmpty(providedAssociationAttribute.AssociationName) && memberInfo.FindAttribute<AssociationAttribute>() == null) memberInfo.AddAttribute(new AssociationAttribute(providedAssociationAttribute.AssociationName)); typesInfo.RefreshInfo(typeToCreateOn); return xpCustomMemberInfo; }
void HandleNumericFormatAttribute(IMemberInfo memberInfo) { var numericFormatAttribute = memberInfo.FindAttribute<NumericFormatAttribute>(); if (numericFormatAttribute != null) { memberInfo.AddAttribute(new CustomAttribute("EditMaskAttribute", "f0")); memberInfo.AddAttribute(new CustomAttribute("DisplayFormatAttribute", "#")); } }
protected virtual void CreateMemberNode(IModelClass classNode, IMemberInfo memberInfo, IModelMember propertyNode) { propertyNode.SetValue("MemberInfo", memberInfo); var indexAttribute = memberInfo.FindAttribute <IndexAttribute>(); if (indexAttribute != null) { propertyNode.Index = (int)indexAttribute.Value; } const BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Instance; var methodInfo = typeof(ModelNode).GetMethod("SetSerializedValue", bindingFlags); foreach (CustomAttribute attribute in memberInfo.FindAttributes <CustomAttribute>()) { methodInfo.Invoke(propertyNode, new object[] { attribute.Name, attribute.Value }); } var exportedAttributeValues = new Dictionary <string, object>(); foreach (ModelExportedValuesAttribute attribute in memberInfo.FindAttributes <ModelExportedValuesAttribute>()) { attribute.FillValues(exportedAttributeValues); } methodInfo = typeof(ModelNode).GetMethod("SetSerializableValues", bindingFlags); methodInfo.Invoke(propertyNode, new object[] { exportedAttributeValues }); }
AssociationAttribute GetAssociationAttribute(IMemberInfo memberInfo, ProvidedAssociationAttribute providedAssociationAttribute) { var associationAttribute = memberInfo.FindAttribute<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; }
void HandleSequencePropertyAttribute(IMemberInfo memberInfo) { var sequencePropertyAttribute = memberInfo.FindAttribute<SequencePropertyAttribute>(); if (sequencePropertyAttribute != null) { var typeInfo = ReflectionHelper.FindTypeDescendants(XafTypesInfo.Instance.FindTypeInfo(typeof(IReleasedSequencePropertyEditor))).SingleOrDefault(); if (typeInfo != null) memberInfo.AddAttribute(new CustomAttribute("PropertyEditorType", typeInfo.FullName)); } }
private static bool IsMapable(this IMemberInfo info) { var isMappable = info.IsPersistent && !info.IsService && info.Name != GCRecordField.StaticName; if (isMappable) { var browsableAttribute = info.FindAttribute <BrowsableAttribute>(); var isBrowsable = browsableAttribute == null || browsableAttribute.Browsable; var visibleInLookupListViewAttribute = info.FindAttribute <VisibleInLookupListViewAttribute>(); var visibleInLookup = visibleInLookupListViewAttribute == null || (bool)visibleInLookupListViewAttribute.Value; var visibleInListViewAttribute = info.FindAttribute <VisibleInListViewAttribute>(); var visibleInListView = visibleInListViewAttribute == null || (bool)visibleInListViewAttribute.Value; var visibleInExcelMapAttribute = info.FindAttribute <VisibleInExcelMapAttribute>(); var visibleInExcelMap = visibleInExcelMapAttribute == null || visibleInExcelMapAttribute.Visible; return((isBrowsable && visibleInLookup && visibleInListView) || visibleInExcelMap); } return(false); }
private static bool IsDefaultValue(IMemberInfo member, object value) { var defaultValueAttribute = member.FindAttribute <DefaultValueAttribute>(); if (defaultValueAttribute == null) { return(false); } return(Equals(defaultValueAttribute.Value, value)); }
public static String GetImmediatePostDataScript(IMemberInfo memberInfo, Boolean Force = false) { ImmediatePostDataAttribute immediatePostDataAttribute = memberInfo.FindAttribute <ImmediatePostDataAttribute>(); if ((immediatePostDataAttribute != null && immediatePostDataAttribute.Value != null) || Force) { return("RaiseXafCallback(globalCallbackControl, '', 'XafParentWindowRefresh', '', false);"); } return(""); }
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))); } }
object GetValue(XElement simpleElement, IMemberInfo memberInfo) { var valueConverterAttribute = memberInfo.FindAttribute <ValueConverterAttribute>(); var valueConverter = valueConverterAttribute?.Converter; if (valueConverter != null && !(valueConverter is EnumsConverter)) { var value = GetValue(valueConverter.StorageType, simpleElement); return(valueConverter.ConvertFromStorageType(value)); } return(GetValue(GetMemberType(memberInfo), simpleElement)); }
private AssociationAttribute assertMemberCreation(object collection, string name, Type type) { Assert.IsNotNull(collection); ITypeInfo typeInfo = XafTypesInfo.CastTypeToTypeInfo(type); IMemberInfo memberInfo = typeInfo.FindMember(name); Assert.IsNotNull(memberInfo); var attribute = memberInfo.FindAttribute <AssociationAttribute>(); Assert.IsNotNull(attribute); Assert.AreEqual("association", attribute.Name); return(attribute); }
SerializationStrategy GetSerializationStrategy(IMemberInfo memberInfo, SerializationStrategy serializationStrategy) { if (memberInfo.MemberTypeInfo.IsPersistent) { var attribute = memberInfo.MemberTypeInfo.FindAttribute <SerializationStrategyAttribute>(); if (attribute != null) { return(attribute.SerializationStrategy); } } var serializationStrategyAttribute = memberInfo.FindAttribute <SerializationStrategyAttribute>(); return(serializationStrategyAttribute != null ? serializationStrategyAttribute.SerializationStrategy : serializationStrategy); }
public static void SetupEnumPropertyDataSource <TControlItem>(this IMemberInfo memberInfo, object objectInstance, IObjectSpace objectSpace, TControlItem[] startitems, IList controlItems, Func <TControlItem, object> itemValueSelector) { var dataSourcePropertyAttribute = memberInfo.FindAttribute <DataSourcePropertyAttribute>(); if (dataSourcePropertyAttribute != null && objectInstance != null) { var noneItem = startitems.FirstOrDefault(item => itemValueSelector(item) == null); var member = memberInfo.Owner.FindMember(dataSourcePropertyAttribute.DataSourceProperty); var items = ((IEnumerable)member.GetValue(objectInstance)).Cast <object>() .Select(o => { var controlItem = startitems.First(item => $"{itemValueSelector(item)}" == $"{o}"); return(controlItem); }).ToArray(); controlItems.Clear(); if (noneItem != null) { controlItems.Add(noneItem); } foreach (var item in items) { controlItems.Add(item); } } foreach (var attribute in memberInfo.Owner.FindAttributes <EnumFilterAttribute>()) { if (attribute.PropertyName == memberInfo.Name) { var isObjectFitForCriteria = attribute.Criteria == null? true : objectSpace.IsObjectFitForCriteria(memberInfo.MemberType, objectInstance, CriteriaOperator.Parse(attribute.Criteria)); if (isObjectFitForCriteria.HasValue && isObjectFitForCriteria.Value) { var items = dataSourcePropertyAttribute == null ? startitems : controlItems.Cast <TControlItem>().ToArray(); controlItems.Clear(); items = attribute.FilterMode == EnumFilterMode.Remove ? items.Where(item => !attribute.Values.Contains(item)).ToArray() : items.Where(item => attribute.Values.Contains(item)).ToArray(); foreach (var item in items) { controlItems.Add(item); } } } } }
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); }
CriteriaOperator CreateOperand(IMemberInfo memberInfo, SelectStatement selectStatement) { var referenceInfoAttribute = memberInfo.FindAttribute<ReferenceInfoAttribute>(); return new QueryOperand(GetColumnName(memberInfo, referenceInfoAttribute), GetAlias(referenceInfoAttribute, selectStatement)); }
public string GetColumnNameCore(IMemberInfo info) { var persistentAttribute = info.FindAttribute<PersistentAttribute>(); return persistentAttribute != null ? persistentAttribute.MapTo : info.Name; }
IMemberInfo GetCollectionMemberInfo(IMemberInfo memberInfo) { var pivotedPropertyAttribute = memberInfo.FindAttribute <PivotedPropertyAttribute>(); return(View != null?View.ObjectTypeInfo.FindMember(pivotedPropertyAttribute.CollectionName) : null); }
bool IsKey(IMemberInfo memberInfo) { return(memberInfo.IsKey || memberInfo.FindAttribute <SerializationKeyAttribute>() != null); }
public string GetColumnNameCore(IMemberInfo info) { var persistentAttribute = info.FindAttribute <PersistentAttribute>(); return(persistentAttribute != null ? persistentAttribute.MapTo : info.Name); }
CriteriaOperator CreateOperand(IMemberInfo memberInfo, SelectStatement selectStatement) { var referenceInfoAttribute = memberInfo.FindAttribute <ReferenceInfoAttribute>(); return(new QueryOperand(GetColumnName(memberInfo, referenceInfoAttribute), GetAlias(referenceInfoAttribute, selectStatement))); }
private static bool IsScriptable(IMemberInfo m) { return(m.IsPersistent && m.IsPublic && !m.IsReadOnly && m.FindAttribute <IgnoreInScriptingAttribute>() == null); }
bool IsKey(IMemberInfo memberInfo) { return memberInfo.IsKey || memberInfo.FindAttribute<SerializationKeyAttribute>() != null; }
SerializationStrategy GetSerializationStrategy(IMemberInfo memberInfo, SerializationStrategy serializationStrategy) { if (memberInfo.MemberTypeInfo.IsPersistent) { var attribute = memberInfo.MemberTypeInfo.FindAttribute<SerializationStrategyAttribute>(); if (attribute != null) { return attribute.SerializationStrategy; } } var serializationStrategyAttribute = memberInfo.FindAttribute<SerializationStrategyAttribute>(); return serializationStrategyAttribute != null ? serializationStrategyAttribute.SerializationStrategy : serializationStrategy; }