コード例 #1
0
        internal static object GetPropertyValue(ADEntity targetEntity, string propertyName)
        {
            PropertyInfo dotNetProperty = targetEntity.GetDotNetProperty(propertyName);

            if (dotNetProperty == null)
            {
                if (targetEntity.PropertyIsReadable(propertyName))
                {
                    ADPropertyValueCollection item = targetEntity[propertyName];
                    if (targetEntity.PropertyIsSingleValue(propertyName))
                    {
                        if (item == null || item.Count == 0)
                        {
                            return(null);
                        }
                        else
                        {
                            return(item[0]);
                        }
                    }
                    else
                    {
                        return(item);
                    }
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(dotNetProperty.GetValue(targetEntity, null));
            }
        }
コード例 #2
0
 public override string GetPropertyTypeName(PSAdaptedProperty property)
 {
     if (property != null)
     {
         ADEntity baseObject = property.BaseObject as ADEntity;
         if (baseObject != null)
         {
             PropertyInfo dotNetProperty = baseObject.GetDotNetProperty(property.Name);
             if (dotNetProperty == null)
             {
                 if (!baseObject.PropertyIsSingleValue(property.Name))
                 {
                     return(ADEntityAdapter.MultiValueTypeName);
                 }
                 else
                 {
                     return(baseObject.GetPropertyType(property.Name).FullName);
                 }
             }
             else
             {
                 return(dotNetProperty.PropertyType.FullName);
             }
         }
         else
         {
             object[] typeAdapterTypeName = new object[2];
             typeAdapterTypeName[0] = ADEntityAdapter.TypeAdapterTypeName;
             typeAdapterTypeName[1] = ADEntityAdapter.ADEntityTypeName;
             throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, StringResources.TypeAdapterForADEntityOnly, typeAdapterTypeName));
         }
     }
     else
     {
         throw new ArgumentNullException("property");
     }
 }
コード例 #3
0
ファイル: ADEntityAdapter.cs プロジェクト: nickchal/pash
		internal static object GetPropertyValue(ADEntity targetEntity, string propertyName)
		{
			PropertyInfo dotNetProperty = targetEntity.GetDotNetProperty(propertyName);
			if (dotNetProperty == null)
			{
				if (targetEntity.PropertyIsReadable(propertyName))
				{
					ADPropertyValueCollection item = targetEntity[propertyName];
					if (targetEntity.PropertyIsSingleValue(propertyName))
					{
						if (item == null || item.Count == 0)
						{
							return null;
						}
						else
						{
							return item[0];
						}
					}
					else
					{
						return item;
					}
				}
				else
				{
					return null;
				}
			}
			else
			{
				return dotNetProperty.GetValue(targetEntity, null);
			}
		}
コード例 #4
0
        public override void SetPropertyValue(PSAdaptedProperty property, object valueObject)
        {
            Type      realType;
            Type      type;
            object    obj       = null;
            Exception exception = null;

            if (property != null)
            {
                ADEntity baseObject = property.BaseObject as ADEntity;
                if (baseObject != null)
                {
                    PSObject pSObject = valueObject as PSObject;
                    if (pSObject != null)
                    {
                        valueObject = pSObject.BaseObject;
                    }
                    PropertyInfo dotNetProperty = baseObject.GetDotNetProperty(property.Name);
                    if (dotNetProperty == null)
                    {
                        if (this.IsSettable(property))
                        {
                            if (valueObject != null)
                            {
                                realType = this.GetRealType(baseObject.GetPropertyType(property.Name));
                                type     = this.GetRealType(valueObject.GetType());
                                if (realType == typeof(object) || realType == type)
                                {
                                    baseObject[property.Name].Value = valueObject;
                                    return;
                                }
                                else
                                {
                                    if (baseObject.PropertyIsSingleValue(property.Name) || valueObject as ICollection == null)
                                    {
                                        baseObject[property.Name].Value = this.ConvertValue(property, valueObject, realType, type);
                                        return;
                                    }
                                    else
                                    {
                                        if (!this.TryConvertValue(property, valueObject, realType, type, out obj, out exception))
                                        {
                                            ICollection collections = valueObject as ICollection;
                                            ADPropertyValueCollection aDPropertyValueCollection = new ADPropertyValueCollection();
                                            foreach (object obj1 in collections)
                                            {
                                                if (obj1 == null)
                                                {
                                                    continue;
                                                }
                                                Type type1 = obj1.GetType();
                                                if (type1 != realType)
                                                {
                                                    aDPropertyValueCollection.Add(this.ConvertValue(property, obj1, realType, type1));
                                                }
                                                else
                                                {
                                                    aDPropertyValueCollection.Add(obj1);
                                                }
                                            }
                                            baseObject[property.Name].Value = aDPropertyValueCollection;
                                            return;
                                        }
                                        else
                                        {
                                            baseObject[property.Name].Value = obj;
                                            return;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                baseObject[property.Name].Value = null;
                                return;
                            }
                        }
                        else
                        {
                            object[] name = new object[1];
                            name[0] = property.Name;
                            throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, StringResources.PropertyIsReadonly, name));
                        }
                    }
                    else
                    {
                        if (dotNetProperty.CanWrite)
                        {
                            if (valueObject != null)
                            {
                                realType = this.GetRealType(dotNetProperty.PropertyType);
                                type     = this.GetRealType(valueObject.GetType());
                                if (realType == typeof(object) || realType == type)
                                {
                                    dotNetProperty.SetValue(baseObject, valueObject, null);
                                    return;
                                }
                                else
                                {
                                    dotNetProperty.SetValue(baseObject, this.ConvertValue(property, valueObject, realType, type), null);
                                    return;
                                }
                            }
                            else
                            {
                                dotNetProperty.SetValue(baseObject, null, null);
                                return;
                            }
                        }
                        else
                        {
                            object[] objArray = new object[1];
                            objArray[0] = property.Name;
                            throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, StringResources.PropertyIsReadonly, objArray));
                        }
                    }
                }
                else
                {
                    object[] typeAdapterTypeName = new object[2];
                    typeAdapterTypeName[0] = ADEntityAdapter.TypeAdapterTypeName;
                    typeAdapterTypeName[1] = ADEntityAdapter.ADEntityTypeName;
                    throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, StringResources.TypeAdapterForADEntityOnly, typeAdapterTypeName));
                }
            }
            else
            {
                throw new ArgumentNullException("property");
            }
        }