コード例 #1
0
        /// <inheritdoc />
        public sealed override object ReadInline(object item, IEdmTypeReference edmType, ODataDeserializerContext readContext)
        {
            if (readContext == null)
            {
                throw Error.ArgumentNull("readContext");
            }

            if (item == null)
            {
                return(null);
            }

            ODataComplexValue complexValue = item as ODataComplexValue;

            if (complexValue == null)
            {
                throw Error.Argument("item", SRResources.ArgumentMustBeOfType, typeof(ODataComplexValue).Name);
            }

            if (!edmType.IsComplex())
            {
                throw Error.Argument("edmType", SRResources.ArgumentMustBeOfType, EdmTypeKind.Complex);
            }

            // Recursion guard to avoid stack overflows
            RuntimeHelpers.EnsureSufficientExecutionStack();

            return(ReadComplexValue(complexValue, edmType.AsComplex(), readContext));
        }
コード例 #2
0
ファイル: StackGuard.cs プロジェクト: wilfriedb/runtime
        public bool TryEnterOnCurrentStack()
        {
#if NETFRAMEWORK || NETSTANDARD2_0
            try
            {
                RuntimeHelpers.EnsureSufficientExecutionStack();
                return(true);
            }
            catch (InsufficientExecutionStackException)
            {
            }
#else
            if (RuntimeHelpers.TryEnsureSufficientExecutionStack())
            {
                return(true);
            }
#endif

            if (_executionStackCount < MaxExecutionStackCount)
            {
                return(false);
            }

            throw new InsufficientExecutionStackException();
        }
コード例 #3
0
        /// <inheritdoc />
        public sealed override object ReadInline(object item, IEdmTypeReference edmType, ODataDeserializerContext readContext)
        {
            if (item == null)
            {
                return(null);
            }
            if (edmType == null)
            {
                throw Error.ArgumentNull("edmType");
            }

            if (!edmType.IsCollection())
            {
                throw new SerializationException(
                          Error.Format(SRResources.TypeCannotBeDeserialized, edmType.ToTraceString(), typeof(ODataMediaTypeFormatter)));
            }

            IEdmCollectionTypeReference collectionType = edmType.AsCollection();
            IEdmTypeReference           elementType    = collectionType.ElementType();

            ODataCollectionValue collection = item as ODataCollectionValue;

            if (collection == null)
            {
                throw Error.Argument("item", SRResources.ArgumentMustBeOfType, typeof(ODataCollectionValue).Name);
            }

            // Recursion guard to avoid stack overflows
            RuntimeHelpers.EnsureSufficientExecutionStack();

            return(ReadCollectionValue(collection, elementType, readContext));
        }
コード例 #4
0
        private bool DispatchTypeName(ITypeName type, int genericArgumentCount, bool isAttribute)
        {
            RuntimeHelpers.EnsureSufficientExecutionStack();
            var typeName = type as TypeName;

            if (typeName != null)
            {
                return(VisitTypeName(typeName, genericArgumentCount, isAttribute));
            }
            else
            {
                var arrayTypeName = type as ArrayTypeName;
                if (arrayTypeName != null)
                {
                    return(VisitArrayTypeName(arrayTypeName));
                }
                else
                {
                    var genericTypeName = type as GenericTypeName;
                    if (genericTypeName != null)
                    {
                        return(VisitGenericTypeName(genericTypeName));
                    }
                }
            }

            return(false);
        }
