Castle.MonoRail.Views.Brail.ExpandDuckTypedExpressions_WorkaroundForDuplicateVirtualMethods.SetProperty C# (CSharp) Méthode

SetProperty() public static méthode

public static SetProperty ( object target, string name, object value ) : object
target object
name string
value object
Résultat object
		public static object SetProperty(object target, string name, object value)
		{
			IQuackFu duck = target as IQuackFu;
			if (null != duck) return duck.QuackSet(name, null, value);

			Type type = target as Type;
			if (null == type)
			{
				target.GetType().InvokeMember(name,
				                              ResolveFlagsToUse(target.GetType(), SetPropertyBindingFlags),
				                              null,
				                              target,
				                              new object[] {value});
			}
			else
			{
				// static member
				type.InvokeMember(name,
				                  SetPropertyBindingFlags,
				                  null,
				                  null,
				                  new object[] {value});
			}
			return value;
		}

Usage Example

 public object QuackSet(string name, object[] parameters, object obj)
 {
     if (target == null)
     {
         return(this);
     }
     if (IsNullOrEmpty(parameters))
     {
         ExpandDuckTypedExpressions_WorkaroundForDuplicateVirtualMethods.SetProperty(target, name, obj);
     }
     else
     {
         ExpandDuckTypedExpressions_WorkaroundForDuplicateVirtualMethods.SetSlice(target, name,
                                                                                  GetParameterArray(parameters, obj));
     }
     return(this);
 }