public static IEnumerable <TypeDefinition> AvailableTraits(this EntityInstance instance, ComputationContext ctx) { IEntityScope scope = instance.Target.Cast <TemplateDefinition>(); if (scope is TypeDefinition typedef) { foreach (TypeDefinition trait in typedef.AssociatedTraits) { // todo: once computed which traits fit maybe we could cache them within given instance? ConstraintMatch match = TypeMatcher.ArgumentsMatchConstraintsOf(ctx, trait.Name.Parameters, instance); if (match != ConstraintMatch.Yes) { continue; } yield return(trait); } } }
public static void Validate(IEntityScope @this, ComputationContext ctx) { foreach (IMember member in @this.NestedMembers()) { if (!member.Modifier.HasNative && member.Modifier.HasPrivate && !member.Modifier.IsPolymorphic && // in NVI pattern private is used externally !member.IsMemberUsed) { // at this level property accessors are not used, only property itself is used if (member is FunctionDefinition func && func.IsPropertyAccessor(out Property prop) && !prop.IsIndexer) { continue; } else { ctx.AddError(ErrorCode.BindableNotUsed, member.Name); } } }