private static GenericTypeParameterBuilder[] CopyGenericArguments( MethodInfo methodToCopyGenericsFrom, ApplyGenArgs genericParameterGenerator) { var originalGenericArguments = methodToCopyGenericsFrom.GetGenericArguments(); if (originalGenericArguments.Length == 0) { return(null); } var argumentNames = GetArgumentNames(originalGenericArguments); var newGenericParameters = genericParameterGenerator(argumentNames); for (var i = 0; i < newGenericParameters.Length; i++) { try { var attributes = originalGenericArguments[i].GenericParameterAttributes; newGenericParameters[i].SetGenericParameterAttributes(attributes); var constraints = AdjustGenericConstraints(methodToCopyGenericsFrom, newGenericParameters, originalGenericArguments, originalGenericArguments[i].GetGenericParameterConstraints()); newGenericParameters[i].SetInterfaceConstraints(constraints); CopyNonInheritableAttributes(newGenericParameters[i], originalGenericArguments[i]); } catch (NotSupportedException) { // Doesn't matter newGenericParameters[i].SetGenericParameterAttributes(GenericParameterAttributes.None); } } return(newGenericParameters); }
private static GenericTypeParameterBuilder[] CopyGenericArguments( MethodInfo methodToCopyGenericsFrom, Dictionary <String, GenericTypeParameterBuilder> name2GenericType, ApplyGenArgs genericParameterGenerator) { var originalGenericArguments = methodToCopyGenericsFrom.GetGenericArguments(); if (originalGenericArguments.Length == 0) { return(null); } var argumentNames = GetArgumentNames(originalGenericArguments); var newGenericParameters = genericParameterGenerator(argumentNames); for (var i = 0; i < newGenericParameters.Length; i++) { try { var attributes = originalGenericArguments[i].GenericParameterAttributes; newGenericParameters[i].SetGenericParameterAttributes(attributes); var types = AdjustGenericConstraints(methodToCopyGenericsFrom, newGenericParameters, originalGenericArguments, originalGenericArguments[i].GetGenericParameterConstraints()); var interfacesConstraints = types.FindAll(type => type.IsInterface); var baseClassConstraint = types.Find(type => type.IsClass); if (interfacesConstraints.Length != 0) { newGenericParameters[i].SetInterfaceConstraints(interfacesConstraints); } if (baseClassConstraint != null) { newGenericParameters[i].SetBaseTypeConstraint(baseClassConstraint); } CopyNonInheritableAttributes(newGenericParameters[i], originalGenericArguments[i]); } catch (NotSupportedException) { // Doesnt matter newGenericParameters[i].SetGenericParameterAttributes(GenericParameterAttributes.None); } name2GenericType[argumentNames[i]] = newGenericParameters[i]; } return(newGenericParameters); }
private static GenericTypeParameterBuilder[] CopyGenericArguments( MethodInfo methodToCopyGenericsFrom, Dictionary<String, GenericTypeParameterBuilder> name2GenericType, ApplyGenArgs genericParameterGenerator) { var originalGenericArguments = methodToCopyGenericsFrom.GetGenericArguments(); if (originalGenericArguments.Length == 0) { return null; } var argumentNames = GetArgumentNames(originalGenericArguments); var newGenericParameters = genericParameterGenerator(argumentNames); for (var i = 0; i < newGenericParameters.Length; i++) { try { var attributes = originalGenericArguments[i].GetTypeInfo().GenericParameterAttributes; newGenericParameters[i].SetGenericParameterAttributes(attributes); var constraints = AdjustGenericConstraints(methodToCopyGenericsFrom, newGenericParameters, originalGenericArguments, originalGenericArguments[i].GetTypeInfo().GetGenericParameterConstraints()); newGenericParameters[i].SetInterfaceConstraints(constraints); CopyNonInheritableAttributes(newGenericParameters[i], originalGenericArguments[i]); } catch (NotSupportedException) { // Doesnt matter newGenericParameters[i].SetGenericParameterAttributes(GenericParameterAttributes.None); } name2GenericType[argumentNames[i]] = newGenericParameters[i]; } return newGenericParameters; }
private static GenericTypeParameterBuilder[] CopyGenericArguments( MethodInfo methodToCopyGenericsFrom, Dictionary <String, GenericTypeParameterBuilder> name2GenericType, ApplyGenArgs genericParameterGenerator) { Type[] originalGenericArguments = methodToCopyGenericsFrom.GetGenericArguments(); string[] argumentNames = GetArgumentNames(originalGenericArguments); if (argumentNames.Length != 0) { GenericTypeParameterBuilder[] newGenericParameters = genericParameterGenerator(argumentNames); for (int i = 0; i < newGenericParameters.Length; i++) { try { GenericParameterAttributes attributes = originalGenericArguments[i].GenericParameterAttributes; Type[] types = originalGenericArguments[i].GetGenericParameterConstraints(); newGenericParameters[i].SetGenericParameterAttributes(attributes); #if SILVERLIGHT Type[] interfacesConstraints = Castle.Core.Extensions.SilverlightExtensions.FindAll(types, delegate(Type type) { return(type.IsInterface); }); Type baseClassConstraint = Castle.DynamicProxy.SilverlightExtensions.Extensions.Find(types, delegate(Type type) { return(type.IsClass); }); #else Type[] interfacesConstraints = Array.FindAll(types, delegate(Type type) { return(type.IsInterface); }); Type baseClassConstraint = Array.Find(types, delegate(Type type) { return(type.IsClass); }); #endif if (interfacesConstraints.Length != 0) { for (int j = 0; j < interfacesConstraints.Length; ++j) { interfacesConstraints[j] = AdjustConstraintToNewGenericParameters(interfacesConstraints[j], methodToCopyGenericsFrom, originalGenericArguments, newGenericParameters); } newGenericParameters[i].SetInterfaceConstraints(interfacesConstraints); } if (baseClassConstraint != null) { baseClassConstraint = AdjustConstraintToNewGenericParameters(baseClassConstraint, methodToCopyGenericsFrom, originalGenericArguments, newGenericParameters); newGenericParameters[i].SetBaseTypeConstraint(baseClassConstraint); } } catch (NotSupportedException) { // Doesnt matter newGenericParameters[i].SetGenericParameterAttributes(GenericParameterAttributes.None); } if (name2GenericType.ContainsKey(argumentNames[i])) { name2GenericType.Remove(argumentNames[i]); } name2GenericType.Add(argumentNames[i], newGenericParameters[i]); } return(newGenericParameters); } else { return(null); } }
private static GenericTypeParameterBuilder[] CopyGenericArguments( MethodInfo methodToCopyGenericsFrom, Dictionary<String, GenericTypeParameterBuilder> name2GenericType, ApplyGenArgs genericParameterGenerator) { Type[] originalGenericArguments = methodToCopyGenericsFrom.GetGenericArguments(); string[] argumentNames = GetArgumentNames(originalGenericArguments); if (argumentNames.Length != 0) { GenericTypeParameterBuilder[] newGenericParameters = genericParameterGenerator(argumentNames); for (int i = 0; i < newGenericParameters.Length; i++) { try { GenericParameterAttributes attributes = originalGenericArguments[i].GenericParameterAttributes; Type[] types = originalGenericArguments[i].GetGenericParameterConstraints(); newGenericParameters[i].SetGenericParameterAttributes(attributes); #if SILVERLIGHT Type[] interfacesConstraints = Castle.Core.Extensions.SilverlightExtensions.FindAll(types, delegate(Type type) { return type.IsInterface; }); Type baseClassConstraint = Castle.DynamicProxy.SilverlightExtensions.Extensions.Find(types, delegate(Type type) { return type.IsClass; }); #else Type[] interfacesConstraints = Array.FindAll(types, type => type.IsInterface); Type baseClassConstraint = Array.Find(types, type => type.IsClass); #endif if (interfacesConstraints.Length != 0) { for (int j = 0; j < interfacesConstraints.Length; ++j) { interfacesConstraints[j] = AdjustConstraintToNewGenericParameters(interfacesConstraints[j], methodToCopyGenericsFrom, originalGenericArguments, newGenericParameters); } newGenericParameters[i].SetInterfaceConstraints(interfacesConstraints); } if (baseClassConstraint != null) { baseClassConstraint = AdjustConstraintToNewGenericParameters(baseClassConstraint, methodToCopyGenericsFrom, originalGenericArguments, newGenericParameters); newGenericParameters[i].SetBaseTypeConstraint(baseClassConstraint); } CopyNonInheritableAttributes(newGenericParameters[i], originalGenericArguments[i]); } catch (NotSupportedException) { // Doesnt matter newGenericParameters[i].SetGenericParameterAttributes(GenericParameterAttributes.None); } if (name2GenericType.ContainsKey(argumentNames[i])) { name2GenericType.Remove(argumentNames[i]); } name2GenericType.Add(argumentNames[i], newGenericParameters[i]); } return newGenericParameters; } else { return null; } }
private static GenericTypeParameterBuilder[] DefineGenericArguments( Type[] genericArguments, Dictionary<String, GenericTypeParameterBuilder> name2GenericType, ApplyGenArgs gen) { GenericTypeParameterBuilder[] genericTypeParams = null; String[] argumentNames = new String[genericArguments.Length]; for (int i = 0; i < argumentNames.Length; i++) { argumentNames[i] = genericArguments[i].Name; } if (argumentNames.Length != 0) { genericTypeParams = gen(argumentNames); for (int i = 0; i < genericTypeParams.Length; i++) { try { GenericParameterAttributes attributes = genericArguments[i].GenericParameterAttributes; Type[] types = genericArguments[i].GetGenericParameterConstraints(); genericTypeParams[i].SetGenericParameterAttributes(attributes); #if SILVERLIGHT Type[] interfacesConstraints = Castle.Core.Extensions.SilverlightExtensions.FindAll(types, delegate(Type type) { return type.IsInterface; }); Type baseClassConstraint = Castle.DynamicProxy.SilverlightExtensions.Extensions.Find(types, delegate(Type type) { return type.IsClass; }); #else Type[] interfacesConstraints = Array.FindAll(types, delegate(Type type) { return type.IsInterface; }); Type baseClassConstraint = Array.Find(types, delegate(Type type) { return type.IsClass; }); #endif if (interfacesConstraints.Length != 0) { for (int j = 0; j < interfacesConstraints.Length; ++j) { interfacesConstraints[j] = SubstituteGenericArguments(interfacesConstraints[j], genericArguments, genericTypeParams); } genericTypeParams[i].SetInterfaceConstraints(interfacesConstraints); } if (baseClassConstraint != null) { baseClassConstraint = SubstituteGenericArguments(baseClassConstraint, genericArguments, genericTypeParams); genericTypeParams[i].SetBaseTypeConstraint(baseClassConstraint); } } catch (NotSupportedException) { // Doesnt matter genericTypeParams[i].SetGenericParameterAttributes(GenericParameterAttributes.None); } if (name2GenericType.ContainsKey(argumentNames[i])) { name2GenericType.Remove(argumentNames[i]); } name2GenericType.Add(argumentNames[i], genericTypeParams[i]); } } return genericTypeParams; }
private static GenericTypeParameterBuilder[] CopyGenericArguments( MethodInfo methodToCopyGenericsFrom, Dictionary<String, GenericTypeParameterBuilder> name2GenericType, ApplyGenArgs genericParameterGenerator) { var originalGenericArguments = methodToCopyGenericsFrom.GetGenericArguments(); if (originalGenericArguments.Length == 0) { return null; } var argumentNames = GetArgumentNames(originalGenericArguments); var newGenericParameters = genericParameterGenerator(argumentNames); for (var i = 0; i < newGenericParameters.Length; i++) { try { var attributes = originalGenericArguments[i].GenericParameterAttributes; newGenericParameters[i].SetGenericParameterAttributes(attributes); var types = AdjustGenericConstraints(methodToCopyGenericsFrom, newGenericParameters, originalGenericArguments, originalGenericArguments[i].GetGenericParameterConstraints()); #if SILVERLIGHT Type[] interfacesConstraints = Castle.Core.Extensions.SilverlightExtensions.FindAll(types, delegate(Type type) { return type.IsInterface; }); Type baseClassConstraint = Castle.DynamicProxy.SilverlightExtensions.Extensions.Find(types, delegate(Type type) { return type.IsClass; }); #else var interfacesConstraints = Array.FindAll(types, type => type.IsInterface); var baseClassConstraint = Array.Find(types, type => type.IsClass); #endif if (interfacesConstraints.Length != 0) { newGenericParameters[i].SetInterfaceConstraints(interfacesConstraints); } if (baseClassConstraint != null) { newGenericParameters[i].SetBaseTypeConstraint(baseClassConstraint); } CopyNonInheritableAttributes(newGenericParameters[i], originalGenericArguments[i]); } catch (NotSupportedException) { // Doesnt matter newGenericParameters[i].SetGenericParameterAttributes(GenericParameterAttributes.None); } name2GenericType[argumentNames[i]] = newGenericParameters[i]; } return newGenericParameters; }