<commit_before>// Copyright 2004-2006 Castle Project - http://www.castleproject.org/
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Castle.MonoRail.ActiveRecordSupport
{
	using System;
	using System.Reflection;

	using Castle.MonoRail.Framework;

	/// <summary>
	/// Mark a parameter with this attribute to instruct the <see cref="SmartDispatcherController" />
	/// to load an <c>ActiveRecord</c> instance of the parameter type, using the request parameter
	/// as the identifier.
	/// </summary>
	/// <remarks>
	/// The <see cref="ARFetchAttribute"/> only loads an instance
	/// based on the primary key value obtained from <see cref="IRailsEngineContext.Params"/>
	/// <para>For example:</para>
	/// <code>
	/// public class CustomerController : ARSmartDispatcherController
	/// {
	///     public void UpdateCustomerLocation([ARFetch("customer.id")] Customer customer, [ARFetch("location.id")] Location location)
	///     {
	///       customer.Location = location;
	///       customer.Save();
	///       
	///       RedirectToAction("index");
	///     }
	/// }
	/// </code>
	/// The code above assumes that you have the fields 
	/// <c>customer.id</c> and <c>location.id</c> on the form being
	/// submitted. 
	/// </remarks>
	[AttributeUsage(AttributeTargets.Parameter), Serializable]
	public class ARFetchAttribute : Attribute, IParameterBinder
	{
		private String requestParameterName;
		private bool create, required;
		
		/// <summary>
		/// Constructs an <see cref="ARFetchAttribute"/> 
		/// specifying the parameter name and the create and require behavior
		/// </summary>
		/// <param name="requestParameterName">The parameter name to be read from the request</param>
		/// <param name="create"><c>true</c> if you want an instance even when the record is not found</param>
		/// <param name="required"><c>true</c> if you want an exception if the record is not found</param>
		public ARFetchAttribute(String requestParameterName, bool create, bool required) : base()
		{
			this.requestParameterName = requestParameterName;
			this.create = create;
			this.required = required;
		}

		/// <summary>
		/// Constructs an <see cref="ARFetchAttribute"/> using the
		/// parameter name as the <see cref="ARFetchAttribute.RequestParameterName"/>
		/// </summary>
		public ARFetchAttribute() : this(null, false, false)
		{
		}
		
		/// <summary>
		/// Constructs an <see cref="ARFetchAttribute"/> specifing the
		/// parameter name
		/// <seealso cref="ARFetchAttribute.RequestParameterName"/>
		/// </summary>
		public ARFetchAttribute(String requestParameterName) : this(requestParameterName, false, false)
		{
		}
		
		/// <summary>
		/// Constructs an <see cref="ARFetchAttribute"/> using the
		/// parameter name as the <see cref="ARFetchAttribute.RequestParameterName"/>
		/// and the create and require behavior
		/// </summary>
		/// <param name="create"><c>true</c> if you want an instance even when the record is not found</param>
		/// <param name="require"><c>true</c> if you want an exception if the record is not found</param>
		public ARFetchAttribute(bool create, bool require) : this(null, create, require)
		{
		}
		
		/// <summary>
		/// The parameter name to be read from the request. The parameter value will 
		/// be used as the primary key value to load the target object instance.
		/// </summary>
		public String RequestParameterName
		{
			get { return requestParameterName; }
			set { requestParameterName = value; }
		}

		/// <summary>
		/// When set to <c>true</c> an instance of
		/// the target type will be created if the record 
		/// is not found. The default is <c>false</c>.
		/// </summary>
		public bool Create
		{
			get { return create; }
			set { create = value; }
		}
		
		/// <summary>
		/// When set to <c>true</c>, an exception will be thrown
		/// if the record specified is not found. The default is <c>false</c>.
		/// </summary>
		public bool Required
		{
			get { return required; }
			set { required = value; }
		}

		protected virtual int CalculateParamPoints(SmartDispatcherController controller, ParameterInfo parameterInfo)
		{
			String paramName = RequestParameterName != null ? RequestParameterName : parameterInfo.Name;

			return controller.Request.Params.Get(paramName) != null ? 10 : 0;
		}

		protected virtual object Bind(SmartDispatcherController controller, ParameterInfo parameterInfo)<commit_msg>Interface implementations should be public. :|<commit_after>// Copyright 2004-2006 Castle Project - http://www.castleproject.org/
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Castle.MonoRail.ActiveRecordSupport
{
	using System;
	using System.Reflection;

	using Castle.MonoRail.Framework;

	/// <summary>
	/// Mark a parameter with this attribute to instruct the <see cref="SmartDispatcherController" />
	/// to load an <c>ActiveRecord</c> instance of the parameter type, using the request parameter
	/// as the identifier.
	/// </summary>
	/// <remarks>
	/// The <see cref="ARFetchAttribute"/> only loads an instance
	/// based on the primary key value obtained from <see cref="IRailsEngineContext.Params"/>
	/// <para>For example:</para>
	/// <code>
	/// public class CustomerController : ARSmartDispatcherController
	/// {
	///     public void UpdateCustomerLocation([ARFetch("customer.id")] Customer customer, [ARFetch("location.id")] Location location)
	///     {
	///       customer.Location = location;
	///       customer.Save();
	///       
	///       RedirectToAction("index");
	///     }
	/// }
	/// </code>
	/// The code above assumes that you have the fields 
	/// <c>customer.id</c> and <c>location.id</c> on the form being
	/// submitted. 
	/// </remarks>
	[AttributeUsage(AttributeTargets.Parameter), Serializable]
	public class ARFetchAttribute : Attribute, IParameterBinder
	{
		private String requestParameterName;
		private bool create, required;
		
		/// <summary>
		/// Constructs an <see cref="ARFetchAttribute"/> 
		/// specifying the parameter name and the create and require behavior
		/// </summary>
		/// <param name="requestParameterName">The parameter name to be read from the request</param>
		/// <param name="create"><c>true</c> if you want an instance even when the record is not found</param>
		/// <param name="required"><c>true</c> if you want an exception if the record is not found</param>
		public ARFetchAttribute(String requestParameterName, bool create, bool required) : base()
		{
			this.requestParameterName = requestParameterName;
			this.create = create;
			this.required = required;
		}

		/// <summary>
		/// Constructs an <see cref="ARFetchAttribute"/> using the
		/// parameter name as the <see cref="ARFetchAttribute.RequestParameterName"/>
		/// </summary>
		public ARFetchAttribute() : this(null, false, false)
		{
		}
		
		/// <summary>
		/// Constructs an <see cref="ARFetchAttribute"/> specifing the
		/// parameter name
		/// <seealso cref="ARFetchAttribute.RequestParameterName"/>
		/// </summary>
		public ARFetchAttribute(String requestParameterName) : this(requestParameterName, false, false)
		{
		}
		
		/// <summary>
		/// Constructs an <see cref="ARFetchAttribute"/> using the
		/// parameter name as the <see cref="ARFetchAttribute.RequestParameterName"/>
		/// and the create and require behavior
		/// </summary>
		/// <param name="create"><c>true</c> if you want an instance even when the record is not found</param>
		/// <param name="require"><c>true</c> if you want an exception if the record is not found</param>
		public ARFetchAttribute(bool create, bool require) : this(null, create, require)
		{
		}
		
		/// <summary>
		/// The parameter name to be read from the request. The parameter value will 
		/// be used as the primary key value to load the target object instance.
		/// </summary>
		public String RequestParameterName
		{
			get { return requestParameterName; }
			set { requestParameterName = value; }
		}

		/// <summary>
		/// When set to <c>true</c> an instance of
		/// the target type will be created if the record 
		/// is not found. The default is <c>false</c>.
		/// </summary>
		public bool Create
		{
			get { return create; }
			set { create = value; }
		}
		
		/// <summary>
		/// When set to <c>true</c>, an exception will be thrown
		/// if the record specified is not found. The default is <c>false</c>.
		/// </summary>
		public bool Required
		{
			get { return required; }
			set { required = value; }
		}

		public virtual int CalculateParamPoints(SmartDispatcherController controller, ParameterInfo parameterInfo)
		{
			String paramName = RequestParameterName != null ? RequestParameterName : parameterInfo.Name;

			return controller.Request.Params.Get(paramName) != null ? 10 : 0;
		}

		public virtual object Bind(SmartDispatcherController controller, ParameterInfo parameterInfo)
{'fraction_non_alphanumeric': 0.12743200570439034, 'fraction_numerical': 0.003055923398186819, 'mean_word_length': 3.2083154736390913, 'pattern_counts': {'":': 0, '<': 131, '<?xml version=': 0, '>': 131, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '828043', 'n_tokens_mistral': 2909, 'n_tokens_neox': 2639, 'n_words': 958}