/// <summary> /// Add a generic supplier to the type reference /// </summary> public void AddGenericSupplier(string parameterName, TypeReference typeReference, bool throwOnError) { if (GenericSupplier == null) { GenericSupplier = new List <TypeReference>(); } // Sanity check if (Class != null && (Class.TypeParameters == null || Class.TypeParameters.Find(o => o.ParameterName == parameterName) == null)) { throw new InvalidOperationException(string.Format("Can't assign type parameter '{0}' on class '{1}' as no such parameter exists", parameterName, Name)); } TypeParameter tp = new TypeParameter(); tp.ParameterName = parameterName; tp.Name = typeReference.name; tp.container = typeReference.container; tp.MemberOf = typeReference.MemberOf; tp.GenericSupplier = typeReference.GenericSupplier; tp.Flavor = typeReference.Flavor; // Turns out that the generic supplier can in fact contain more than one traversal name // for different types that are placed at the point of contact... soo... // this can cause if (GenericSupplier.Exists(o => (o as TypeParameter).ParameterName.Equals(tp.ParameterName)) && throwOnError) { throw new ArgumentException(String.Format("More than one supplier is provided for the same type parameter '{0}' on class '{1}'. This is not permitted!", tp.ParameterName, Name)); } GenericSupplier.Add(tp); }
public void AddTypeParameter(TypeParameter p) { p.Container = new Property(); p.Container.Container = this; if (TypeParameters == null) { TypeParameters = new List <TypeParameter>(); } TypeParameters.Add(p); }
/// <summary> /// Add a generic supplier to the type reference /// </summary> public void AddGenericSupplier(string parameterName, TypeReference typeReference, bool throwOnError) { if (GenericSupplier == null) GenericSupplier = new List<TypeReference>(); // Sanity check if (Class != null && (Class.TypeParameters == null || Class.TypeParameters.Find(o => o.ParameterName == parameterName) == null)) throw new InvalidOperationException(string.Format("Can't assign type parameter '{0}' on class '{1}' as no such parameter exists", parameterName, Name)); TypeParameter tp = new TypeParameter(); tp.ParameterName = parameterName; tp.Name = typeReference.name; tp.container = typeReference.container; tp.MemberOf = typeReference.MemberOf; tp.GenericSupplier = typeReference.GenericSupplier; tp.Flavor = typeReference.Flavor; // Turns out that the generic supplier can in fact contain more than one traversal name // for different types that are placed at the point of contact... soo... // this can cause if (GenericSupplier.Exists(o => (o as TypeParameter).ParameterName.Equals(tp.ParameterName)) && throwOnError) throw new ArgumentException(String.Format("More than one supplier is provided for the same type parameter '{0}' on class '{1}'. This is not permitted!", tp.ParameterName, Name)); GenericSupplier.Add(tp); }
public void AddTypeParameter(TypeParameter p) { p.Container = new Property(); p.Container.Container = this; if (TypeParameters == null) TypeParameters = new List<TypeParameter>(); TypeParameters.Add(p); }
/// <summary> /// Resolve a generic parameter to a concrete class if possible /// </summary> /// <param name="context">The parent class which contains the generic bindings</param> /// <param name="supplier">The current supplier to look for</param> /// <returns>The real type reference</returns> private TypeReference ResolveGenericParameter(TypeReference context, TypeParameter supplier) { if(context.Class == null || context.GenericSupplier == null || context.Class.TypeParameters.Count != context.GenericSupplier.Count) return supplier; // Can't resolve TypeReference retVal = supplier; // In case we can't find for (int i = 0; i < context.Class.TypeParameters.Count; i++) if (context.Class.TypeParameters[i].ParameterName == supplier.ParameterName && retVal == supplier) retVal = context.GenericSupplier[i]; // Found, return the found value else if (retVal == supplier && context.GenericSupplier[i].GenericSupplier != null && context.GenericSupplier[i].GenericSupplier.Count > 0) retVal = ResolveGenericParameter(context.GenericSupplier[i], supplier); return retVal; // Can't find }