/// <summary> /// Creates a <see cref="MethodNameBasedNodeTypeRegistry"/> and automatically registers all types implementing <see cref="IExpressionNode"/> /// from a given type sequence that offer a public static <c>SupportedMethodNames</c> field. /// </summary> /// <returns>A <see cref="MethodInfoBasedNodeTypeRegistry"/> with all <see cref="IExpressionNode"/> types with a <c>SupportedMethodNames</c> /// field registered.</returns> public static MethodNameBasedNodeTypeRegistry CreateFromTypes (IEnumerable<Type> searchedTypes) { ArgumentUtility.CheckNotNull ("searchedTypes", searchedTypes); var expressionNodeTypes = from t in searchedTypes where typeof (IExpressionNode).GetTypeInfo().IsAssignableFrom (t.GetTypeInfo()) select t; var infoForTypes = from t in expressionNodeTypes let supportedMethodNamesField = t.GetRuntimeField ("SupportedMethodNames") select new { Type = t, RegistrationInfo = supportedMethodNamesField != null && supportedMethodNamesField.IsStatic ? ((IEnumerable<NameBasedRegistrationInfo>) supportedMethodNamesField.GetValue (null)) : Enumerable.Empty<NameBasedRegistrationInfo>() }; var registry = new MethodNameBasedNodeTypeRegistry(); foreach (var infoForType in infoForTypes) registry.Register (infoForType.RegistrationInfo, infoForType.Type); return registry; }
/// <summary> /// Creates a <see cref="MethodNameBasedNodeTypeRegistry"/> and automatically registers all types implementing <see cref="IExpressionNode"/> /// from a given type sequence that offer a public static <c>SupportedMethodNames</c> field. /// </summary> /// <returns>A <see cref="MethodInfoBasedNodeTypeRegistry"/> with all <see cref="IExpressionNode"/> types with a <c>SupportedMethodNames</c> /// field registered.</returns> public static MethodNameBasedNodeTypeRegistry CreateFromTypes(IEnumerable <Type> searchedTypes) { ArgumentUtility.CheckNotNull("searchedTypes", searchedTypes); var expressionNodeTypes = from t in searchedTypes where typeof(IExpressionNode).GetTypeInfo().IsAssignableFrom(t.GetTypeInfo()) select t; var infoForTypes = from t in expressionNodeTypes let supportedMethodNamesField = t.GetRuntimeField("SupportedMethodNames") select new { Type = t, RegistrationInfo = supportedMethodNamesField != null && supportedMethodNamesField.IsStatic ? ((IEnumerable <NameBasedRegistrationInfo>)supportedMethodNamesField.GetValue(null)) : Enumerable.Empty <NameBasedRegistrationInfo>() }; var registry = new MethodNameBasedNodeTypeRegistry(); foreach (var infoForType in infoForTypes) { registry.Register(infoForType.RegistrationInfo, infoForType.Type); } return(registry); }