コード例 #5
0
        //private void SerializeSymbol(ISymbol symbol, IFastJsonWriter writer, string relationToParent) {
        //    RuntimeHelpers.EnsureSufficientExecutionStack();
        //    writer.WriteStartObject();
        //    writer.WriteProperty("type", "symbol");
        //    writer.WriteProperty("property", relationToParent);
        //    writer.WriteProperty("kind", symbol.Kind.ToString());
        //    writer.WritePropertyStartArray("children");
        //    writer.WriteStartObject();
        //    writer.WriteProperty("type", "property");
        //    writer.WriteProperty("property", "Name");
        //    writer.WriteProperty("value", symbol.Name);
        //    writer.WriteEndObject();
        //    writer.WriteEndArray();
        //    writer.WriteEndObject();
        //}

        private void SerializeOperation(IOperation operation, IFastJsonWriter writer)
        {
            RuntimeHelpers.EnsureSufficientExecutionStack();
            writer.WriteStartObject();
            writer.WriteProperty("type", "operation");
            writer.WriteProperty("property", "Operation");
            writer.WriteProperty("kind", operation.Kind.ToString());
            if (operation.ConstantValue.HasValue)
            {
                writer.WritePropertyStartArray("children");
                writer.WriteStartObject();
                writer.WriteProperty("type", "property-only");
                writer.WriteProperty("property", "Value");
                writer.WritePropertyName("value");
                switch (operation.ConstantValue.Value)
                {
                case int i: writer.WriteValue(i); break;

                case string s: writer.WriteValueFromParts("\"", s, "\""); break;

                case var v: writer.WriteValue(v?.ToString()); break;
                }
                writer.WriteEndObject();
                writer.WriteEndArray();
            }

            writer.WriteEndObject();
        }
コード例 #6
0
 public static void EnsureSufficientExecutionStack(int recursionDepth)
 {
     if (recursionDepth > MaxUncheckedRecursionDepth)
     {
         RuntimeHelpers.EnsureSufficientExecutionStack();
     }
 }
コード例 #7
0
        public bool TryEnterOnCurrentStack()
        {
#if NETCOREAPP2_0
            if (RuntimeHelpers.TryEnsureSufficientExecutionStack())
            {//尝试确保有足够的堆栈来执行平均 .NET Core 库函数
                return(true);
            }
#else
            try
            {
                RuntimeHelpers.EnsureSufficientExecutionStack();//确保剩余的堆栈控件足够大,可以执行一般的 .NET 函数
                return(true);
            }
            catch (InsufficientExecutionStackException)
            {
            }
#endif

            if (_executionStackCount < MaxExecutionStackCount)
            {
                return(false);
            }

            throw new InsufficientExecutionStackException();
        }
コード例 #8
0
        /// <summary>
        /// Binds a <see cref="QueryNode"/> to create a LINQ <see cref="Expression"/> that represents the semantics
        /// of the <see cref="QueryNode"/>.
        /// </summary>
        /// <param name="node">The node to bind.</param>
        /// <returns>The LINQ <see cref="Expression"/> created.</returns>
        public override Expression Bind(QueryNode node)
        {
            if (node == null)
            {
                throw Error.ArgumentNull(nameof(node));
            }

            // Recursion guard to avoid stack overflows
            RuntimeHelpers.EnsureSufficientExecutionStack();

            CollectionNode  collectionNode  = node as CollectionNode;
            SingleValueNode singleValueNode = node as SingleValueNode;

            if (collectionNode != null)
            {
                return(BindCollectionNode(collectionNode));
            }
            else if (singleValueNode != null)
            {
                return(BindSingleValueNode(singleValueNode));
            }
            else
            {
                throw Error.NotSupported(SRResources.QueryNodeBindingNotSupported, node.Kind, typeof(FilterBinder).Name);
            }
        }
コード例 #9
0
        internal static Exception?FetchCurrentOrNull(out ExceptionDispatchInfo?dispatchInfo)
        {
            dispatchInfo = null;

            // prevent potential interop errors in this method
            // from crashing process with undebuggable StackOverflowException
            RuntimeHelpers.EnsureSufficientExecutionStack();

            using var _ = new Py.GILState();
            Runtime.PyErr_Fetch(out var type, out var value, out var traceback);
            if (type.IsNull())
            {
                Debug.Assert(value.IsNull());
                Debug.Assert(traceback.IsNull());
                return(null);
            }

            Runtime.PyErr_NormalizeException(type: ref type, val: ref value, tb: ref traceback);

            try
            {
                return(FromPyErr(typeRef: type, valRef: value, tbRef: traceback, out dispatchInfo));
            }
            finally
            {
                type.Dispose();
                value.Dispose();
                traceback.Dispose();
            }
        }
