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


C# DynamicMetaObject.Except方法代码示例

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


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

示例1: FallbackCreateInstance

 public override DynamicMetaObject FallbackCreateInstance(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion)
 {
     bool flag;
     Type type = (Type) target.Value;
     MethodInformation[] methodInformationArray = DotNetAdapter.GetMethodInformationArray(type.GetConstructors());
     target = new DynamicMetaObject(target.Expression, BindingRestrictions.GetInstanceRestriction(target.Expression, target.Value), target.Value);
     string errorId = null;
     string errorMsg = null;
     int count = base.CallInfo.ArgumentCount - base.CallInfo.ArgumentNames.Count;
     MethodInformation information = Adapter.FindBestMethod(methodInformationArray, null, (from arg in args.Take<DynamicMetaObject>(count) select arg.Value).ToArray<object>(), ref errorId, ref errorMsg, out flag);
     if (information == null)
     {
         if (errorSuggestion == null)
         {
         }
         return new DynamicMetaObject(Expression.Throw(Expression.New(CachedReflectionInfo.MethodException_ctor, new Expression[] { Expression.Constant(errorId), Expression.Constant(null, typeof(Exception)), Expression.Constant(errorMsg), Expression.NewArrayInit(typeof(object), new Expression[] { Expression.Constant(".ctor").Cast(typeof(object)), ExpressionCache.Constant(count).Cast(typeof(object)) }) }), this.ReturnType), target.CombineRestrictions(args));
     }
     ConstructorInfo method = (ConstructorInfo) information.method;
     ParameterInfo[] parameters = method.GetParameters();
     Expression[] arguments = new Expression[parameters.Length];
     int index = 0;
     while (index < parameters.Length)
     {
         bool flag3;
         Type parameterType = parameters[index].ParameterType;
         if (parameters[index].GetCustomAttributes(typeof(ParamArrayAttribute), true).Any<object>() && flag)
         {
             Type elementType = parameters[index].ParameterType.GetElementType();
             List<Expression> initializers = new List<Expression>();
             int num3 = index;
             int num4 = index;
             while (num4 < count)
             {
                 bool flag2;
                 LanguagePrimitives.ConversionData data = LanguagePrimitives.FigureConversion(args[index].Value, elementType, out flag2);
                 initializers.Add(PSConvertBinder.InvokeConverter(data, args[num4].Expression, elementType, flag2, ExpressionCache.InvariantCulture));
                 num4++;
                 index++;
             }
             arguments[num3] = Expression.NewArrayInit(elementType, initializers);
             break;
         }
         LanguagePrimitives.ConversionData conversion = LanguagePrimitives.FigureConversion(args[index].Value, parameterType, out flag3);
         arguments[index] = PSConvertBinder.InvokeConverter(conversion, args[index].Expression, parameterType, flag3, ExpressionCache.InvariantCulture);
         index++;
     }
     Expression right = Expression.New(method, arguments);
     if (base.CallInfo.ArgumentNames.Any<string>())
     {
         ParameterExpression expr = Expression.Parameter(right.Type);
         List<Expression> expressions = new List<Expression>();
         foreach (string str3 in base.CallInfo.ArgumentNames)
         {
             Expression expression3;
             Type propertyType;
             bool flag4;
             MemberInfo[] infoArray3 = type.GetMember(str3, MemberTypes.Property | MemberTypes.Field, BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase);
             if ((infoArray3.Length != 1) || (!(infoArray3[0] is PropertyInfo) && !(infoArray3[0] is FieldInfo)))
             {
                 return target.ThrowRuntimeError(args, BindingRestrictions.Empty, "PropertyNotFoundForType", ParserStrings.PropertyNotFoundForType, new Expression[] { Expression.Constant(str3), Expression.Constant(type) });
             }
             MemberInfo info2 = infoArray3[0];
             if (info2 is PropertyInfo)
             {
                 PropertyInfo property = (PropertyInfo) info2;
                 if (property.GetSetMethod() == null)
                 {
                     return target.ThrowRuntimeError(args, BindingRestrictions.Empty, "PropertyIsReadOnly", ParserStrings.PropertyIsReadOnly, new Expression[] { Expression.Constant(str3) });
                 }
                 propertyType = property.PropertyType;
                 expression3 = Expression.Property(expr.Cast(info2.DeclaringType), property);
             }
             else
             {
                 propertyType = ((FieldInfo) info2).FieldType;
                 expression3 = Expression.Field(expr.Cast(info2.DeclaringType), (FieldInfo) info2);
             }
             LanguagePrimitives.ConversionData data3 = LanguagePrimitives.FigureConversion(args[index].Value, propertyType, out flag4);
             if (data3.Rank == ConversionRank.None)
             {
                 return PSConvertBinder.ThrowNoConversion(args[index], propertyType, this, -1, args.Except<DynamicMetaObject>(new DynamicMetaObject[] { args[index] }).Prepend<DynamicMetaObject>(target).ToArray<DynamicMetaObject>());
             }
             expressions.Add(Expression.Assign(expression3, PSConvertBinder.InvokeConverter(data3, args[index].Expression, propertyType, flag4, ExpressionCache.InvariantCulture)));
             index++;
         }
         ParameterExpression variable = Expression.Parameter(typeof(Exception));
         BlockExpression expression5 = Expression.Block(Expression.Assign(expr, right), Expression.TryCatch(Expression.Block(typeof(void), expressions), new CatchBlock[] { Expression.Catch(variable, Expression.Block(Expression.Call(CachedReflectionInfo.CommandProcessorBase_CheckForSevereException, variable), Compiler.ThrowRuntimeErrorWithInnerException("PropertyAssignmentException", Expression.Property(variable, "Message"), variable, typeof(void), new Expression[0]))) }), expr);
         right = Expression.Block(new ParameterExpression[] { expr }, new Expression[] { expression5 });
     }
     return new DynamicMetaObject(right, target.CombineRestrictions(args));
 }
