public static List<GenericDeclaration> FromXElement (XElement generic) { List<GenericDeclaration> decls = new List<GenericDeclaration> (); if (generic == null) return decls; decls.AddRange (from decl in generic.Descendants ("param") select new GenericDeclaration ((string)decl.Attribute ("name"))); var constraints = from constr in generic.Descendants ("where") select BaseConstraint.FromXElement (constr); foreach (BaseConstraint constr in constraints) { GenericDeclaration decl = FindGenericDeclFor (constr, decls); if (decl != null) decl.Constraints.Add (constr); } return decls; }
public bool IsEqualityConstrainedByAssociatedType(GenericDeclaration generic, TypeMapper typeMap) { return(AssociatedTypeDeclarationFromConstrainedGeneric(generic, typeMap) != null); }
public AssociatedTypeDeclaration AssociatedTypeDeclarationFromConstrainedGeneric(GenericDeclaration generic, TypeMapper typeMap) { // looking for where U == T.At1[.At2...] if (generic.Constraints.Count != 1) { return(null); } var eqConstraint = generic.Constraints [0] as EqualityConstraint; if (eqConstraint == null) { return(null); } var namedSpec = eqConstraint.Type2Spec as NamedTypeSpec; if (namedSpec == null) { return(null); } var parts = namedSpec.Name.Split('.'); if (parts.Length <= 1) { return(null); } if (!IsTypeSpecGeneric(parts [0])) { return(null); } var refProto = GetConstrainedAssociatedTypeProtocol(new NamedTypeSpec(parts [0]), typeMap); if (refProto == null) { return(null); } if (parts.Length > 2) { throw new NotImplementedException($"Not currently supporting equality constraints of nested associated types (yet) {eqConstraint.Type1} == {eqConstraint.Type2}"); } return(refProto.Protocol.AssociatedTypeNamed(parts [1])); }
public ProtocolDeclaration OwningProtocolFromConstrainedGeneric(GenericDeclaration generic, TypeMapper typeMap) { var refProto = RefProtoFromConstrainedGeneric(generic, typeMap); return(refProto?.Protocol); }