PDA

View Full Version : حرفه ای: سوالاتی راجع به سورس و معماری موجود در پروژه آموزشی "اعمال متداول با گرید"نوشته بهروز راد عزیز



amirjalili
سه شنبه 13 مهر 1389, 20:12 عصر
با سلام و عرض خسته نباشید.
پس از مطالعه سورس های پروژه اعمال متداول با گریدویو سوالاتی برام پیش اومد که بدین شرحه.
حالا هر کی هر کدومش رو بلده اگه جواب بده ممنون میشم


1: کار کلاس های موجود در فولدر Configuration و اینکه لزوم وجود این کلاس ها چیه رو نفهمیدم و اینکه آیا وجود این کلاس ها از معماری خاصی تبعیت میکنه و یا دلیل وجودش تبعیت از یکی از الگو های برنامه نویسی هست؟
کلا دلیل استفاده از Custom Configuration رو نمیدونم چیه؟ نبودش چه مشکلی ایجاد میکنه و یا وجودش چه حسنی داره؟


2: کار کلاس هایی که با نام helper هست چیه؟ در دنیای برنامه نویسی روی چه کلاس هایی اسم helper میذارن؟ مثل sitehelper ,...

3: سوالی هم بود راجع به این نوع استفاده از base که فهمیدم از ایندکسر ها استفاده کرده و خودم سعی میکنم کامل که فهمیدم اینجا توضیحش بدم.

public string ConnectionStringName
{
get { return (string)base["connectionStringName"]; }
set { base["connectionStringName"] = value; }
}با تشکر زیاد زیاد .

raziee
سه شنبه 13 مهر 1389, 20:28 عصر
1: کار کلاس های موجود در فولدر Configuration و اینکه لزوم وجود این کلاس ها چیه رو نفهمیدم و اینکه آیا وجود این کلاس ها از معماری خاصی تبعیت میکنه و یا دلیل وجودش تبعیت از یکی از الگو های برنامه نویسی هست؟
کلا دلیل استفاده از Custom Configuration رو نمیدونم چیه؟ نبودش چه مشکلی ایجاد میکنه و یا وجودش چه حسنی داره؟برای دسترسی به فایل وب کانفیگ است.
مزایا و معایبش هم عدم وابستگی تنظیمات به کلاس ها است.
مثلا برای اینکه PageSize رو از 10 به 30 تغییر بدید نیاز نباشه برید سورستون رو ویرایش و دوباره کامپایل کنید.
یا مثلا اگه امروز با SqlServer کار میکنید فردا خواستید برید با Oracle کار کنید یه Provider مربوط به Oracle مینویسید و بعد از کامپایل به پروژه اضافه میکنید و تنها این provider رو در وب کانفیگ تعریف میکینید.



2: کار کلاس هایی که با نام helper هست چیه؟ در دنیای برنامه نویسی روی چه کلاس هایی اسم helper میذارن؟ مثل sitehelper ,...
در این کلاس متد هایی نوشته شده که در کل سایت استفاده میشود مثلا:
public static string GridViewRowsIndexing(int pageIndex, int pageSize, int rowIndex)
{
Func<int, int, int, string> pageNumberIndexer = (pi, ps, ri) => ((pi * ps) + 1 + ri).ToString(CultureInfo.CurrentCulture);
return pageNumberIndexer(pageIndex, pageSize, rowIndex);
}
این متد برای ساخت ایندکس هست. شما میتونید در پروژه های دیگه هم استفاده کنید.

3: سوالی هم بود راجع به این نوع استفاده از base که فهمیدم از ایندکسر ها استفاده کرده و خودم سعی میکنم کامل که فهمیدم اینجا توضیحش بدم.

کلمه ی کلیدی base در C# به کلاس پایه (کلاسی که ازش ارث برده شده) اشاره میکنه.

Behrouz_Rad
سه شنبه 13 مهر 1389, 22:10 عصر
آقای raziee به خوبی توضیح دادند. فقط بنده کمی در مورد پاسخ سوال اولتون بیشتر توضیح میدم:


دلیل استفاده از Custom Configuration رو نمیدونم چیه؟ نبودش چه مشکلی ایجاد میکنه و یا وجودش چه حسنی داره؟