コード例 #10
0
        private static ManifestEntry BuildEntry(XElement element)
        {
            RuntimeHelpers.EnsureSufficientExecutionStack();
            if (element.NodeType != XmlNodeType.Element)
            {
                throw new InvalidOperationException($"Invalid manifest format. Expected a 'File' or a 'Directory' node:" +
                                                    $" '{element.ToString()}'");
            }

            if (string.Equals(element.Name.LocalName, "File", StringComparison.Ordinal))
            {
                var entryName = EnsureName(element);
                var path      = EnsureElement(element, "ResourcePath");
                var pathValue = EnsureText(path);
                return(new ManifestFile(entryName, pathValue));
            }

            if (string.Equals(element.Name.LocalName, "Directory", StringComparison.Ordinal))
            {
                var directoryName = EnsureName(element);
                var children      = new List <ManifestEntry>();
                foreach (var child in element.Elements())
                {
                    children.Add(BuildEntry(child));
                }

                ValidateEntries(children);

                return(ManifestDirectory.CreateDirectory(directoryName, children.ToArray()));
            }

            throw new InvalidOperationException($"Invalid manifest format.Expected a 'File' or a 'Directory' node. " +
                                                $"Got '{element.Name.LocalName}' instead.");
        }
コード例 #11
0
        /// <inheritdoc />
        public sealed override object ReadInline(object item, IEdmTypeReference edmType, ODataDeserializerContext readContext)
        {
            if (edmType == null)
            {
                throw Error.ArgumentNull("edmType");
            }

            if (edmType.IsComplex() && item == null)
            {
                return(null);
            }

            if (item == null)
            {
                throw Error.ArgumentNull("item");
            }

            if (!edmType.IsStructured())
            {
                throw Error.Argument("edmType", SRResources.ArgumentMustBeOfType, "Entity or Complex");
            }

            ODataResourceWrapper resourceWrapper = item as ODataResourceWrapper;

            if (resourceWrapper == null)
            {
                throw Error.Argument("item", SRResources.ArgumentMustBeOfType, typeof(ODataResource).Name);
            }

            // Recursion guard to avoid stack overflows
            RuntimeHelpers.EnsureSufficientExecutionStack();

            return(ReadResource(resourceWrapper, edmType.AsStructured(), readContext));
        }
コード例 #12
0
        private async Task <ModelBindingResult> TryBind(ModelBindingContext bindingContext)
        {
            RuntimeHelpers.EnsureSufficientExecutionStack();

            foreach (var binder in ModelBinders)
            {
                var result = await binder.BindModelAsync(bindingContext);

                if (result != null)
                {
                    // Use returned ModelBindingResult if it either indicates the model was set or is related to a
                    // ModelState entry. The second condition is necessary because the ModelState entry would never be
                    // validated if caller fell back to the empty prefix, leading to an possibly-incorrect !IsValid.
                    //
                    // In most (hopefully all) cases, the ModelState entry exists because some binders add errors
                    // before returning a result with !IsModelSet. Those binders often cannot run twice anyhow.
                    if (result.IsModelSet || bindingContext.ModelState.ContainsKey(bindingContext.ModelName))
                    {
                        return(result);
                    }

                    // Current binder should have been able to bind value but found nothing. Exit loop in a way that
                    // tells caller to fall back to the empty prefix, if appropriate. Do not return result because it
                    // means only "other binders are not applicable".
                    break;
                }
            }

            // Either we couldn't find a binder, or the binder couldn't bind. Distinction is not important.
            return(null);
        }
コード例 #13
0
        private ExpressionAst CheckUsingExpression(ExpressionAst exprAst)
        {
            RuntimeHelpers.EnsureSufficientExecutionStack();
            if (exprAst is VariableExpressionAst)
            {
                return(null);
            }
            MemberExpressionAst ast = exprAst as MemberExpressionAst;

            if (((ast != null) && !(ast is InvokeMemberExpressionAst)) && (ast.Member is StringConstantExpressionAst))
            {
                return(this.CheckUsingExpression(ast.Expression));
            }
            IndexExpressionAst ast2 = exprAst as IndexExpressionAst;

            if (ast2 == null)
            {
                return(exprAst);
            }
            if (!this.IsValidAttributeArgument(ast2.Index))
            {
                return(ast2.Index);
            }
            return(this.CheckUsingExpression(ast2.Target));
        }
