public Type GetPropertyType(string propertyExpression) { var propertyDesc = PropertyDescriptors.FirstOrDefault( propertyDescriptor => propertyDescriptor.PropertyName == propertyExpression); return(propertyDesc != null ? propertyDesc.PropertyType : null); }
public void Add(TLDefinition tld, Stream srcStm) { TLFunction tlf = tld as TLFunction; if (tlf != null) { if (tlf.Signature.IsExtension) { Extensions.Add(tlf, srcStm); } else if (tlf.IsTopLevelFunction) { if (tlf.Signature is SwiftAddressorType) { Variables.Add(tlf, srcStm); } else if (tlf.Signature is SwiftWitnessTableType) { WitnessTables.Add(tld, srcStm); } else { Functions.Add(tlf, srcStm); } } else { if (tlf.Class.EntityKind == MemberNesting.Protocol) { Protocols.Add(tlf, srcStm); } else { Classes.Add(tld, srcStm); } } } else { if (tld is TLVariable tlvar && ((TLVariable)tld).Class == null) { if (tlvar is TLPropertyDescriptor propDesc) { if (propDesc.ExtensionOn != null) { ExtensionDescriptors.Add(propDesc); } else { PropertyDescriptors.Add(tlvar, srcStm); } } else { Variables.Add(tld, srcStm); } }
public IEnumerable <object> GetRowValues(RowItem rowItem) { var rawValues = PropertyDescriptors.Select(pd => pd.GetValue(rowItem)); if (Transform != null) { return(Transform.TransformRow(rawValues).Cast <object>()); } return(rawValues); }
/// <summary> /// Ctor. /// </summary> /// <param name="eventTypeData">The event type data.</param> public CatalystEventType(XElement eventTypeData) { _eventTypeData = eventTypeData; Name = EventTypeExtensions.RequireAttribute(_eventTypeData, "name"); PropertyDescriptors = _eventTypeData .Elements("propertyDescriptor") .Select(element => element.ToEventPropertyDescriptor()) .ToList(); PropertyNames = PropertyDescriptors .Select(propertyDescriptor => propertyDescriptor.PropertyName) .ToList(); }
/// <summary> /// Fluent entry point to configure the viewmodel's property specified through the param: <paramref name="propertyName"/> (e.g. RegisterProperty(nameof(Property))) /// </summary> /// <typeparam name="TResult">Type of the property</typeparam> /// <param name="propertyName">Property name</param> /// <returns>A <see cref="ViewModelPropertyDescriptor{TOwner, TResult}"/> describing the property specified through <paramref name="exp"/></returns> protected internal static ViewModelPropertyDescriptor <TInheritor, TResult> RegisterProperty <TResult>(string propertyName) { ViewModelPropertyDescriptor <TInheritor, TResult> result; if (PropertyDescriptors.TryGetValue(propertyName, out var desc)) { result = desc as ViewModelPropertyDescriptor <TInheritor, TResult>; } else { PropertyDescriptors.Add(propertyName, result = new ViewModelPropertyDescriptor <TInheritor, TResult>(propertyName)); } return(result); }
/// <summary> /// It is intended to be used as the implementation of the <b>set</b> accessors of the properties on the inheritor ViewModel class. It returns the value set using <see cref="SetValue{T}(T, string)"/> /// </summary> /// <typeparam name="T">Type of the property</typeparam> /// <param name="value">The value assigned to the property</param> /// <param name="propertyName">Name of the property</param> /// <remarks> /// This method ensures the following in order: /// - Apply validations on the property. <see cref="ViewModelPropertyDescriptor{TOwner, TResult}.ValidateAlways"/>, <see cref="HasErrors"/>, <see cref="GetValidationResults(string)"/> /// - Apply coerce on new values /// - Validate coerced values if desired /// - Assign value to the property /// - Apply value setters on the property /// - Record the property set if the property assignation is in an edition scope /// - Notify property change when property is not in an edition scope /// </remarks> protected virtual bool SetValue <T>(T value, [CallerMemberName] string propertyName = null) { if (!_values.TryGetValue(propertyName, out IViewModelProperty prop)) { if (!PropertyDescriptors.ContainsKey(propertyName)) { PropertyDescriptors.Add(propertyName, new ViewModelPropertyDescriptor <TInheritor, T>(propertyName)); } prop = new ViewModelProperty <TInheritor, T>(); _values.Add(propertyName, prop); } return(((ViewModelProperty <TInheritor, T>)prop).SetValue((TInheritor)this, propertyName, value)); }
protected virtual void SetCollection <T>(T collection, [CallerMemberName] string propertyName = null) where T : ICollection, INotifyCollectionChanged { if (!_values.TryGetValue(propertyName, out IViewModelProperty prop)) { if (!PropertyDescriptors.ContainsKey(propertyName)) { PropertyDescriptors.Add(propertyName, new ViewModelCollectionPropertyDescriptor <TInheritor, T>(propertyName)); } prop = new ViewModelCollectionProperty <TInheritor, T>(); _values.Add(propertyName, prop); } ((ViewModelCollectionProperty <TInheritor, T>)prop).SetValue((TInheritor)this, propertyName, collection); }
public object GetRowValue(RowItem rowItem, DataPropertyDescriptor propertyDescriptor) { if (Transform == null) { return(propertyDescriptor.GetValue(rowItem)); } var pdIndex = PropertyDescriptors.IndexOf(propertyDescriptor); if (pdIndex < 0) { return(null); } return(GetRowValues(rowItem).Skip(pdIndex).FirstOrDefault()); }
//readonly ILoggerFacade logger = ServiceLocator.Current.GetInstance<ILoggerFacade>(LogNames.Session); private void BuildClassResults(object entity, IList <ValidationError> errors) { if (ClassValidators == null || !ClassValidators.Any()) { return; } //var timer = new Stopwatch(); #if DEBUG var timer2 = new Stopwatch(); #endif // timer.Start(); var ctxt = new ValidationContext(entity); foreach (var attr in ClassValidators) { #if DEBUG timer2.Start(); #endif var result = attr.GetValidationResult(entity, ctxt); #if DEBUG timer2.Stop(); var message = string.Format("IP/ED dataset imports - Time of Execution of class validation {2}: {0}:{1}", timer2.Elapsed.Seconds, timer2.Elapsed.Milliseconds, attr.GetType().Name); Trace.WriteLine(message); timer2.Reset(); #endif if (result != null && !string.IsNullOrEmpty(result.ErrorMessage)) { #if DEBUG timer2.Start(); #endif ValidationErrorState errorState = (attr.GetType() == typeof(RejectIfAnyPropertyHasValueAttribute)) ? ValidationErrorState.ExcludedByCrosswalk : ValidationErrorState.ValidationError; if (result.MemberNames != null && result.MemberNames.Any()) { foreach (var memberName in result.MemberNames.ToList()) { PropertyDescriptor propDesc; if (PropertyDescriptors.TryGetValue(memberName, out propDesc)) { errors.Add(new ValidationError(result.ErrorMessage, PropertyDescriptors[memberName].Property, errorState)); } else { errors.Add(new ValidationError(result.ErrorMessage, null, errorState)); } } } else { errors.Add(new ValidationError(result.ErrorMessage, null, errorState)); } #if DEBUG timer2.Stop(); var message2 = string.Format("IP/ED dataset imports - Time of Execution of message processing: {0}:{1}", timer2.Elapsed.Seconds, timer2.Elapsed.Milliseconds); Trace.WriteLine(message2); #endif } } // timer.Stop(); // var message3 = string.Format("IP/ED dataset imports - Overall Time of Execution of all class validations: {0}:{1}", // timer.Elapsed.Seconds, timer.Elapsed.Milliseconds); // Trace.WriteLine(message3); //if(logger != null) // logger.Write(message, Category.Debug, Priority.High); }
public void Add(TLDefinition tld, Stream srcStm) { TLFunction tlf = tld as TLFunction; if (tlf != null) { if (IsConstructor(tlf.Signature, tlf.Class)) { Constructors.Add(tlf, srcStm); } else if (tlf.Signature is SwiftClassConstructorType) { if (ClassConstructor.Values.Count() == 0) { ClassConstructor.Add(tlf, srcStm); } else { throw ErrorHelper.CreateError(ReflectorError.kInventoryBase + 12, $"multiple type metadata accessors for {tlf.Class.ClassName.ToFullyQualifiedName ()}"); } } else if (IsDestructor(tlf.Signature, tlf.Class)) { Destructors.Add(tlf, srcStm); } else if (IsProperty(tlf.Signature, tlf.Class)) { if (IsSubscript(tlf.Signature, tlf.Class)) { if (IsPrivateProperty(tlf.Signature, tlf.Class)) { PrivateSubscripts.Add(tlf); } else { Subscripts.Add(tlf); } } else { if (IsStaticProperty(tlf.Signature, tlf.Class)) { if (IsPrivateProperty(tlf.Signature, tlf.Class)) { StaticPrivateProperties.Add(tlf, srcStm); } else { StaticProperties.Add(tlf, srcStm); } } else { if (IsPrivateProperty(tlf.Signature, tlf.Class)) { PrivateProperties.Add(tlf, srcStm); } else { Properties.Add(tlf, srcStm); } } } } else if (IsMethodOnClass(tlf.Signature, tlf.Class)) { if (tlf is TLMethodDescriptor) { MethodDescriptors.Add(tlf, srcStm); } else { Methods.Add(tlf, srcStm); } } else if (IsStaticMethod(tlf.Signature, tlf.Class)) { StaticFunctions.Add(tlf, srcStm); } else if (IsWitnessTable(tlf.Signature, tlf.Class)) { WitnessTable.Add(tlf, srcStm); } else if (IsInitializer(tlf.Signature, tlf.Class)) { Initializers.Add(tlf, srcStm); } else { FunctionsOfUnknownDestination.Add(tlf); } return; } var meta = tld as TLDirectMetadata; if (meta != null) { if (DirectMetadata != null) { throw ErrorHelper.CreateError(ReflectorError.kInventoryBase + 13, $"duplicate direct metadata in class {DirectMetadata.Class.ClassName.ToFullyQualifiedName ()}"); } DirectMetadata = meta; return; } var lazy = tld as TLLazyCacheVariable; if (lazy != null) { if (LazyCacheVariable != null) { throw ErrorHelper.CreateError(ReflectorError.kInventoryBase + 14, $"duplicate lazy cache variable in class {LazyCacheVariable.Class.ClassName.ToFullyQualifiedName ()}"); } LazyCacheVariable = lazy; return; } var mc = tld as TLMetaclass; if (mc != null) { if (Metaclass != null) { throw ErrorHelper.CreateError(ReflectorError.kInventoryBase + 15, $"duplicate type meta data descriptor in class {Metaclass.Class.ClassName.ToFullyQualifiedName ()}"); } Metaclass = mc; return; } var nom = tld as TLNominalTypeDescriptor; if (nom != null) { if (TypeDescriptor != null) { throw ErrorHelper.CreateError(ReflectorError.kInventoryBase + 16, $"duplicate nominal type descriptor in class {TypeDescriptor.Class.ClassName.ToFullyQualifiedName ()}"); } TypeDescriptor = nom; return; } var tlvar = tld as TLVariable; if (tlvar != null) { if (tlvar is TLPropertyDescriptor tlpropDesc) { PropertyDescriptors.Add(tlpropDesc); } else { Variables.Add(tlvar, srcStm); } return; } var tlprot = tld as TLProtocolConformanceDescriptor; if (tlprot != null) { ProtocolConformanceDescriptors.Add(tlprot); return; } DefinitionsOfUnknownDestination.Add(tld); }
public EventPropertyDescriptor GetPropertyDescriptor(string propertyName) { return(PropertyDescriptors.FirstOrDefault( propertyDescriptor => propertyDescriptor.PropertyName == propertyName)); }