开发者ID:nickchal,项目名称:pash,代码行数:91,代码来源:PSAttributeGenerator.cs

示例2: SetIndexMultiDimensionArray

 private DynamicMetaObject SetIndexMultiDimensionArray(DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject value, DynamicMetaObject errorSuggestion)
 {
     Type elementType = target.LimitType.GetElementType();
     Expression expression = PSGetIndexBinder.ConvertIndex(value, elementType);
     if (expression != null)
     {
         if ((int)indexes.Length != 1)
         {
             Array arrays = (Array)target.Value;
             if ((int)indexes.Length == arrays.Rank)
             {
                 Expression[] expressionArray = new Expression[(int)indexes.Length];
                 int num = 0;
                 while (num < (int)indexes.Length)
                 {
                     expressionArray[num] = PSGetIndexBinder.ConvertIndex(indexes[num], typeof(int));
                     if (expressionArray[num] != null)
                     {
                         num++;
                     }
                     else
                     {
                         DynamicMetaObject[] dynamicMetaObjectArray = new DynamicMetaObject[1];
                         dynamicMetaObjectArray[0] = indexes[num];
                         return PSConvertBinder.ThrowNoConversion(indexes[num], typeof(int), this, this._version, indexes.Except<DynamicMetaObject>(dynamicMetaObjectArray).Append<DynamicMetaObject>(target).Append<DynamicMetaObject>(value).ToArray<DynamicMetaObject>());
                     }
                 }
                 return new DynamicMetaObject(Expression.Call(CachedReflectionInfo.ArrayOps_SetMDArrayValue, target.Expression.Cast(typeof(Array)), Expression.NewArrayInit(typeof(int), expressionArray), expression.Cast(typeof(object))), target.CombineRestrictions(indexes).Merge(value.PSGetTypeRestriction()));
             }
             else
             {
                 DynamicMetaObject dynamicMetaObject = errorSuggestion;
                 DynamicMetaObject dynamicMetaObject1 = dynamicMetaObject;
                 if (dynamicMetaObject == null)
                 {
                     DynamicMetaObject dynamicMetaObject2 = target;
                     DynamicMetaObject[] dynamicMetaObjectArray1 = indexes;
                     BindingRestrictions bindingRestriction = value.PSGetTypeRestriction();
                     string str = "NeedMultidimensionalIndex";
                     string needMultidimensionalIndex = ParserStrings.NeedMultidimensionalIndex;
                     Expression[] expressionArray1 = new Expression[2];
                     expressionArray1[0] = ExpressionCache.Constant(arrays.Rank);
                     Expression[] expressionArray2 = expressionArray1;
                     int num1 = 1;
                     MethodInfo arrayOpsIndexStringMessage = CachedReflectionInfo.ArrayOps_IndexStringMessage;
                     Type type = typeof(object);
                     DynamicMetaObject[] dynamicMetaObjectArray2 = indexes;
                     expressionArray2[num1] = Expression.Call(arrayOpsIndexStringMessage, Expression.NewArrayInit(type, dynamicMetaObjectArray2.Select<DynamicMetaObject, Expression>((DynamicMetaObject i) => i.Expression.Cast(typeof(object)))));
                     dynamicMetaObject1 = dynamicMetaObject2.ThrowRuntimeError(dynamicMetaObjectArray1, bindingRestriction, str, needMultidimensionalIndex, expressionArray1);
                 }
                 return dynamicMetaObject1;
             }
         }
         else
         {
             Expression expression1 = PSGetIndexBinder.ConvertIndex(indexes[0], typeof(int[]));
             if (expression1 != null)
             {
                 return new DynamicMetaObject(Expression.Call(CachedReflectionInfo.ArrayOps_SetMDArrayValue, target.Expression.Cast(typeof(Array)), expression1, expression.Cast(typeof(object))), target.CombineRestrictions(indexes).Merge(value.PSGetTypeRestriction()));
             }
             else
             {
                 DynamicMetaObject dynamicMetaObject3 = errorSuggestion;
                 DynamicMetaObject dynamicMetaObject4 = dynamicMetaObject3;
                 if (dynamicMetaObject3 == null)
                 {
                     DynamicMetaObject[] dynamicMetaObjectArray3 = new DynamicMetaObject[2];
                     dynamicMetaObjectArray3[0] = target;
                     dynamicMetaObjectArray3[1] = value;
                     dynamicMetaObject4 = PSConvertBinder.ThrowNoConversion(indexes[0], typeof(int[]), this, this._version, dynamicMetaObjectArray3);
                 }
                 return dynamicMetaObject4;
             }
         }
     }
     else
     {
         DynamicMetaObject dynamicMetaObject5 = errorSuggestion;
         DynamicMetaObject dynamicMetaObject6 = dynamicMetaObject5;
         if (dynamicMetaObject5 == null)
         {
             dynamicMetaObject6 = PSConvertBinder.ThrowNoConversion(value, elementType, this, this._version, indexes.Prepend<DynamicMetaObject>(target).ToArray<DynamicMetaObject>());
         }
         return dynamicMetaObject6;
     }
 }
开发者ID:nickchal,项目名称:pash,代码行数:86,代码来源:PSSetIndexBinder.cs


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