コード例 #14
0
        /// <inheritdoc />
        public sealed override object ReadInline(object item, IEdmTypeReference edmType, ODataDeserializerContext readContext)
        {
            if (item == null)
            {
                return(null);
            }
            if (edmType == null)
            {
                throw Error.ArgumentNull("edmType");
            }
            if (!edmType.IsCollection() || !edmType.AsCollection().ElementType().IsEntity())
            {
                throw Error.Argument("edmType", SRResources.TypeMustBeEntityCollection, edmType.ToTraceString(), typeof(IEdmEntityType).Name);
            }

            IEdmEntityTypeReference elementType = edmType.AsCollection().ElementType().AsEntity();

            ODataFeedWithEntries feed = item as ODataFeedWithEntries;

            if (feed == null)
            {
                throw Error.Argument("item", SRResources.ArgumentMustBeOfType, typeof(ODataFeedWithEntries).Name);
            }

            // Recursion guard to avoid stack overflows
            RuntimeHelpers.EnsureSufficientExecutionStack();

            return(ReadFeed(feed, elementType, readContext));
        }
コード例 #15
0
        /// <inheritdoc />
        public sealed override object ReadInline(object item, IEdmTypeReference edmType, ODataDeserializerContext readContext)
        {
            if (item == null)
            {
                throw Error.ArgumentNull("item");
            }
            if (edmType == null)
            {
                throw Error.ArgumentNull("edmType");
            }
            if (!edmType.IsEntity())
            {
                throw Error.Argument("edmType", SRResources.ArgumentMustBeOfType, EdmTypeKind.Entity);
            }

            ODataEntryWithNavigationLinks entryWrapper = item as ODataEntryWithNavigationLinks;

            if (entryWrapper == null)
            {
                throw Error.Argument("item", SRResources.ArgumentMustBeOfType, typeof(ODataEntry).Name);
            }

            // Recursion guard to avoid stack overflows
            RuntimeHelpers.EnsureSufficientExecutionStack();

            return(ReadEntry(entryWrapper, edmType.AsEntity(), readContext));
        }
コード例 #16
0
ファイル: EnumerableOps.cs プロジェクト: modulexcite/pash-1
 private static void MethodInvokerWorker(CallSite invokeMemberSite, IEnumerator enumerator, object[] args, ExecutionContext context, ArrayList result, ref bool foundMethod)
 {
     RuntimeHelpers.EnsureSufficientExecutionStack();
     while (MoveNext(context, enumerator))
     {
         object element = Current(enumerator);
         try
         {
             dynamic obj3 = invokeMemberSite;
             object  o    = obj3.Target.DynamicInvoke(args.Prepend <object>(element).Prepend <object>(invokeMemberSite).ToArray <object>());
             foundMethod = true;
             if (o != AutomationNull.Value)
             {
                 FlattenResults(o, result);
             }
             continue;
         }
         catch (TargetInvocationException exception)
         {
             RuntimeException innerException = exception.InnerException as RuntimeException;
             if ((innerException != null) && innerException.ErrorRecord.FullyQualifiedErrorId.Equals("MethodNotFound", StringComparison.Ordinal))
             {
                 IEnumerator enumerator2 = LanguagePrimitives.GetEnumerator(element);
                 if (enumerator2 != null)
                 {
                     MethodInvokerWorker(invokeMemberSite, enumerator2, args, context, result, ref foundMethod);
                     continue;
                 }
             }
             throw exception.InnerException;
         }
     }
 }
