当前位置: 首页>>代码示例>>C#>>正文


C# Binder.ChangeType方法代码示例

本文整理汇总了C#中System.Reflection.Binder.ChangeType方法的典型用法代码示例。如果您正苦于以下问题:C# Binder.ChangeType方法的具体用法?C# Binder.ChangeType怎么用?C# Binder.ChangeType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Reflection.Binder的用法示例。


在下文中一共展示了Binder.ChangeType方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConvertArgs

		internal static bool ConvertArgs (Binder binder, object[] args, ParameterInfo[] pinfo, CultureInfo culture) {
			if (args == null) {
				if ( pinfo.Length == 0)
					return true;
				else
					throw new TargetParameterCountException ();
			}
			if (pinfo.Length != args.Length)
				throw new TargetParameterCountException ();
			for (int i = 0; i < args.Length; ++i) {
				object v = binder.ChangeType (args [i], pinfo[i].ParameterType, culture);
				if ((v == null) && (args [i] != null))
					return false;
				args [i] = v;
			}
			return true;
		}
开发者ID:tgiphil,项目名称:Mono-Class-Libraries,代码行数:17,代码来源:Binder.cs

示例2: ConvertParams

 private object[] ConvertParams(int offset, object[] parameters, Binder binder, CultureInfo culture)
 {
     int length = this.formalParams.Length;
     if (this.hasVarargs)
     {
         length--;
     }
     for (int i = offset; i < length; i++)
     {
         Type parameterType = this.formalParams[i].ParameterType;
         if (parameterType != Typeob.Object)
         {
             parameters[i] = binder.ChangeType(parameters[i], parameterType, culture);
         }
     }
     return parameters;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:17,代码来源:JSNativeMethod.cs

示例3: SetValue

		public override void SetValue (object obj, object val, BindingFlags invokeAttr, Binder binder, CultureInfo culture)
		{
			if (!IsStatic) {
				if (obj == null)
					throw new TargetException ("Non-static field requires a target");
				if (!DeclaringType.IsAssignableFrom (obj.GetType ()))
					throw new ArgumentException (string.Format (
						"Field {0} defined on type {1} is not a field on the target object which is of type {2}.",
					 	Name, DeclaringType, obj.GetType ()),
					 	"obj");
			}
			if (IsLiteral)
				throw new FieldAccessException ("Cannot set a constant field");
			if (binder == null)
				binder = Binder.DefaultBinder;
			CheckGeneric ();
			if (val != null) {
				object newVal;
				newVal = binder.ChangeType (val, FieldType, culture);
				if (newVal == null)
					throw new ArgumentException ("Object type " + val.GetType() + " cannot be converted to target type: " + FieldType, "val");
				val = newVal;
			}
			SetValueInternal (this, obj, val);
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:25,代码来源:MonoField.cs

示例4: LickArgumentsIntoShape

 private static object[] LickArgumentsIntoShape(ParameterInfo[] pars, object[] arguments, Binder binder, CultureInfo culture)
 {
     if (arguments == null)
     {
         return null;
     }
     int length = pars.Length;
     if (length == 0)
     {
         return null;
     }
     object[] objArray = arguments;
     int num2 = arguments.Length;
     if (num2 != length)
     {
         objArray = new object[length];
     }
     int index = length - 1;
     int num4 = (num2 < index) ? num2 : index;
     for (int i = 0; i < num4; i++)
     {
         object obj2 = arguments[i];
         if (obj2 is DBNull)
         {
             objArray[i] = null;
         }
         else
         {
             objArray[i] = binder.ChangeType(arguments[i], pars[i].ParameterType, culture);
         }
     }
     for (int j = num4; j < index; j++)
     {
         object defaultParameterValue = TypeReferences.GetDefaultParameterValue(pars[j]);
         if (defaultParameterValue == System.Convert.DBNull)
         {
             defaultParameterValue = binder.ChangeType(null, pars[j].ParameterType, culture);
         }
         objArray[j] = defaultParameterValue;
     }
     if (Microsoft.JScript.CustomAttribute.IsDefined(pars[index], typeof(ParamArrayAttribute), false))
     {
         int num7 = num2 - index;
         if (num7 < 0)
         {
             num7 = 0;
         }
         Type elementType = pars[index].ParameterType.GetElementType();
         Array array = Array.CreateInstance(elementType, num7);
         for (int k = 0; k < num7; k++)
         {
             array.SetValue(binder.ChangeType(arguments[k + index], elementType, culture), k);
         }
         objArray[index] = array;
         return objArray;
     }
     if (num2 < length)
     {
         object obj4 = TypeReferences.GetDefaultParameterValue(pars[index]);
         if (obj4 == System.Convert.DBNull)
         {
             obj4 = binder.ChangeType(null, pars[index].ParameterType, culture);
         }
         objArray[index] = obj4;
         return objArray;
     }
     objArray[index] = binder.ChangeType(arguments[index], pars[index].ParameterType, culture);
     return objArray;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:69,代码来源:LateBinding.cs

示例5: ConvertParams

 private Object[] ConvertParams(int offset, Object[] parameters, Binder binder, CultureInfo culture){
   int n = this.formalParams.Length;
   if (this.hasVarargs) n--;
   for (int i = offset; i < n; i++){
     Type fpt = this.formalParams[i].ParameterType;
     if (fpt != Typeob.Object)
       parameters[i] = binder.ChangeType(parameters[i], fpt, culture);
   }
   return parameters;  
 }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:10,代码来源:jsnativemethod.cs

示例6: CopyToNewParamArray

 private static Array CopyToNewParamArray(Type t, int n, object[] args, int offset, Binder binder, CultureInfo culture)
 {
     Array array = Array.CreateInstance(t, n);
     for (int i = 0; i < n; i++)
     {
         array.SetValue(binder.ChangeType(args[i + offset], t, culture), i);
     }
     return array;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:9,代码来源:FunctionObject.cs

示例7: ConvertArguments

 private void ConvertArguments(object[] args, object[] newargs, int offset, int length, int n, Binder binder, CultureInfo culture)
 {
     ParameterInfo[] parameterInfos = this.parameterInfos;
     if (parameterInfos != null)
     {
         int num = 0;
         for (int i = offset; num < n; i++)
         {
             Type parameterType = parameterInfos[i].ParameterType;
             if ((num == (n - 1)) && Microsoft.JScript.CustomAttribute.IsDefined(parameterInfos[i], typeof(ParamArrayAttribute), false))
             {
                 int num3 = length - num;
                 if (num3 < 0)
                 {
                     num3 = 0;
                 }
                 newargs[i] = CopyToNewParamArray(parameterType.GetElementType(), num3, args, num, binder, culture);
                 return;
             }
             object obj2 = (num < length) ? args[num] : null;
             if (parameterType == Typeob.Object)
             {
                 newargs[i] = obj2;
             }
             else if (binder != null)
             {
                 newargs[i] = binder.ChangeType(obj2, parameterType, culture);
             }
             else
             {
                 newargs[i] = Microsoft.JScript.Convert.CoerceT(obj2, parameterType);
             }
             num++;
         }
     }
     else
     {
         ParameterDeclaration[] declarationArray = this.parameter_declarations;
         int index = 0;
         for (int j = offset; index < n; j++)
         {
             IReflect parameterIReflect = declarationArray[index].ParameterIReflect;
             if ((index == (n - 1)) && Microsoft.JScript.CustomAttribute.IsDefined(declarationArray[j], typeof(ParamArrayAttribute), false))
             {
                 int num6 = length - index;
                 if (num6 < 0)
                 {
                     num6 = 0;
                 }
                 newargs[j] = CopyToNewParamArray(((TypedArray) parameterIReflect).elementType, num6, args, index);
                 return;
             }
             object obj3 = (index < length) ? args[index] : null;
             if (parameterIReflect == Typeob.Object)
             {
                 newargs[j] = obj3;
             }
             else if (parameterIReflect is ClassScope)
             {
                 newargs[j] = Microsoft.JScript.Convert.Coerce(obj3, parameterIReflect);
             }
             else if (binder != null)
             {
                 newargs[j] = binder.ChangeType(obj3, Microsoft.JScript.Convert.ToType(parameterIReflect), culture);
             }
             else
             {
                 newargs[j] = Microsoft.JScript.Convert.CoerceT(obj3, Microsoft.JScript.Convert.ToType(parameterIReflect));
             }
             index++;
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:73,代码来源:FunctionObject.cs

示例8: CopyToNewParamArray

 private static System.Array CopyToNewParamArray(Type t, int n, Object[] args, int offset, Binder binder, CultureInfo culture){
   System.Array paramArray = System.Array.CreateInstance(t, n);
   for (int i = 0; i < n; i++)
     paramArray.SetValue(binder.ChangeType(args[i+offset], t, culture), i);
   return paramArray;
 }
开发者ID:ArildF,项目名称:masters,代码行数:6,代码来源:functionobject.cs

示例9: ConvertArguments

 private void ConvertArguments(Object[] args, Object[] newargs, int offset, int length, int n, Binder binder, CultureInfo culture){
   ParameterInfo[] pars = this.parameterInfos;
   if (pars != null){
     for (int i = 0, j = offset; i < n; i++, j++){
       Type t = pars[j].ParameterType;
       if (i == n-1 && pars[j].IsDefined(Typeob.ParamArrayAttribute, false)){
         int k = length-i; if (k < 0) k = 0;
         newargs[j] = FunctionObject.CopyToNewParamArray(t.GetElementType(), k, args, i, binder, culture);
         return;
       }
       Object argval = i < length ? args[i] : null;
       if (t == Typeob.Object)
         newargs[j] = argval;
       else if (binder != null)
         newargs[j] = binder.ChangeType(argval, t, culture);
       else
         newargs[j] = Convert.CoerceT(argval, t);
     }
   }else{
     ParameterDeclaration[] pds = this.parameter_declarations;
     for (int i = 0, j = offset; i < n; i++, j++){
       IReflect ir = pds[i].ParameterIReflect;
       if (i == n-1 && pds[j].IsDefined(Typeob.ParamArrayAttribute, false)){
         int k = length-i; if (k < 0) k = 0;
         newargs[j] = FunctionObject.CopyToNewParamArray(((TypedArray)ir).elementType, k, args, i);
         return;
       }
       Object argval = i < length ? args[i] : null;
       if (ir == Typeob.Object){
         newargs[j] = argval; continue;
       }
       if (ir is ClassScope)
         newargs[j] = Convert.Coerce(argval, ir);
       else if (binder != null)
         newargs[j] = binder.ChangeType(argval, Convert.ToType(ir), culture);
       else
         newargs[j] = Convert.CoerceT(argval, Convert.ToType(ir));
     }
   }
 }
开发者ID:ArildF,项目名称:masters,代码行数:40,代码来源:functionobject.cs

示例10: LickArgumentsIntoShape

 //Do not call this method for arguments that are going out to COM2 objects via interop.
 private static Object[] LickArgumentsIntoShape(ParameterInfo[] pars, Object[] arguments, Binder binder, CultureInfo culture){
   if (arguments == null)
     return null;
   int formals = pars.Length;
   if (formals == 0)
     return null;
   Object[] newArgs = arguments;
   int actuals = arguments.Length;
   if (actuals != formals)
     newArgs = new Object[formals];
   int m = formals-1; //Position of last formal param
   int k = actuals < m ? actuals : m; //Number of formal params that have corresponding actual arguments, bar the last one, which may be a varArg array.
   //Copy all actual args that match formal param, bar the last one. Change DBNull to null. Coerce actual value to formal param type.
   for (int i = 0; i < k; i++){
     Object arg = arguments[i];
     if (arg is DBNull)
       newArgs[i] = null; //Outside of the world of OLE Variants, undefined == null == the null pointer.
     else
       newArgs[i] = binder.ChangeType(arguments[i], pars[i].ParameterType, culture);
   }
   //Supply default values for all formal params, bar the last one, that do not have corresponding actual arguments
   for (int i = k; i < m; i++){
     Object dv = pars[i].DefaultValue;
     if (dv == System.Convert.DBNull) //No default value was specified
       dv = binder.ChangeType(null, pars[i].ParameterType, culture); //Substitute undefined
     newArgs[i] = dv;
   }
   //If the last formal param is a vararg param, treat it specially.
   if (pars[m].IsDefined(Typeob.ParamArrayAttribute, false)){
     int numVarArgs = actuals - m;
     if (numVarArgs < 0) numVarArgs = 0;
     Type t = pars[m].ParameterType.GetElementType();
     Array pa = Array.CreateInstance(t, numVarArgs);
     for (int j = 0; j < numVarArgs; j++)
       pa.SetValue(binder.ChangeType(arguments[j+m], t, culture), j);
     newArgs[m] = pa;
   }else if (actuals < formals){
     Object dv = pars[m].DefaultValue;
     if (dv == System.Convert.DBNull) //No default value was specified
       dv = binder.ChangeType(null, pars[m].ParameterType, culture); //Substitute undefined
     newArgs[m] = dv;
   }else
     newArgs[m] = binder.ChangeType(arguments[m], pars[m].ParameterType, culture);
   return newArgs;
 }
开发者ID:ArildF,项目名称:masters,代码行数:46,代码来源:latebinding.cs

示例11: SetValue

		public override void SetValue (object obj, object val, BindingFlags invokeAttr, Binder binder, CultureInfo culture)
		{
			if (!IsStatic && obj == null)
				throw new TargetException ("Non-static field requires a target");
			if (IsLiteral)
				throw new FieldAccessException ("Cannot set a constant field");
			if (binder == null)
				binder = Binder.DefaultBinder;
			CheckGeneric ();
			if (val != null) {
				object newVal;
				newVal = binder.ChangeType (val, type, culture);
				if (newVal == null)
					throw new ArgumentException ("Object type " + val.GetType() + " cannot be converted to target type: " + type, "val");
				val = newVal;
			}
			SetValueInternal (this, obj, val);
		}
开发者ID:runefs,项目名称:Marvin,代码行数:18,代码来源:MonoField.cs


注:本文中的System.Reflection.Binder.ChangeType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。