protected override void OnInitialized() { base.OnInitialized(); if (!Sortable) { Sortable = SorterMultiple != default || SorterCompare != default || Sort != default; } if (IsHeader) { if (FieldExpression != null) { _propertyReflector = PropertyReflector.Create(FieldExpression); if (Sortable) { SortModel = new SortModel <TData>(_propertyReflector.Value.PropertyInfo, SorterMultiple, Sort, SorterCompare); } } else { (GetValue, SortModel) = ColumnDataIndexHelper <TData> .GetDataIndexConfig(this); } } else if (IsBody) { SortModel = Context.HeaderColumns[ColIndex] is IFieldColumn fieldColumn ? fieldColumn.SortModel : null; (GetValue, _) = ColumnDataIndexHelper <TData> .GetDataIndexConfig(this); } ClassMapper .If("ant-table-column-has-sorters", () => Sortable) .If($"ant-table-column-sort", () => Sortable && SortModel != null && SortModel.SortType.IsIn(SortType.Ascending, SortType.Descending)); }
private IPropertyInformation EnsurePropertyDefinitionExisitsOnClassDefinition( ClassDefinition classDefinition, Type declaringType, string propertyName) { var propertyInfo = PropertyInfoAdapter.Create(declaringType.GetProperty(propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)); var propertyReflector = new PropertyReflector( classDefinition, propertyInfo, new ReflectionBasedMemberInformationNameResolver(), PropertyMetadataProvider, DomainModelConstraintProviderStub); var propertyDefinition = propertyReflector.GetMetadata(); if (!classDefinition.MyPropertyDefinitions.Contains(propertyDefinition.PropertyName)) { var propertyDefinitions = new PropertyDefinitionCollection(classDefinition.MyPropertyDefinitions, false); propertyDefinitions.Add(propertyDefinition); PrivateInvoke.SetNonPublicField(classDefinition, "_propertyDefinitions", propertyDefinitions); var endPoints = new RelationEndPointDefinitionCollection(classDefinition.MyRelationEndPointDefinitions, false); endPoints.Add(MappingObjectFactory.CreateRelationEndPointDefinition(classDefinition, propertyInfo)); PrivateInvoke.SetNonPublicField(classDefinition, "_relationEndPoints", endPoints); } return(propertyInfo); }
private static string ExtractString(dynamic field) { if (field == null) { return(""); } if (field is string) { return(field.ToString()); } var result = ""; if (field is Dictionary <string, string> ) { foreach (string prop in field.Keys) { result += " " + ExtractString(field[prop]); } return(result); } var properties = PropertyReflector.GetProperties(field); foreach (string prop in properties.Keys) { result += " " + ExtractString(properties[prop]); } return(result); }
public void GetMetadata_ForSealedBusinessObject_WithExistingMixin() { var mixinTargetType = typeof(ManualBusinessObject); var businessObjectType = typeof(SealedBindableObject); Assertion.IsTrue(mixinTargetType.IsAssignableFrom(businessObjectType)); using (MixinConfiguration.BuildNew() .AddMixinToClass( MixinKind.Extending, mixinTargetType, typeof(MixinStub), MemberVisibility.Public, Enumerable.Empty <Type>(), Enumerable.Empty <Type>()) .EnterScope()) { IPropertyInformation propertyInfo = GetPropertyInfo(typeof(ClassWithReferenceType <SealedBindableObject>), "Scalar"); PropertyReflector propertyReflector = PropertyReflector.Create(propertyInfo, _businessObjectProvider); var referenceProperty = (IBusinessObjectReferenceProperty)propertyReflector.GetMetadata(); Assert.That(() => referenceProperty.SupportsSearchAvailableObjects, Throws.Nothing); } }
public override void Given() { base.Given(); WorkItemStore = TimedAction(() => IntegrationSettings.CreateRestStore(), "REST", "WIS Create"); ConfigureOptions(); var pr = new PropertyReflector(); var pi = new PropertyInspector(pr); var attMapper = new AttributeMapperStrategy(pi); var mapper = new WorkItemMapper(attMapper); var translator = new WiqlTranslator(); var pe = new PartialEvaluator(); var qr = new QueryRewriter(); var wqb = new WiqlQueryBuilder(translator, pe, qr); var qp = new MapperTeamFoundationServerWorkItemQueryProvider( WorkItemStore, wqb, mapper); Query = new Query <Bug>(qp, wqb); _ids = new[] { 8663955 }; }
void IFormItem.AddControl <TValue>(AntInputComponentBase <TValue> control) { if (control.FieldIdentifier.Model == null) { throw new InvalidOperationException($"Please use @bind-Value in the control with generic type `{typeof(TValue)}`."); } this._control = control; CurrentEditContext.OnValidationStateChanged += (s, e) => { control.ValidationMessages = CurrentEditContext.GetValidationMessages(control.FieldIdentifier).ToArray(); this._isValid = !control.ValidationMessages.Any(); StateHasChanged(); }; _formValidationMessages = builder => { var i = 0; builder.OpenComponent <FormValidationMessage <TValue> >(i++); builder.AddAttribute(i++, "Control", control); builder.CloseComponent(); }; _propertyReflector = PropertyReflector.Create(control.ValueExpression); if (_propertyReflector.RequiredAttributes.Any()) { _labelCls = $"{_prefixCls}-required"; } }
public static void ApplyCorrectYeKeToProperties(this object obj) { if (obj == null) { throw new ArgumentNullException(nameof(obj)); } var propertyInfos = obj.GetType().GetProperties( BindingFlags.Public | BindingFlags.Instance ).Where(p => p.CanRead && p.CanWrite && p.PropertyType == typeof(string)); var propertyReflector = new PropertyReflector(); foreach (var propertyInfo in propertyInfos) { var propName = propertyInfo.Name; var value = propertyReflector.GetValue(obj, propName); if (value != null) { var strValue = value.ToString(); var newVal = strValue.ApplyCorrectYeKe(); if (newVal == strValue) { continue; } propertyReflector.SetValue(obj, propName, newVal); } } }
public CompanyInformationModel GetCompanyInformationModel() { //if (getcompanyInformationModel==null) //{ var companyInformationModel = new CompanyInformationModel(); var pr = new PropertyReflector(); var dict = companyInformationModel.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly) .ToDictionary(prop => prop.Name, prop => prop?.GetValue(companyInformationModel, null)?.ToString() ?? ""); var keyValues = _keyValues.Where(x => dict.Keys.Contains(x.Key)).ToList(); if (keyValues.Any()) { //keyValues.ForEach(x => x.Value = dict[x.Key]); foreach (var keyValue in keyValues) { pr.SetValue(companyInformationModel, keyValue.Key, keyValue.Value); } } getcompanyInformationModel = companyInformationModel; return(companyInformationModel); //} //else //{ // return getcompanyInformationModel; //} }
/// <summary> /// This Compare method helps to compare the values and it will return the SortDirection. /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> public int Compare(object x, object y) { var group = (x as Group); var group1 = (y as Group); for (int i = 0; i < (x as Group).GetTopLevelGroup().GroupDescriptions.Count; i++) { if (group.Records == null) { group = group.Groups.FirstOrDefault() as Group; group1 = group1.Groups.FirstOrDefault() as Group; } } object record = group.Records.FirstOrDefault().Data; object record1 = group1.Records.FirstOrDefault().Data; var key1 = PropertyReflector.GetValue(record, ColumnName); var key2 = PropertyReflector.GetValue(record1, ColumnName); char[] first = key1.ToString().ToCharArray(); char[] second = key2.ToString().ToCharArray(); int compareFirstValue = Convert.ToInt32(first[0]); int compareSecondValue = Convert.ToInt32(second[0]); var diff = compareFirstValue.CompareTo(compareSecondValue); if (diff > 0) { return(SortDirection == ListSortDirection.Ascending ? 1 : -1); } if (diff == -1) { return(SortDirection == ListSortDirection.Ascending ? -1 : 1); } return(0); }
protected IEnumerable <PropertyBase> GetProperties() { IPropertyFinder propertyFinder = _metadataFactory.CreatePropertyFinder(_concreteType); Dictionary <string, PropertyBase> propertiesByName = new Dictionary <string, PropertyBase>(); foreach (IPropertyInformation propertyInfo in propertyFinder.GetPropertyInfos()) { PropertyReflector propertyReflector = _metadataFactory.CreatePropertyReflector(_concreteType, propertyInfo, _businessObjectProvider); PropertyBase property = propertyReflector.GetMetadata(); if (propertiesByName.ContainsKey(property.Identifier)) { string message = string.Format( "Type '{0}' has two properties called '{1}', this is currently not supported.", TargetType.FullName, property.Identifier); throw new NotSupportedException(message); } else { propertiesByName.Add(property.Identifier, property); } } return(propertiesByName.Values); }
private IBusinessObjectProperty GetMetadataFromPropertyReflector(string propertyName) { IPropertyInformation propertyInfo = GetPropertyInfo(typeof(ClassWithAllDataTypes), propertyName); PropertyReflector propertyReflector = PropertyReflector.Create(propertyInfo, _businessObjectProvider); return(propertyReflector.GetMetadata()); }
public static void ApplyCorrectYeKe(this object entity) { if (entity == null) { return; } var properties = entity .GetType() .GetProperties() .Where(p => string.Equals(p.PropertyType.Name, AppConsts.StringDataTypeName, StringComparison.CurrentCultureIgnoreCase)) .ToList(); var propertyReflector = new PropertyReflector(); foreach (var memberInfo in properties) { var name = memberInfo.Name; var targetObjectValue = propertyReflector.GetValue(entity, name); if (targetObjectValue != null) { propertyReflector .SetValue(entity, name, targetObjectValue.ToString().ApplyUnifiedYeKe()); } } }
private PropertyBase.Parameters GetPropertyParameters(IPropertyInformation property, BindableObjectProvider provider) { PropertyReflector reflector = PropertyReflector.Create(property, provider); return((PropertyBase.Parameters)PrivateInvoke.InvokeNonPublicMethod( reflector, typeof(PropertyReflector), "CreateParameters", GetUnderlyingType(reflector))); }
public void StorageClass_WithNoneAttribute() { PropertyReflector propertyReflector = CreatePropertyReflector <ClassWithPropertiesHavingStorageClassAttribute> ( "None", DomainModelConstraintProviderStub); Assert.That(propertyReflector.StorageClass, Is.EqualTo(StorageClass.None)); }
private static LambdaExpression GenerateGetterLambda <TInterface, TState, TArg>(PropertyInfo stateProperty) { var ctxParam = Expression.Parameter(typeof(IContext <TInterface, TState>), "ctx"); var stateGetter = Expression.Property(ctxParam, PropertyReflector <IContext <TInterface, TState> > .FromGetter(s => s.State)); var statePropertyGetter = Expression.Property(stateGetter, stateProperty); return(Expression.Lambda <Func <IContext <TInterface, TState>, TArg> >(statePropertyGetter, ctxParam)); }
public void Test_StronglyTyped_InvalidCast_Set( ) { using (var property = new PropertyReflector <string>(Agent007, "id")) { Assert.Catch <ArgumentException>(() => property.SetValue(Agent007, "Abacus"), "Expected InvalidCastException to be raised when attempting to" + " retrieve field of type Guid as a string."); } }
public void TestHasProperties() { TestClass obj = new TestClass(); Assert.False(PropertyReflector.HasProperty(obj, "123")); Assert.True(PropertyReflector.HasProperty(obj, "PublicProp")); Assert.True(PropertyReflector.HasProperty(obj, "NestedProperty")); }
public ReflectionSetterBenchmark() { _indexerEntity = new("hello word.", 1, 0.99M); var property = typeof(IndexerEntity).GetTypeInfo().GetProperty("Prop1"); _reflector = property.GetReflector(); _dotNextSetter = Type <IndexerEntity> .Property <string> .RequireSetter(nameof(IndexerEntity.Prop1)); }
public void Initialize() { IPropertyInformation propertyInfo = GetPropertyInfo(typeof(ClassWithAllDataTypes), "String"); PropertyReflector propertyReflector = PropertyReflector.Create(propertyInfo, _businessObjectProvider); Assert.That(propertyReflector.PropertyInfo, Is.SameAs(propertyInfo)); Assert.That(propertyReflector.BusinessObjectProvider, Is.SameAs(_businessObjectProvider)); }
public void Test_StronglyTyped_TargetException_Get( ) { using (var property = new PropertyReflector <Guid>(typeof(Person), "id")) { // This is a non-static field thus field access requires a target object instance. Assert.Catch <TargetException>(() => property.GetValue(null), "Expected TargetException to be raised when attempting to " + "retrieve the value of non-static property."); } }
void IFormItem.AddControl <TValue>(AntInputComponentBase <TValue> control) { if (_control != null) { return; } if (control.FieldIdentifier.Model == null) { throw new InvalidOperationException($"Please use @bind-Value (or @bind-Values for selected components) in the control with generic type `{typeof(TValue)}`."); } _fieldIdentifier = control.FieldIdentifier; this._control = control; if (Form.ValidateMode.IsIn(FormValidateMode.Rules, FormValidateMode.Complex)) { _fieldPropertyInfo = _fieldIdentifier.Model.GetType().GetProperty(_fieldIdentifier.FieldName); } _validationStateChangedHandler = (s, e) => { control.ValidationMessages = CurrentEditContext.GetValidationMessages(control.FieldIdentifier).Distinct().ToArray(); this._isValid = !control.ValidationMessages.Any(); StateHasChanged(); }; CurrentEditContext.OnValidationStateChanged += _validationStateChangedHandler; _formValidationMessages = builder => { var i = 0; builder.OpenComponent <FormValidationMessage <TValue> >(i++); builder.AddAttribute(i++, "Control", control); builder.CloseComponent(); }; if (control.ValueExpression is not null) { _propertyReflector = PropertyReflector.Create(control.ValueExpression); } else { _propertyReflector = PropertyReflector.Create(control.ValuesExpression); } if (_propertyReflector.RequiredAttribute != null) { _labelCls = $"{_prefixCls}-required"; } if (_propertyReflector.DisplayName != null) { Label ??= _propertyReflector.DisplayName; } }
public void Test_WeaklyTyped_TargetException_Set( ) { using (var property = new PropertyReflector(typeof(Person), "id")) { // This is a non-static field thus field access requires a target object instance. Assert.Catch <TargetException>(() => property.SetValue(null, Guid.NewGuid( )), "Expected TargetException to be raised when attempting to " + "assign the value of non-static property."); } }
public virtual PropertyReflector CreatePropertyReflector( Type concreteType, IPropertyInformation propertyInfo, BindableObjectProvider businessObjectProvider) { ArgumentUtility.CheckNotNull("concreteType", concreteType); ArgumentUtility.CheckNotNull("propertyInfo", propertyInfo); ArgumentUtility.CheckNotNull("businessObjectProvider", businessObjectProvider); return(PropertyReflector.Create(propertyInfo, businessObjectProvider)); }
/// <summary> /// This Compare method helps to compare the values and it will return the SortDirection. /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> public int Compare(object x, object y) { var group = (x as Group); var group1 = (y as Group); for (int i = 0; i < (x as Group).GetTopLevelGroup().GroupDescriptions.Count; i++) { if (group.Records == null) { group = group.Groups.FirstOrDefault() as Group; group1 = group1.Groups.FirstOrDefault() as Group; } } object record = group.Records.FirstOrDefault().Data; object record1 = group1.Records.FirstOrDefault().Data; var key1 = PropertyReflector.GetValue(record, ColumnName); var key2 = PropertyReflector.GetValue(record1, ColumnName); var ColumnType = key1.GetType(); int compareFirstValue = 0, compareSecondValue = 0; DateTime date = (DateTime)key1; DateTime date1 = (DateTime)key2; if (GroupMode == DateGroupingMode.Month) { compareFirstValue = date.Month; compareSecondValue = date1.Month; } else if (GroupMode == DateGroupingMode.Year) { compareFirstValue = date.Year; compareSecondValue = date.Year; } else if (GroupMode == DateGroupingMode.Week) { compareFirstValue = date.Day; compareSecondValue = date1.Day; } else { var dt = (DateRange)group.Key; var dt1 = (DateRange)group1.Key; compareFirstValue = (int)dt; compareSecondValue = (int)dt1; } var diff = compareFirstValue.CompareTo(compareSecondValue); if (diff > 0) { return(SortDirection == ListSortDirection.Ascending ? 1 : -1); } if (diff == -1) { return(SortDirection == ListSortDirection.Ascending ? -1 : 1); } return(0); }
public void GetMetadata_ForValueType() { IPropertyInformation propertyInfo = GetPropertyInfo(typeof(ClassWithReferenceType <ValueTypeBindableObject>), "Scalar"); PropertyReflector propertyReflector = PropertyReflector.Create(propertyInfo, _businessObjectProvider); var referenceProperty = (IBusinessObjectReferenceProperty)propertyReflector.GetMetadata(); Assert.That(() => referenceProperty.SupportsSearchAvailableObjects, Throws.Nothing); }
private static LambdaExpression GenerateSetterLambda <TInterface, TState, TArg>(PropertyInfo stateProperty) { var setMethod = stateProperty.GetSetMethod(); var ctxParam = Expression.Parameter(typeof(IContext <TInterface, TState>), "ctx"); var argParam = Expression.Parameter(typeof(TArg), "value"); var stateGetter = Expression.Property(ctxParam, PropertyReflector <IContext <TInterface, TState> > .FromGetter(s => s.State)); var statePropertySetMethod = Expression.Call(stateGetter, setMethod, argParam); return(Expression.Lambda <Action <IContext <TInterface, TState>, TArg> >(statePropertySetMethod, ctxParam, argParam)); }
public void Test_StronglyTyped_Get( ) { using (var property = new PropertyReflector <Guid>(Agent007, "id")) { Assert.NotNull(property.PropertyInfo, $"Property named \"id\" not found in type {Agent007.GetType( )}"); Assert.NotNull(property.GetValue(Agent007), $"Value returned was null."); Assert.IsTrue(property.Value is Guid, $"Unexpected value type for property \"id\" in {Agent007.GetType( )}, " + $"expected {typeof( Guid )}."); } }
public void Test_WeaklyTyped_Get( ) { // Wrapping instantiation in a using statements allows for automatic disposable of the reflector when // it's no longer required. using (var property = new PropertyReflector(Agent007, "id")) { Assert.NotNull(property.PropertyInfo, $"Property named \"id\" not found in type {Agent007.GetType( )}"); Assert.NotNull(property.GetValue(Agent007), $"Value returned was null."); } }
public void GetMetadata_WithEnumBase() { IPropertyInformation IPropertyInformation = GetPropertyInfo(typeof(ClassWithReferenceType <Enum>), "Scalar"); PropertyReflector propertyReflector = PropertyReflector.Create(IPropertyInformation, _businessObjectProvider); IBusinessObjectProperty businessObjectProperty = propertyReflector.GetMetadata(); Assert.That(businessObjectProperty, Is.TypeOf(typeof(NotSupportedProperty))); Assert.That(businessObjectProperty.Identifier, Is.EqualTo("Scalar")); }
public PropertyReflectorBenchmarks() { PropertyFakes.StaticProperty = "StaticProperty"; _staticField = typeof(PropertyFakes).GetTypeInfo().GetProperty("StaticProperty"); _staticFieldReflector = _staticField.GetReflector(); _instance = new PropertyFakes(); _instance.InstanceProperty = "InstanceProperty"; _field = typeof(PropertyFakes).GetTypeInfo().GetProperty("InstanceProperty"); _fieldReflector = _field.GetReflector(); }
void SaveSelectedLevel() { LevelConfiguration newLC = new LevelConfiguration (); newLC.levelNum = curentLevel; BaseActivityElement[] aEls = levelContainer.GetComponentsInChildren<BaseActivityElement> (); for (int i = 0; i < aEls.Length; i++) { BaseElement e = aEls[i]; BaseActivityElement _bae = e as BaseActivityElement; ElementRflector el = new ElementRflector(); newLC.elements.Add(el); el.elementType = e.ElementType; el.position = new float[3]{e.transform.position.x, e.transform.position.y, e.transform.position.z}; IwPropertyValue<PropertyType, int>[] elProps = e.gameObject.GetComponents<IwPropertyValue<PropertyType, int>>(); for (int p = 0; p < elProps.Length; p++) { IwPropertyValue<PropertyType, int> _be = elProps[p]; PropertyReflector pr = new PropertyReflector(_be.propType, _be.val, _be.maxVal); el.properties.Add(pr); } if(_bae != null){ IElementFunction<BaseElement>[] elfuncs = e.gameObject.GetComponents<IElementFunction<BaseElement>>(); for (int f = 0; f < elfuncs.Length; f++) { IElementFunction<BaseElement> func = elfuncs[f]; FunctionReflector fr = new FunctionReflector(func.functionType); el.functions.Add(fr); } } Debug.Log("element saved"); } // if (curentLevel >= levels.Count) { // levels.Add (newLC); // newLC.levelNum = levels.Count - 1; // curentLevel = newLC.levelNum; // } else { // levels[curentLevel] = newLC; // } saveAndLoad.SaveLevelToPrefs (newLC); }