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); } }
/// <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)); }
/// <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); }
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 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); }