کامپوننت های Third Party تنظیمات خودشون رو در فایل web.config ذخیره می کنن. Custom Section ها اجازه میدن تا از تداخل Key تنظیمات جلوگیری بشه. اگر قرار بود همه از App Settings استفاده کنند، احتمال تداخل عنوان Key ها بسیار زیاد بود.

موفق باشید.

amirjalili
چهارشنبه 14 مهر 1389, 08:00 صبح
با تشکر از پاسخ های خوبتون.


کلمه ی کلیدی base در C#‎‎ به کلاس پایه (کلاسی که ازش ارث برده شده) اشاره میکنه.

در مورد base البته که میدونم که به کلاس پدر و فیلد ها ,متد ها و سازنده های اون اشاره میکنه. سوال من در مورد نحوه استفاده از base در ایندکسر ها بود و نوع استفاده ای که ازش در این سورس شده و اینکه حالا چرا از ایندکسر استفاده شده؟
پس از اینکه به نتیجه رسیدم حتما برای دوستان هم توضیح خواهم داد.

raziee
چهارشنبه 14 مهر 1389, 14:18 عصر
سوال من در مورد نحوه استفاده از base در ایندکسر ها بود و نوع استفاده ای که ازش در این سورس شده و اینکه حالا چرا از ایندکسر استفاده شده؟
به خاطر کلاس پایه هست.
ببین این کمکی بهت میکنه:
//
// Summary:
// Gets or sets a property, attribute, or child element of this configuration
// element.
//
// Parameters:
// propertyName:
// The name of the System.Configuration.ConfigurationProperty to access.
//
// Returns:
// The specified property, attribute, or child element
//
// Exceptions:
// System.Configuration.ConfigurationErrorsException:
// prop is read-only or locked.
protected internal object this[string propertyName] { get; set; }

#region Assembly System.Configuration.dll, v2.0.50727
// C:\Windows\Microsoft.NET\Framework\v2.0.50727\Syst em.Configuration.dll
#endregion

using System;
using System.Collections;
using System.Reflection;
using System.Xml;

