|
//---------------------------------------------------------------------
//
// Copyright (C) 2005 Hongju Cao <hjcao_wei@hotmail.com>
//
// Permission to copy, use, modify, sell and distribute this software is
// granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied warranty,
// and with no claim as to its suitability for any purpose.
//
//---------------------------------------------------------------------
using System;
using System.Collections;
namespace First.Commons.Property
{
/// <summary>
/// ListProxy ��ժҪ˵����
/// </summary>
internal sealed class ListProxy : IDynaAccessProxy
{
private string[] _propertyNames = new string[0];
public ListProxy()
{
//
// TODO: �ڴ˴���ӹ��캯����
//
}
#region IDynaAccessProxy methods
public string[] GetPropertyNames(object target)
{
if (target is IList)
{
string [] propertyNames = new string[((IList) target).Count];
for(int i = 0;i< ((IList) target).Count ; i++)
propertyNames[i] = System.Convert.ToString(i);
return propertyNames;
}
else
{
return _propertyNames;
}
}
public void SetProperty(object target , string propertyName , object propertyValue)
{
try
{
int i = System.Convert.ToInt32(propertyName);
if (target is IList)
{
((IList) target)[i] = propertyValue;
}
else
{
throw new DynaAccessException(target.GetType().Name + " class is not a List or Array.");
}
}
catch(Exception e)
{
throw new DynaAccessException(e);
}
}
public object GetProperty(object target , string propertyName)
{
object value = null;
try
{
int i = System.Convert.ToInt32(propertyName);
if (target is IList)
{
value = ((IList) target)[i];
}
else
{
throw new DynaAccessException(target.GetType().Name + " class is not a List or Array.");
}
}
catch(Exception e)
{
throw new DynaAccessException(e);
}
return value;
}
public bool HasProperty(object target , string propertyName)
{
try
{
int i = System.Convert.ToInt32(propertyName);
if (target is IList)
{
return i>-1 && i < ((IList) target).Count;
}
return false;
}
catch(Exception)
{
return false;
}
}
public Type GetPropertyType(object target , string propertyName)
{
object value = null;
try
{
int i = System.Convert.ToInt32(propertyName);
if (target is IList)
{
value = ((IList) target)[i];
if(value == null)
{
value = new object();
}
return value.GetType();
}
else
{
throw new DynaAccessException(target.GetType().Name + " class is not a List or Array.");
}
}
catch(Exception e)
{
throw new DynaAccessException(e);
}
}
public Type ProxyType
{
get
{
return typeof(System.Collections.IList);
}
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
developer located in Tianjin, China.interests include C++/.NET/Java, etc. like coding.