コード例 #17
0
        /// <inheritdoc />
        public sealed override object ReadInline(object item, IEdmTypeReference edmType, ODataDeserializerContext readContext)
        {
            if (item == null)
            {
                return(null);
            }
            if (edmType == null)
            {
                throw Error.ArgumentNull("edmType");
            }

            if (!edmType.IsCollection())
            {
                throw new SerializationException(
                          Error.Format(SRResources.TypeCannotBeDeserialized, edmType.ToTraceString(), typeof(ODataMediaTypeFormatter)));
            }

            IEdmCollectionTypeReference collectionType = edmType.AsCollection();
            IEdmTypeReference           elementType    = collectionType.ElementType();

            ODataCollectionValue collection = item as ODataCollectionValue;

            if (collection == null)
            {
                throw Error.Argument("item", SRResources.ArgumentMustBeOfType, typeof(ODataCollectionValue).Name);
            }
            // Recursion guard to avoid stack overflows
            RuntimeHelpers.EnsureSufficientExecutionStack();

            IEnumerable result = ReadCollectionValue(collection, elementType, readContext);

            if (result != null)
            {
                if (readContext.IsUntyped && elementType.IsComplex())
                {
                    EdmComplexObjectCollection complexCollection = new EdmComplexObjectCollection(collectionType);
                    foreach (EdmComplexObject complexObject in result)
                    {
                        complexCollection.Add(complexObject);
                    }
                    return(complexCollection);
                }
                else if (readContext.IsUntyped && elementType.IsEnum())
                {
                    EdmEnumObjectCollection enumCollection = new EdmEnumObjectCollection(collectionType);
                    foreach (EdmEnumObject enumObject in result)
                    {
                        enumCollection.Add(enumObject);
                    }
                    return(enumCollection);
                }
                else
                {
                    Type        elementClrType = EdmLibHelpers.GetClrType(elementType, readContext.Model);
                    IEnumerable castedResult   = _castMethodInfo.MakeGenericMethod(elementClrType).Invoke(null, new object[] { result }) as IEnumerable;
                    return(castedResult);
                }
            }
            return(null);
        }
コード例 #18
0
ファイル: ArrayTypeName.cs プロジェクト: modulexcite/pash-1
        private string GetName(bool includeAssemblyName)
        {
            StringBuilder builder = new StringBuilder();

            try
            {
                RuntimeHelpers.EnsureSufficientExecutionStack();
                builder.Append(this.ElementType.Name);
                builder.Append('[');
                if (this.Rank > 1)
                {
                    builder.Append(',', this.Rank - 1);
                }
                builder.Append(']');
                if (includeAssemblyName)
                {
                    string assemblyName = this.ElementType.AssemblyName;
                    if (assemblyName != null)
                    {
                        builder.Append(',');
                        builder.Append(assemblyName);
                    }
                }
            }
            catch (InsufficientExecutionStackException)
            {
                throw new ScriptCallDepthException();
            }
            return(builder.ToString());
        }
コード例 #19
0
 private void FormatMembers(
     CommonObjectFormatter.Builder result,
     object obj)
 {
     RuntimeHelpers.EnsureSufficientExecutionStack();
     result.Append(' ');
     if (!this.VisitedObjects.Add(obj))
     {
         result.AppendInfiniteRecursionMarker();
     }
     else
     {
         bool flag = false;
         if (obj is IDictionary dict)
         {
             this.FormatDictionaryMembers(result, dict);
             flag = true;
         }
         else if (obj is IEnumerable sequence)
         {
             this.FormatSequenceMembers(result, sequence);
             flag = true;
         }
         if (!flag)
         {
             this.FormatObjectMembers(result, obj);
         }
         this.VisitedObjects.Remove(obj);
     }
 }
コード例 #20
0
ファイル: QueryVisitor.cs プロジェクト: radtek/ravendb
        public void Visit(Query q)
        {
            RuntimeHelpers.EnsureSufficientExecutionStack();

            if (q.DeclaredFunctions != null)
            {
                VisitDeclaredFunctions(q.DeclaredFunctions);
            }

            if (q.From.From != null)
            {
                VisitFromClause(q.From.From, q.From.Alias, q.From.Filter, q.From.Index);
            }

            if (q.GraphQuery != null)
            {
                VisitGraph(q.GraphQuery);
            }

            if (q.GroupBy != null)
            {
                VisitGroupByExpression(q.GroupBy);
            }

            if (q.Where != null)
            {
                VisitWhereClause(q.Where);
            }

            if (q.OrderBy != null)
            {
                VisitOrderBy(q.OrderBy);
            }

            if (q.Load != null)
            {
                VisitLoad(q.Load);
            }

            if (q.Select != null)
            {
                VisitSelect(q.Select, q.IsDistinct);
            }

            if (q.SelectFunctionBody.FunctionText != null)
            {
                VisitSelectFunctionBody(q.SelectFunctionBody.FunctionText);
            }

            if (q.UpdateBody != null)
            {
                VisitUpdate(q.UpdateBody);
            }

            if (q.Include != null)
            {
                VisitInclude(q.Include);
            }
        }