namespace System.Configuration
{
// Summary:
// Represents a configuration element within a configuration file.
public abstract class ConfigurationElement
{
// Summary:
// Initializes a new instance of the System.Configuration.ConfigurationElement
// class.
protected ConfigurationElement();

// Summary:
// Gets an System.Configuration.ElementInformation object that contains the
// non-customizable information and functionality of the System.Configuration.ConfigurationElement
// object.
//
// Returns:
// An System.Configuration.ElementInformation that contains the non-customizable
// information and functionality of the System.Configuration.ConfigurationElement.
public ElementInformation ElementInformation { get; }
//
// Summary:
// Gets the System.Configuration.ConfigurationElementProperty object that represents
// the System.Configuration.ConfigurationElement object itself.
//
// Returns:
// The System.Configuration.ConfigurationElementProperty that represents the
// System.Configuration.ConfigurationElement itself.
protected internal virtual ConfigurationElementProperty ElementProperty { get; }
//
// Summary:
// Gets the System.Configuration.ContextInformation object for the System.Configuration.ConfigurationElement
// object.
//
// Returns:
// The System.Configuration.ContextInformation for the System.Configuration.ConfigurationElement.
//
// Exceptions:
// System.Configuration.ConfigurationErrorsException:
// The current element is not associated with a context.
protected ContextInformation EvaluationContext { get; }
//
// Summary:
// Gets the collection of locked attributes.
//
// Returns:
// The System.Configuration.ConfigurationLockCollection of locked attributes
// (properties) for the element.
public ConfigurationLockCollection LockAllAttributesExcept { get; }
//
// Summary:
// Gets the collection of locked elements.
//
// Returns:
// The System.Configuration.ConfigurationLockCollection of locked elements.
public ConfigurationLockCollection LockAllElementsExcept { get; }
//
// Summary:
// Gets the collection of locked attributes
//
// Returns:
// The System.Configuration.ConfigurationLockCollection of locked attributes
// (properties) for the element.
public ConfigurationLockCollection LockAttributes { get; }
//
// Summary:
// Gets the collection of locked elements.
//
// Returns:
// The System.Configuration.ConfigurationLockCollection of locked elements.
public ConfigurationLockCollection LockElements { get; }
//
// Summary:
// Gets or sets a value indicating whether the element is locked.
//
// Returns:
// true if the element is locked; otherwise, false. The default is false.
//
// Exceptions:
// System.Configuration.ConfigurationErrorsException:
// The element has already been locked at a higher configuration level.
public bool LockItem { get; set; }
//
// Summary:
// Gets the collection of properties.
//
// Returns:
// The System.Configuration.ConfigurationPropertyCollecti on of properties for
// the element.
protected internal virtual ConfigurationPropertyCollection Properties { get; }

// Summary:
// Gets or sets a property or attribute of this configuration element.
//
// Parameters:
// prop:
// The property to access.
//
// Returns:
// The specified property, attribute, or child element.
//
// Exceptions:
// System.Configuration.ConfigurationException:
// prop is null or does not exist within the element.
//
// System.Configuration.ConfigurationErrorsException:
// prop is read only or locked.
protected internal object this[ConfigurationProperty prop] { get; set; }
//
// Summary:
// Gets or sets a property, attribute, or child element of this configuration
// element.
//
// Parameters:
// propertyName:
// The name of the System.Configuration.ConfigurationProperty to access.
//
// Returns:
// The specified property, attribute, or child element
//
// Exceptions:
// System.Configuration.ConfigurationErrorsException:
// prop is read-only or locked.
protected internal object this[string propertyName] { get; set; }

// Summary:
// Reads XML from the configuration file.
//
// Parameters:
// reader:
// The System.Xml.XmlReader that reads from the configuration file.
//
// serializeCollectionKey:
// true to serialize only the collection key properties; otherwise, false.
//
// Exceptions:
// System.Configuration.ConfigurationErrorsException:
// The element to read is locked. - or - An attribute of the current node is
// not recognized. - or - The lock status of the current node cannot be determined.
protected internal virtual void DeserializeElement(XmlReader reader, bool serializeCollectionKey);
//
// Summary:
// Compares the current System.Configuration.ConfigurationElement instance to
// the specified object.
//
// Parameters:
// compareTo:
// The object to compare with.
//
// Returns:
// true if the object to compare with is equal to the current System.Configuration.ConfigurationElement
// instance; otherwise, false. The default is false.
public override bool Equals(object compareTo);
//
// Summary:
// Gets a unique value representing the current System.Configuration.ConfigurationElement
// instance.
//
// Returns:
// A unique value representing the current System.Configuration.ConfigurationElement
// instance.
public override int GetHashCode();
//
// Summary:
// Sets the System.Configuration.ConfigurationElement object to its initial
// state.
protected internal virtual void Init();
//
// Summary:
// Used to initialize a default set of values for the System.Configuration.ConfigurationElement
// object.
protected internal virtual void InitializeDefault();
//
// Summary:
// Indicates whether this configuration element has been modified since it was
// last saved or loaded, when implemented in a derived class.
//
// Returns:
// true if the element has been modified; otherwise, false.
protected internal virtual bool IsModified();
//
// Summary:
// Gets a value indicating whether the System.Configuration.ConfigurationElement
// object is read-only.
//
// Returns:
// true if the System.Configuration.ConfigurationElement object is read-only;
// otherwise, false.
public virtual bool IsReadOnly();
//
// Summary:
// Adds the invalid-property errors in this System.Configuration.ConfigurationElement
// object, and in all subelements, to the passed list.
//
// Parameters:
// errorList:
// An object that implements the System.Collections.IList interface.
protected virtual void ListErrors(IList errorList);
//
// Summary:
// Gets a value indicating whether an unknown attribute is encountered during
// deserialization.
//
// Parameters:
// name:
// The name of the unrecognized attribute.
//
// value:
// The value of the unrecognized attribute.
//
// Returns:
// true when an unknown attribute is encountered while deserializing; otherwise,
// false.
protected virtual bool OnDeserializeUnrecognizedAttribute(string name, string value);
//
// Summary:
// Gets a value indicating whether an unknown element is encountered during
// deserialization.
//
// Parameters:
// elementName:
// The name of the unknown subelement.
//
// reader:
// The System.Xml.XmlReader being used for deserialization.
//
// Returns:
// true when an unknown element is encountered while deserializing; otherwise,
// false.
//
// Exceptions:
// System.Configuration.ConfigurationErrorsException:
// The element identified by elementName is locked. - or - One or more of the
// element's attributes is locked. - or - elementName is unrecognized, or the
// element has an unrecognized attribute. - or - The element has a Boolean
// attribute with an invalid value. - or - An attempt was made to deserialize
// a property more than once. - or - An attempt was made to deserialize a property
// that is not a valid member of the element. - or - The element cannot contain
// a CDATA or text element.
protected virtual bool OnDeserializeUnrecognizedElement(string elementName, XmlReader reader);
//
// Summary:
// Throws an exception when a required property is not found.
//
// Parameters:
// name:
// The name of the required attribute that was not found.
//
// Returns:
// None.
//
// Exceptions:
// System.Configuration.ConfigurationErrorsException:
// In all cases.
protected virtual object OnRequiredPropertyNotFound(string name);
//
// Summary:
// Called after deserialization.
protected virtual void PostDeserialize();
//
// Summary:
// Called before serialization.
//
// Parameters:
// writer:
// The System.Xml.XmlWriter that will be used to serialize the System.Configuration.ConfigurationElement.
protected virtual void PreSerialize(XmlWriter writer);
//
// Summary:
// Resets the internal state of the System.Configuration.ConfigurationElement
// object, including the locks and the properties collections.
//
// Parameters:
// parentElement:
// The parent node of the configuration element.
protected internal virtual void Reset(ConfigurationElement parentElement);
//
// Summary:
// Resets the value of the System.Configuration.ConfigurationElement.IsModifi ed()
// method to false when implemented in a derived class.
protected internal virtual void ResetModified();
//
// Summary:
// Writes the contents of this configuration element to the configuration file
// when implemented in a derived class.
//
// Parameters:
// writer:
// The System.Xml.XmlWriter that writes to the configuration file.
//
// serializeCollectionKey:
// true to serialize only the collection key properties; otherwise, false.
//
// Returns:
// true if any data was actually serialized; otherwise, false.
//
// Exceptions:
// System.Configuration.ConfigurationErrorsException:
// The current attribute is locked at a higher configuration level.
protected internal virtual bool SerializeElement(XmlWriter writer, bool serializeCollectionKey);
//
// Summary:
// Writes the outer tags of this configuration element to the configuration
// file when implemented in a derived class.
//
// Parameters:
// writer:
// The System.Xml.XmlWriter that writes to the configuration file.
//
// elementName:
// The name of the System.Configuration.ConfigurationElement to be written.
//
// Returns:
// true if writing was successful; otherwise, false.
//
// Exceptions:
// System.Exception:
// The element has multiple child elements.
protected internal virtual bool SerializeToXmlElement(XmlWriter writer, string elementName);
//
// Summary:
// Sets a property to the specified value.
//
// Parameters:
// prop:
// The element property to set.
//
// value:
// The value to assign to the property.
//
// ignoreLocks:
// true if the locks on the property should be ignored; otherwise, false.
//
// Exceptions:
// System.Configuration.ConfigurationErrorsException:
// Occurs if the element is read-only or ignoreLocks is true but the locks cannot
// be ignored.
protected void SetPropertyValue(ConfigurationProperty prop, object value, bool ignoreLocks);
//
// Summary:
// Sets the System.Configuration.ConfigurationElement.IsReadOn ly() property
// for the System.Configuration.ConfigurationElement object and all subelements.
protected internal virtual void SetReadOnly();
//
// Summary:
// Modifies the System.Configuration.ConfigurationElement object to remove all
// values that should not be saved.
//
// Parameters:
// sourceElement:
// A System.Configuration.ConfigurationElement at the current level containing
// a merged view of the properties.
//
// parentElement:
// The parent System.Configuration.ConfigurationElement, or null if this is
// the top level.
//
// saveMode:
// A System.Configuration.ConfigurationSaveMode that determines which property
// values to include.
protected internal virtual void Unmerge(ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode);
}
}