private static void SetupSystemReflection(NamespacePolicy namespacePolicy) { ForEachTypeInNamespaceOf <MemberInfo>(type => { if (type.IsEnum) { namespacePolicy.Type(type, Allowed); return; } if (!type.GetTypeInfo().IsSameAsOrSubclassOf <MemberInfo>()) { return; } namespacePolicy.Type(type, Neutral, typePolicy => { foreach (var property in type.GetProperties()) { if (property.Name.Contains("Handle")) { continue; } typePolicy.Getter(property.Name, Allowed); } foreach (var method in type.GetMethods()) { if (method.ReturnType.GetTypeInfo().IsSameAsOrSubclassOf <MemberInfo>()) { typePolicy.Member(method.Name, Allowed); } } }); }); }
private static void SetupSystemLinqExpressions(NamespacePolicy namespacePolicy) { ForEachTypeInNamespaceOf <Expression>(type => { if (type.IsEnum) { namespacePolicy.Type(type, Allowed); return; } if (!type.GetTypeInfo().IsSameAsOrSubclassOf <Expression>()) { return; } namespacePolicy.Type(type, Allowed, typePolicy => { foreach (var method in type.GetMethods()) { if (method.Name.Contains("Compile")) { typePolicy.Member(method.Name, Denied); } } }); }); }
private static void SystemPolicy(NamespacePolicy policy) { foreach (Type type in Primitives.Types) { policy .Type(type, AccessPolicy.Allowed); } policy .Type(typeof(void).Name, AccessPolicy.Allowed) .Type(typeof(object).Name, AccessPolicy.Denied, m => m.Member(nameof(ToString), AccessPolicy.Allowed) .Constructor(AccessPolicy.Allowed)); }
private static void SetupSystemGlobalization(NamespacePolicy globalization) { globalization .Type(nameof(CultureInfo), Neutral, t => t.Getter(nameof(CultureInfo.InvariantCulture), Allowed) ); }
private static void SetupSystemText(NamespacePolicy text) { text .Type(nameof(Encoding), Allowed, t => t.Member(nameof(Encoding.RegisterProvider), Denied) .Setter(nameof(Encoding.DecoderFallback), Denied) .Setter(nameof(Encoding.EncoderFallback), Denied) .Member(nameof(Encoding.Convert), Allowed, ArrayReturnRewriter.Default) .Member(nameof(Encoding.GetEncodings), Allowed, ArrayReturnRewriter.Default) .Member(nameof(Encoding.GetPreamble), Allowed, ArrayReturnRewriter.Default) .Member(nameof(Encoding.GetBytes), Allowed, ArrayReturnRewriter.Default) .Member(nameof(Encoding.GetChars), Allowed, ArrayReturnRewriter.Default) .Member(nameof(Encoding.GetString), Allowed, StringReturnRewriter.Default) ) .Type(nameof(StringBuilder), Neutral, t => t.Constructor(Allowed, CountArgumentRewriter.ForCapacity) .Member(nameof(StringBuilder.Append), Allowed, AddCallRewriter.Default, CountArgumentRewriter.Default, new CountArgumentRewriter("repeatCount")) .Member(nameof(StringBuilder.AppendFormat), Allowed, AddCallRewriter.Default) .Member(nameof(StringBuilder.AppendLine), Allowed, AddCallRewriter.Default) .Member(nameof(StringBuilder.Clear), Allowed) .Member(nameof(StringBuilder.EnsureCapacity), Allowed, CountArgumentRewriter.ForCapacity) .Getter(nameof(StringBuilder.Insert), Allowed, AddCallRewriter.Default, CountArgumentRewriter.Default) .Getter(nameof(StringBuilder.Remove), Allowed) .Getter(nameof(StringBuilder.Replace), Allowed) .Getter(nameof(StringBuilder.ToString), Allowed) .Getter(nameof(StringBuilder.Length), Allowed) .Getter(nameof(StringBuilder.MaxCapacity), Allowed) ); }
private static void SetupSystemTextRegularExpressions(NamespacePolicy text) { text .Type(nameof(Regex), Neutral, t => t.Constructor(Allowed, RegexDangerousMethodCallRewriter.Default) .Getter(nameof(Regex.Options), Allowed) .Getter(nameof(Regex.RightToLeft), Allowed) .Member(nameof(Regex.IsMatch), Allowed, RegexDangerousMethodCallRewriter.Default) .Member(nameof(Regex.Match), Allowed, RegexDangerousMethodCallRewriter.Default) .Member(nameof(Regex.Matches), Allowed, RegexDangerousMethodCallRewriter.Default) .Member(nameof(Regex.Replace), Allowed, RegexDangerousMethodCallRewriter.Default, StringReturnRewriter.Default) .Member(nameof(Regex.Split), Allowed, RegexDangerousMethodCallRewriter.Default, ArrayReturnRewriter.Default) .Member(nameof(Regex.GetGroupNames), Allowed, ArrayReturnRewriter.Default) .Member(nameof(Regex.GetGroupNumbers), Allowed, ArrayReturnRewriter.Default) .Member(nameof(Regex.GroupNameFromNumber), Allowed) .Member(nameof(Regex.GroupNumberFromName), Allowed) .Member(nameof(Regex.Escape), Allowed, StringReturnRewriter.Default) .Member(nameof(Regex.Unescape), Allowed, StringReturnRewriter.Default) .Member(nameof(Regex.ToString), Allowed, StringReturnRewriter.Default) ) .Type(nameof(RegexOptions), Allowed, t => t.Member(nameof(RegexOptions.Compiled), Denied)) .Type(nameof(Match), Allowed, t => t.Member(nameof(Match.Synchronized), Denied)) .Type(nameof(MatchCollection), Allowed) .Type(nameof(MatchEvaluator), Neutral, t => t.Constructor(Allowed).Member("Invoke", Allowed)) .Type(nameof(Capture), Allowed) .Type(nameof(CaptureCollection), Allowed) .Type(nameof(Group), Allowed, t => t.Member(nameof(Group.Synchronized), Denied)) .Type(nameof(GroupCollection), Allowed); }
private static void SetupSystemRuntimeInteropServices(NamespacePolicy namespacePolicy) { namespacePolicy .Type(typeof(Marshal), Neutral, t => t.Member(nameof(Marshal.SizeOf), Allowed) ); }
private static void SetupSystem(NamespacePolicy namespacePolicy) { namespacePolicy .Type(typeof(Console), Neutral, t => t.Member(nameof(Console.Write), Allowed) .Member(nameof(Console.WriteLine), Allowed) // required by F#'s printf .Getter(nameof(Console.Out), Allowed) ) .Type(typeof(Environment), Neutral, t => t.Getter(nameof(Environment.StackTrace), Allowed, new StringReturnRewriter()) ) .Type(typeof(MemoryExtensions), Neutral, SetupSystemMemoryExtensions) .Type(typeof(ReadOnlySpan <>), Allowed, t => t.Member(nameof(ReadOnlySpan <object> .ToArray), Allowed, ArrayReturnRewriter.Default) ) .Type(typeof(ReadOnlySpan <> .Enumerator), Allowed) .Type(typeof(Span <>), Allowed, t => t.Member(nameof(Span <object> .ToArray), Allowed, ArrayReturnRewriter.Default) ) .Type(typeof(Span <> .Enumerator), Allowed) .Type(typeof(STAThreadAttribute), Allowed) .Type(typeof(NotImplementedException), Neutral, t => t.Constructor(Allowed)) .Type(typeof(Type), Neutral, SetupSystemType); }
private static void SetupThreading(NamespacePolicy namespacePolicy) { namespacePolicy .Type(typeof(Thread), Neutral, t => t .Member("get_Name", Allowed) .Member(nameof(Thread.Priority), Allowed) //.Member(nameof(Thread.CurrentCulture), Allowed) //.Member(nameof(Thread.CurrentPrincipal), Allowed) .Member("get_CurrentThread", Allowed) //TODO: not sure //.Member(nameof(Thread.ExecutionContext), Allowed) .Member(nameof(Thread.IsAlive), Allowed) .Member(nameof(Thread.IsBackground), Allowed) .Member(nameof(Thread.ThreadState), Allowed) //.Member(nameof(Thread.ManagedThreadId), Allowed) //.Member(nameof(Thread.CurrentUICulture), Allowed) //.Member(nameof(Thread.IsThreadPoolThread), Allowed) .Member(nameof(Thread.Abort), Allowed) .Member(nameof(Thread.Equals), Allowed) .Member(nameof(Thread.Interrupt), Allowed) .Member(nameof(Thread.Join), Allowed) .Member(nameof(Thread.Sleep), Allowed) .Member(nameof(Thread.Start), Allowed) .Member(nameof(Thread.Yield), Allowed) //Some not accepted between .Member(nameof(Thread.SpinWait), Allowed) ); }
private static void CompilerServicesPolicy(NamespacePolicy compilerServices) { compilerServices .Type(nameof(IteratorStateMachineAttribute), AccessPolicy.Allowed) .Type(nameof(RuntimeHelpers), AccessPolicy.Denied, t => t.Member(nameof(RuntimeHelpers.InitializeArray), AccessPolicy.Allowed) ); }
private static void SetupSystemText(NamespacePolicy namespacePolicy) { namespacePolicy .Type(typeof(Encoding), Neutral, // TODO: Move to Unbreakable t => t.Member(nameof(Encoding.GetBytes), Allowed, ArrayReturnRewriter.Default) ); }
private static void SetupMicrosoftVisualBasic(NamespacePolicy namespacePolicy) { namespacePolicy #if !NETCOREAPP .Type(nameof(Microsoft.VisualBasic.Globals), Allowed) #endif .Type(nameof(Microsoft.VisualBasic.Strings), Allowed); }
private static void SetupSystemLinq(NamespacePolicy linq) { linq .Type(nameof(Enumerable), Neutral, t => t.Member(nameof(Enumerable.Aggregate), Allowed) .Member(nameof(Enumerable.All), Allowed) .Member(nameof(Enumerable.Any), Allowed) .Member(nameof(Enumerable.AsEnumerable), Allowed) .Member(nameof(Enumerable.Average), Allowed) .Member(nameof(Enumerable.Cast), Allowed) .Member(nameof(Enumerable.Concat), Allowed) .Member(nameof(Enumerable.Contains), Allowed) .Member(nameof(Enumerable.Count), Allowed) .Member(nameof(Enumerable.DefaultIfEmpty), Allowed) .Member(nameof(Enumerable.Distinct), Allowed, CollectedEnumerableArgumentRewriter.Default) .Member(nameof(Enumerable.ElementAt), Allowed) .Member(nameof(Enumerable.ElementAtOrDefault), Allowed) .Member(nameof(Enumerable.Empty), Allowed) .Member(nameof(Enumerable.Except), Allowed, CollectedEnumerableArgumentRewriter.Default) .Member(nameof(Enumerable.First), Allowed) .Member(nameof(Enumerable.FirstOrDefault), Allowed) .Member(nameof(Enumerable.GroupBy), Allowed, CollectedEnumerableArgumentRewriter.Default) .Member(nameof(Enumerable.GroupJoin), Allowed, CollectedEnumerableArgumentRewriter.Default) .Member(nameof(Enumerable.Intersect), Allowed, CollectedEnumerableArgumentRewriter.Default) .Member(nameof(Enumerable.Join), Allowed, CollectedEnumerableArgumentRewriter.Default) .Member(nameof(Enumerable.Last), Allowed) .Member(nameof(Enumerable.LastOrDefault), Allowed) .Member(nameof(Enumerable.LongCount), Allowed) .Member(nameof(Enumerable.Max), Allowed) .Member(nameof(Enumerable.Min), Allowed) .Member(nameof(Enumerable.OfType), Allowed) .Member(nameof(Enumerable.OrderBy), Allowed, CollectedEnumerableArgumentRewriter.Default) .Member(nameof(Enumerable.OrderByDescending), Allowed, CollectedEnumerableArgumentRewriter.Default) .Member(nameof(Enumerable.Range), Allowed, CountArgumentRewriter.Default) .Member(nameof(Enumerable.Repeat), Allowed, CountArgumentRewriter.Default) .Member(nameof(Enumerable.Reverse), Allowed, CollectedEnumerableArgumentRewriter.Default) .Member(nameof(Enumerable.Select), Allowed) .Member(nameof(Enumerable.SelectMany), Allowed) .Member(nameof(Enumerable.SequenceEqual), Allowed, CollectedEnumerableArgumentRewriter.Default) .Member(nameof(Enumerable.Single), Allowed) .Member(nameof(Enumerable.SingleOrDefault), Allowed) .Member(nameof(Enumerable.Skip), Allowed) .Member(nameof(Enumerable.SkipWhile), Allowed) .Member(nameof(Enumerable.Sum), Allowed) .Member(nameof(Enumerable.Take), Allowed) .Member(nameof(Enumerable.TakeWhile), Allowed) .Member(nameof(Enumerable.ThenBy), Allowed, CollectedEnumerableArgumentRewriter.Default) .Member(nameof(Enumerable.ThenByDescending), Allowed, CollectedEnumerableArgumentRewriter.Default) .Member(nameof(Enumerable.ToArray), Allowed, CollectedEnumerableArgumentRewriter.Default) .Member(nameof(Enumerable.ToDictionary), Allowed, CollectedEnumerableArgumentRewriter.Default) .Member(nameof(Enumerable.ToList), Allowed, CollectedEnumerableArgumentRewriter.Default) .Member(nameof(Enumerable.ToLookup), Allowed, CollectedEnumerableArgumentRewriter.Default) .Member(nameof(Enumerable.Union), Allowed, CollectedEnumerableArgumentRewriter.Default) .Member(nameof(Enumerable.Where), Allowed) .Member(nameof(Enumerable.Zip), Allowed) ) .Type(typeof(IGrouping <,>), Allowed); }
//.Namespace("System.Runtime.InteropServices", Neutral, SetupSystemRuntimeInteropServices) //.Namespace("System.Web", Neutral, SetupSystemWeb); private static void SetupSystem(NamespacePolicy namespacePolicy) { namespacePolicy .Type(typeof(Console), Neutral, t => t.Member(nameof(Console.WriteLine), Allowed) ) .Type(typeof(NotImplementedException), Neutral, t => t.Constructor(Allowed)) .Type(typeof(Type), Neutral, SetupSystemType); }
private static void SetupSystemCollectionsSpecialized(NamespacePolicy namespacePolicy) { namespacePolicy.Type(typeof(NameValueCollection), Allowed, t => t.Constructor(Allowed, CountArgumentRewriter.ForCapacity) .Member(nameof(NameValueCollection.Add), Allowed, AddCallRewriter.Default) .Member(nameof(NameValueCollection.Set), Allowed, AddCallRewriter.Default) .Member("set_Item", Allowed, AddCallRewriter.Default) ); }
private static void SetupSystemCollectionsConcurrent(NamespacePolicy namespacePolicy) { namespacePolicy.Type(typeof(ConcurrentDictionary <,>), Allowed, t => t.Constructor(Allowed, CountArgumentRewriter.ForCapacity) .Member(nameof(ConcurrentDictionary <object, object> .AddOrUpdate), Allowed, AddCallRewriter.Default) .Member(nameof(ConcurrentDictionary <object, object> .GetOrAdd), Allowed, AddCallRewriter.Default) .Member(nameof(ConcurrentDictionary <object, object> .TryAdd), Allowed, AddCallRewriter.Default) ); }
private static void SetupSystemDiagnostics(NamespacePolicy diagnostics) { diagnostics .Type(nameof(DebuggerDisplayAttribute), Allowed) .Type(nameof(DebuggerHiddenAttribute), Allowed) .Type(nameof(DebuggerNonUserCodeAttribute), Allowed) .Type(nameof(DebuggerStepThroughAttribute), Allowed) .Type(nameof(Process), Denied) .Type(nameof(Stopwatch), Allowed); }
private static void SetupFSharpCore(NamespacePolicy namespacePolicy) { namespacePolicy .Type(typeof(CompilationArgumentCountsAttribute), Allowed) .Type(typeof(CompilationMappingAttribute), Allowed) .Type(typeof(CustomOperationAttribute), Allowed) .Type(typeof(EntryPointAttribute), Allowed) .Type(typeof(ExtraTopLevelOperators), Neutral, t => t.Member(nameof(ExtraTopLevelOperators.CreateDictionary), Allowed, CollectedEnumerableArgumentRewriter.Default) .Member(nameof(ExtraTopLevelOperators.CreateSet), Allowed, CollectedEnumerableArgumentRewriter.Default) .Member(nameof(ExtraTopLevelOperators.LazyPattern), Allowed) .Member(nameof(ExtraTopLevelOperators.PrintFormat), Allowed) .Member(nameof(ExtraTopLevelOperators.PrintFormatLine), Allowed) .Member(nameof(ExtraTopLevelOperators.PrintFormatToTextWriter), Allowed) .Member(nameof(ExtraTopLevelOperators.PrintFormatLineToTextWriter), Allowed) .Member(nameof(ExtraTopLevelOperators.PrintFormatToString), Allowed) .Member(nameof(ExtraTopLevelOperators.SpliceExpression), Allowed) .Member(nameof(ExtraTopLevelOperators.SpliceUntypedExpression), Allowed) .Member(nameof(ExtraTopLevelOperators.ToByte), Allowed) .Member(nameof(ExtraTopLevelOperators.ToDouble), Allowed) .Member(nameof(ExtraTopLevelOperators.ToSByte), Allowed) .Member(nameof(ExtraTopLevelOperators.ToSingle), Allowed) ) .Type(typeof(ExtraTopLevelOperators.Checked), Allowed) .Type(typeof(FSharpChoice <,>), Allowed) .Type(typeof(FSharpFunc <,>), Allowed) .Type(typeof(FSharpOption <>), Allowed) .Type(typeof(LanguagePrimitives), Neutral, t => t.Getter(nameof(LanguagePrimitives.GenericComparer), Allowed) .Getter(nameof(LanguagePrimitives.GenericEqualityComparer), Allowed) .Getter(nameof(LanguagePrimitives.GenericEqualityERComparer), Allowed) ) .Type(typeof(LanguagePrimitives.HashCompare), Allowed) .Type(typeof(OptimizedClosures.FSharpFunc <, ,>), Allowed) .Type(typeof(OptimizedClosures.FSharpFunc <, , ,>), Allowed) .Type(typeof(OptimizedClosures.FSharpFunc <, , , ,>), Allowed) .Type(typeof(Microsoft.FSharp.Core.Operators), Allowed, t => t.Member("ConsoleError", Denied) .Member("ConsoleIn", Denied) .Member("ConsoleOut", Denied) .Member("Lock", Denied) ) .Type(typeof(Microsoft.FSharp.Core.Operators.OperatorIntrinsics), Neutral, t => t.Member("RangeInt32", Allowed) ) .Type(typeof(PrintfFormat <, , ,>), Allowed) .Type(typeof(PrintfFormat <, , , ,>), Allowed) .Type(typeof(PrintfModule), Neutral, t => t.Member(nameof(PrintfModule.PrintFormat), Allowed) .Member(nameof(PrintfModule.PrintFormatLine), Allowed) .Member(nameof(PrintfModule.PrintFormatToTextWriter), Allowed) .Member(nameof(PrintfModule.PrintFormatLineToTextWriter), Allowed) ) .Type(typeof(Unit), Allowed); }
private static void SetupSystemRuntimeCompilerServices(NamespacePolicy namespacePolicy) { namespacePolicy .Type(typeof(Unsafe), Neutral, t => t.Member(nameof(Unsafe.AreSame), Allowed) .Member(nameof(Unsafe.ByteOffset), Allowed) .Member(nameof(Unsafe.SizeOf), Allowed) .Member(nameof(Unsafe.IsAddressGreaterThan), Allowed) .Member(nameof(Unsafe.IsAddressLessThan), Allowed) ); }
private static void SetupSystemRuntimeCompilerServices(NamespacePolicy compilerServices) { compilerServices .Type(nameof(CompilerGeneratedAttribute), Allowed) .Type(nameof(ExtensionAttribute), Allowed) .Type(nameof(FormattableStringFactory), Allowed) .Type(nameof(IteratorStateMachineAttribute), Allowed) .Type("IsReadOnlyAttribute", Allowed) .Type(nameof(RuntimeHelpers), Neutral, t => t.Member(nameof(RuntimeHelpers.InitializeArray), Allowed) ); }
private static void SetupSystemGlobalization(NamespacePolicy namespacePolicy) { namespacePolicy .Type(typeof(CultureInfo), Neutral, typePolicy => { typePolicy.Constructor(Allowed) .Member(nameof(CultureInfo.GetCultureInfo), Allowed) .Member(nameof(CultureInfo.GetCultureInfoByIetfLanguageTag), Allowed); foreach (var property in typeof(CultureInfo).GetProperties()) { typePolicy.Getter(property.Name, Allowed); } }); }
private static void SetupSystemCollections(NamespacePolicy collections) { collections .Type(nameof(DictionaryEntry), Allowed) .Type(nameof(ICollection), Allowed) .Type(nameof(IComparer), Allowed) .Type(nameof(IDictionary), Allowed, SetupAdd) .Type(nameof(IEqualityComparer), Allowed) .Type(nameof(IDictionaryEnumerator), Allowed) .Type(nameof(IList), Allowed, t => t.Other(SetupAdd, SetupInsert)) .Type(nameof(IEnumerable), Allowed) .Type(nameof(IEnumerator), Allowed); }
private static void SetupSystemSecurityCryptography(NamespacePolicy namespacePolicy) { ForEachTypeInNamespaceOf <HashAlgorithm>(type => { if (!type.GetTypeInfo().IsSameAsOrSubclassOf <HashAlgorithm>()) { return; } namespacePolicy.Type(type, Neutral, t => t.Constructor(Allowed, DisposableReturnRewriter.Default) .Member(nameof(HashAlgorithm.ComputeHash), Allowed, ArrayReturnRewriter.Default) ); }); }
private static void SetupSystemRuntimeCompilerServices(NamespacePolicy compilerServices) { compilerServices .Type(nameof(CompilerGeneratedAttribute), Allowed) .Type(nameof(ExtensionAttribute), Allowed) .Type(nameof(FormattableStringFactory), Allowed) .Type(nameof(IteratorStateMachineAttribute), Allowed) .Type("IsExternalInit", Allowed) .Type("IsReadOnlyAttribute", Allowed) .Type("PreserveBaseOverridesAttribute", Allowed) .Type(nameof(RuntimeHelpers), Neutral, t => t.Member(nameof(RuntimeHelpers.InitializeArray), Allowed) .Member("GetSubArray", Allowed, ArrayReturnRewriter.Default) ); }
private static void SetupSystemText(NamespacePolicy text) { text .Type(nameof(Encoding), Neutral, t => t.Getter(nameof(Encoding.ASCII), Allowed) .Getter(nameof(Encoding.BigEndianUnicode), Allowed) .Getter(nameof(Encoding.BodyName), Allowed) .Getter(nameof(Encoding.CodePage), Allowed) .Getter(nameof(Encoding.Default), Allowed) .Getter(nameof(Encoding.EncodingName), Allowed) .Getter(nameof(Encoding.IsReadOnly), Allowed) .Getter(nameof(Encoding.IsSingleByte), Allowed) .Getter("Latin1", Allowed) .Getter("Preamble", Allowed) .Getter(nameof(Encoding.Unicode), Allowed) .Getter(nameof(Encoding.UTF32), Allowed) .Getter(nameof(Encoding.UTF8), Allowed) .Getter(nameof(Encoding.WebName), Allowed) .Getter(nameof(Encoding.WindowsCodePage), Allowed) .Getter(nameof(Encoding.GetByteCount), Allowed) .Member(nameof(Encoding.GetBytes), Allowed, ArrayReturnRewriter.Default) .Member(nameof(Encoding.GetCharCount), Allowed) .Member(nameof(Encoding.GetChars), Allowed, ArrayReturnRewriter.Default) .Member(nameof(Encoding.GetEncoding), Allowed) .Member(nameof(Encoding.GetEncodings), Allowed, ArrayReturnRewriter.Default) .Member(nameof(Encoding.GetMaxByteCount), Allowed) .Member(nameof(Encoding.GetMaxCharCount), Allowed) .Member(nameof(Encoding.GetPreamble), Allowed, ArrayReturnRewriter.Default) .Member(nameof(Encoding.GetString), Allowed, StringReturnRewriter.Default) .Member(nameof(Encoding.Convert), Allowed, ArrayReturnRewriter.Default) .Member(nameof(Encoding.IsAlwaysNormalized), Allowed) ) .Type(nameof(StringBuilder), Neutral, t => t.Constructor(Allowed, CountArgumentRewriter.ForCapacity) .Member(nameof(StringBuilder.Append), Allowed, AddCallRewriter.Default, CountArgumentRewriter.Default, new CountArgumentRewriter("repeatCount")) .Member(nameof(StringBuilder.AppendFormat), Allowed, AddCallRewriter.Default) .Member(nameof(StringBuilder.AppendLine), Allowed, AddCallRewriter.Default) .Member(nameof(StringBuilder.Clear), Allowed) .Member(nameof(StringBuilder.EnsureCapacity), Allowed, CountArgumentRewriter.ForCapacity) .Member(nameof(StringBuilder.Equals), Allowed) .Getter(nameof(StringBuilder.Insert), Allowed, AddCallRewriter.Default, CountArgumentRewriter.Default) .Getter(nameof(StringBuilder.Remove), Allowed) .Getter(nameof(StringBuilder.Replace), Allowed) .Getter(nameof(StringBuilder.ToString), Allowed) .Getter(nameof(StringBuilder.Length), Allowed) .Getter(nameof(StringBuilder.MaxCapacity), Allowed) ); }
private static void SetupSystemComponentModel(NamespacePolicy componentModel) { componentModel .Type(nameof(TypeConverter), Neutral, t => t.Member(nameof(TypeConverter.CanConvertFrom), Allowed) .Member(nameof(TypeConverter.CanConvertTo), Allowed) .Member(nameof(TypeConverter.ConvertFrom), Allowed) .Member(nameof(TypeConverter.ConvertFromInvariantString), Allowed) .Member(nameof(TypeConverter.ConvertFromString), Allowed) .Member(nameof(TypeConverter.ConvertTo), Allowed) .Member(nameof(TypeConverter.ConvertToInvariantString), Allowed) .Member(nameof(TypeConverter.ConvertToString), Allowed) ) .Type(nameof(TypeDescriptor), Neutral, t => t.Member(nameof(TypeDescriptor.GetConverter), Allowed) ); }
private static void SetupSystemDiagnostics(NamespacePolicy namespacePolicy) { namespacePolicy .Type(typeof(Stopwatch), Allowed, typePolicy => { foreach (var property in typeof(Stopwatch).GetProperties()) { if (!property.Name.Contains("Elapsed")) { continue; } typePolicy.Getter(property.Name, Allowed, new WarningMemberRewriter( "Please do not rely on Stopwatch results in SharpLab.\r\n\r\n" + "There are many checks and reports added to your code before it runs,\r\n" + "so the performance might be completely unrelated to the original code." )); } }); }
private static void SetupSystemWeb(NamespacePolicy namespacePolicy) { namespacePolicy .Type(typeof(HttpServerUtility), Neutral, t => t.Member(nameof(HttpServerUtility.HtmlDecode), Allowed) .Member(nameof(HttpServerUtility.HtmlEncode), Allowed).Member(nameof(HttpServerUtility.UrlDecode), Allowed) .Member(nameof(HttpServerUtility.UrlEncode), Allowed) .Member(nameof(HttpServerUtility.UrlTokenDecode), Allowed, ArrayReturnRewriter.Default) .Member(nameof(HttpServerUtility.UrlTokenEncode), Allowed) ) .Type(typeof(HttpUtility), Neutral, t => t.Member(nameof(HttpUtility.HtmlDecode), Allowed) .Member(nameof(HttpUtility.HtmlEncode), Allowed) .Member(nameof(HttpUtility.UrlDecode), Allowed) .Member(nameof(HttpUtility.UrlEncode), Allowed) .Member(nameof(HttpUtility.HtmlAttributeEncode), Allowed) .Member(nameof(HttpUtility.JavaScriptStringEncode), Allowed) .Member(nameof(HttpUtility.ParseQueryString), Allowed) ); }
private static void SetupSystem(NamespacePolicy namespacePolicy) { namespacePolicy .Type(typeof(Console), Neutral, t => t.Member(nameof(Console.Write), Allowed) .Member(nameof(Console.WriteLine), Allowed) // required by F#'s printf .Getter(nameof(Console.Out), Allowed) ) .Type(typeof(ReadOnlySpan <>), Allowed, t => t.Member(nameof(ReadOnlySpan <object> .DangerousCreate), Denied) ) .Type(typeof(ReadOnlySpan <> .Enumerator), Allowed) .Type(typeof(Span <>), Allowed, t => t.Member(nameof(ReadOnlySpan <object> .DangerousCreate), Denied) ) .Type(typeof(Span <> .Enumerator), Allowed) .Type(typeof(STAThreadAttribute), Allowed) .Type(typeof(NotImplementedException), Neutral, t => t.Constructor(Allowed)) .Type(typeof(Type), Neutral, SetupSystemType); }
private static void SetupSystemIO(NamespacePolicy namespacePolicy) { namespacePolicy // required by F#'s printf .Type(typeof(TextWriter), Neutral) .Type(typeof(TextReader), Neutral, t => t.Member(nameof(TextReader.Dispose), Allowed) .Member(nameof(TextReader.Close), Allowed) .Member(nameof(TextReader.Peek), Allowed) .Member(nameof(TextReader.ReadBlock), Allowed) .Member(nameof(TextReader.ReadLine), Allowed, StringReturnRewriter.Default) .Member(nameof(TextReader.ReadToEnd), Allowed, StringReturnRewriter.Default) ) .Type(typeof(StringReader), Neutral, t => t.Constructor(Allowed) .Member(nameof(StringReader.Close), Allowed) .Member(nameof(StringReader.Peek), Allowed) .Member(nameof(StringReader.Read), Allowed) .Member(nameof(StringReader.ReadLine), Allowed, StringReturnRewriter.Default) .Member(nameof(StringReader.ReadToEnd), Allowed, StringReturnRewriter.Default) ); }