コード例 #21
0
        /// <summary>
        /// Copies the changed property values from the underlying entity (accessible via <see cref="GetInstance()" />)
        /// to the <paramref name="original"/> entity recursively.
        /// </summary>
        /// <param name="original">The entity to be updated.</param>
        public void CopyChangedValues(TStructuralType original)
        {
            if (original == null)
            {
                throw Error.ArgumentNull("original");
            }

            // Delta parameter type cannot be derived type of original
            // to prevent unrecognizable information from being applied to original resource.
            if (!_structuredType.IsAssignableFrom(original.GetType()))
            {
                throw Error.Argument("original", SRResources.DeltaTypeMismatch, _structuredType, original.GetType());
            }

            RuntimeHelpers.EnsureSufficientExecutionStack();

            // For regular non-structural properties at current level.
            PropertyAccessor <TStructuralType>[] propertiesToCopy =
                this._changedProperties.Select(s => _allProperties[s]).ToArray();
            foreach (PropertyAccessor <TStructuralType> propertyToCopy in propertiesToCopy)
            {
                propertyToCopy.Copy(_instance, original);
            }

            CopyChangedDynamicValues(original);

            // For nested resources.
            foreach (string nestedResourceName in _deltaNestedResources.Keys)
            {
                // Patch for each nested resource changed under this TStructuralType.
                dynamic deltaNestedResource    = _deltaNestedResources[nestedResourceName];
                dynamic originalNestedResource = null;
                if (!TryGetPropertyRef(original, nestedResourceName, out originalNestedResource))
                {
                    throw Error.Argument(nestedResourceName, SRResources.DeltaNestedResourceNameNotFound,
                                         nestedResourceName, original.GetType());
                }

                if (originalNestedResource == null)
                {
                    // When patching original target of null value, directly set nested resource.
                    dynamic deltaObject = _deltaNestedResources[nestedResourceName];
                    dynamic instance    = deltaObject.GetInstance();

                    // Recursively patch up the instance with the nested resources.
                    deltaObject.CopyChangedValues(instance);

                    _allProperties[nestedResourceName].SetValue(original, instance);
                }
                else
                {
                    // Recursively patch the subtree.
                    bool isDeltaType = TypedDelta.IsDeltaOfT(deltaNestedResource.GetType());
                    Contract.Assert(isDeltaType, nestedResourceName + "'s corresponding value should be Delta<T> type but is not.");

                    deltaNestedResource.CopyChangedValues(originalNestedResource);
                }
            }
        }
コード例 #22
0
 private void CheckArrayLiteralAssignment(ArrayLiteralAst ast, Action <Ast> reportError)
 {
     RuntimeHelpers.EnsureSufficientExecutionStack();
     foreach (ExpressionAst ast2 in ast.Elements)
     {
         this.CheckAssignmentTarget(ast2, true, reportError);
     }
 }
コード例 #23
0
ファイル: Program.cs プロジェクト: gundermanc/MetadataTools
            public override AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters)
            {
                RuntimeHelpers.EnsureSufficientExecutionStack(); // see https://github.com/KirillOsenkov/MetadataTools/issues/4
                var resolved = checker.Resolve(name);

                resolved = resolved ?? base.Resolve(name, parameters);
                return(resolved);
            }
コード例 #24
0
        static void Recursive(int a, int b, int c)
        {
            RuntimeHelpers.EnsureSufficientExecutionStack();

            var ss = new SomeStruct();

            Recursive(a, b, c);
        }
コード例 #25
0
ファイル: Program.cs プロジェクト: simple555a/DotNetAppDev
 private static void ForseOverflow(bool forse)
 {
     if (forse)
     {
         RuntimeHelpers.EnsureSufficientExecutionStack();
         ForseOverflow(true);
     }
 }
コード例 #26
0
        bool __CanCastByVarianceToInterfaceOrDelegate(DmdType target)
        {
            if (MetadataToken != target.MetadataToken || Module != target.Module)
            {
                return(false);
            }

            // The original code used a list to check for infinite recursion, we'll use this code unless it throws too often
            try {
                RuntimeHelpers.EnsureSufficientExecutionStack();
            }
            catch (InsufficientExecutionStackException) {
                Debug.Fail("Should probably not happen often");
                return(false);
            }

            var inst = GetGenericArguments();

            if (inst.Count > 0)
            {
                var targetInst          = target.GetGenericArguments();
                var targetInstGenParams = target.GetGenericTypeDefinition().GetGenericArguments();

                for (int i = 0; i < inst.Count; i++)
                {
                    var thArg       = inst[i];
                    var thTargetArg = targetInst[i];

                    if (!thArg.IsEquivalentTo(thTargetArg))
                    {
                        switch (targetInstGenParams[i].GenericParameterAttributes & DmdGenericParameterAttributes.VarianceMask)
                        {
                        case DmdGenericParameterAttributes.Covariant:
                            if (!thArg.__IsBoxedAndCanCastTo(thTargetArg))
                            {
                                return(false);
                            }
                            break;

                        case DmdGenericParameterAttributes.Contravariant:
                            if (!thTargetArg.__IsBoxedAndCanCastTo(thArg))
                            {
                                return(false);
                            }
                            break;

                        case DmdGenericParameterAttributes.None:
                            return(false);

                        default:
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
コード例 #27
0
        private static void checkStackInternal()
        {
#pragma warning disable CS0168
            decimal f0, f1, f2, f3, f4, f5, f6, f7, f8;
#pragma warning restore CS0168
#if !(PORTABLE || NETCORE) && !NET35
            RuntimeHelpers.EnsureSufficientExecutionStack();
#endif
        }
コード例 #28
0
        private static unsafe int ConsumeStack()
        {
            var t        = 0;
            var stackTop = (ulong)&t;

            minStackTop = Math.Min(stackTop, minStackTop);
            RuntimeHelpers.EnsureSufficientExecutionStack();
            return(ConsumeStack() + 1);
        }
コード例 #29
0
        /// <inheritdoc />
        public sealed override object ReadInline(object item, IEdmTypeReference edmType, ODataDeserializerContext readContext)
        {
            if (item == null)
            {
                return(null);
            }

            if (edmType == null)
            {
                throw Error.ArgumentNull("edmType");
            }

            if (!edmType.IsCollection() || !edmType.AsCollection().ElementType().IsStructured())
            {
                throw Error.Argument("edmType", SRResources.TypeMustBeResourceSet, edmType.ToTraceString());
            }

            ODataResourceSetWrapper resourceSet = item as ODataResourceSetWrapper;

            if (resourceSet == null)
            {
                throw Error.Argument("item", SRResources.ArgumentMustBeOfType, typeof(ODataResourceSetWrapper).Name);
            }

            // Recursion guard to avoid stack overflows
            RuntimeHelpers.EnsureSufficientExecutionStack();

            IEdmStructuredTypeReference elementType = edmType.AsCollection().ElementType().AsStructured();

            IEnumerable result = ReadResourceSet(resourceSet, elementType, readContext);

            if (result != null && elementType.IsComplex())
            {
                if (readContext.IsUntyped)
                {
                    EdmComplexObjectCollection complexCollection = new EdmComplexObjectCollection(edmType.AsCollection());
                    foreach (EdmComplexObject complexObject in result)
                    {
                        complexCollection.Add(complexObject);
                    }
                    return(complexCollection);
                }
                else
                {
                    Type        elementClrType = EdmLibHelpers.GetClrType(elementType, readContext.Model);
                    IEnumerable castedResult   =
                        CastMethodInfo.MakeGenericMethod(elementClrType).Invoke(null, new object[] { result }) as
                        IEnumerable;
                    return(castedResult);
                }
            }
            else
            {
                return(result);
            }
        }
コード例 #30
0
 // Recurse method.
 private static void RecurseWithStackCheck()
 {
     try {
         RuntimeHelpers.EnsureSufficientExecutionStack();
         RecurseWithStackCheck();
     }
     catch (Exception e) {
         Console.WriteLine(e.Message);
     }
 }