Skip to content

Commit

Permalink
Use .net standard 2.0 APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
jbevain committed Feb 11, 2019
1 parent cbec1fa commit bde4fd3
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 199 deletions.
2 changes: 1 addition & 1 deletion Mono.Cecil.Cil/Symbols.cs
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ static SR.AssemblyName GetSymbolAssemblyName (SymbolKind kind)

var suffix = GetSymbolNamespace (kind);

var cecil_name = typeof (SymbolProvider).Assembly ().GetName ();
var cecil_name = typeof (SymbolProvider).Assembly.GetName ();

var name = new SR.AssemblyName {
Name = cecil_name.Name + "." + suffix,
Expand Down
8 changes: 2 additions & 6 deletions Mono.Cecil/AssemblyWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,10 @@ static void Write (ModuleDefinition module, Disposable<Stream> stream, WriterPar
if (symbol_writer_provider == null && parameters.WriteSymbols)
symbol_writer_provider = new DefaultSymbolWriterProvider ();

#if !NET_CORE
if (parameters.StrongNameKeyPair != null && name != null) {
name.PublicKey = parameters.StrongNameKeyPair.PublicKey;
module.Attributes |= ModuleAttributes.StrongNameSigned;
}
#endif

var metadata = new MetadataBuilder (module, fq_name, timestamp, symbol_writer_provider);
try {
Expand All @@ -122,10 +120,8 @@ static void Write (ModuleDefinition module, Disposable<Stream> stream, WriterPar
stream.value.SetLength (0);
writer.WriteImage ();

#if !NET_CORE
if (parameters.StrongNameKeyPair != null)
CryptoService.StrongName (stream.value, writer, parameters.StrongNameKeyPair);
#endif
}
} finally {
module.metadata_builder = null;
Expand Down Expand Up @@ -1917,7 +1913,7 @@ static ElementType GetConstantType (TypeReference constant_type, object constant

static ElementType GetConstantType (Type type)
{
switch (type.GetTypeCode ()) {
switch (Type.GetTypeCode(type)) {
case TypeCode.Boolean:
return ElementType.Boolean;
case TypeCode.Byte:
Expand Down Expand Up @@ -2977,7 +2973,7 @@ void WritePrimitiveValue (object value)
if (value == null)
throw new ArgumentNullException ();

switch (value.GetType ().GetTypeCode ()) {
switch (Type.GetTypeCode(value.GetType ())) {
case TypeCode.Boolean:
WriteByte ((byte) (((bool) value) ? 1 : 0));
break;
Expand Down
9 changes: 3 additions & 6 deletions Mono.Cecil/BaseAssemblyResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,7 @@ AssemblyDefinition SearchTrustedPlatformAssemblies (AssemblyNameReference name,
string paths;

try {
// AppContext is only available on platforms that implement .NET Standard 1.6
var appContextType = Type.GetType ("System.AppContext, System.AppContext, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", throwOnError: false);
var getData = appContextType?.GetTypeInfo ().GetDeclaredMethod ("GetData");
paths = (string) getData?.Invoke (null, new [] { "TRUSTED_PLATFORM_ASSEMBLIES" });
paths = (string) AppDomain.CurrentDomain.GetData ("TRUSTED_PLATFORM_ASSEMBLIES");
} catch {
paths = null;
}
Expand Down Expand Up @@ -380,7 +377,7 @@ AssemblyDefinition GetAssemblyInNetGac (AssemblyNameReference reference, ReaderP

return null;
}
#endif

static string GetAssemblyFile (AssemblyNameReference reference, string prefix, string gac)
{
var gac_folder = new StringBuilder ()
Expand All @@ -396,7 +393,7 @@ static string GetAssemblyFile (AssemblyNameReference reference, string prefix, s
Path.Combine (gac, reference.Name), gac_folder.ToString ()),
reference.Name + ".dll");
}

#endif
public void Dispose ()
{
Dispose (true);
Expand Down
26 changes: 8 additions & 18 deletions Mono.Cecil/Import.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ TypeReference ImportType (Type type, ImportGenericContext context, ImportGeneric
type.Name,
module,
ImportScope (type),
type.IsValueType ());
type.IsValueType);

reference.etype = ImportElementType (type);

Expand All @@ -187,20 +187,20 @@ TypeReference ImportType (Type type, ImportGenericContext context, ImportGeneric
else
reference.Namespace = type.Namespace ?? string.Empty;

if (type.IsGenericType ())
if (type.IsGenericType)
ImportGenericParameters (reference, type.GetGenericArguments ());

return reference;
}

protected virtual IMetadataScope ImportScope (Type type)
{
return ImportScope (type.Assembly ());
return ImportScope (type.Assembly);
}

static bool ImportOpenGenericType (Type type, ImportGenericKind import_kind)
{
return type.IsGenericType () && type.IsGenericTypeDefinition () && import_kind == ImportGenericKind.Open;
return type.IsGenericType && type.IsGenericTypeDefinition && import_kind == ImportGenericKind.Open;
}

static bool ImportOpenGenericMethod (SR.MethodBase method, ImportGenericKind import_kind)
Expand All @@ -224,7 +224,7 @@ TypeReference ImportTypeSpecification (Type type, ImportGenericContext context)
if (type.IsArray)
return new ArrayType (ImportType (type.GetElementType (), context), type.GetArrayRank ());

if (type.IsGenericType ())
if (type.IsGenericType)
return ImportGenericInstance (type, context);

if (type.IsGenericParameter)
Expand All @@ -238,8 +238,8 @@ static TypeReference ImportGenericParameter (Type type, ImportGenericContext con
if (context.IsEmpty)
throw new InvalidOperationException ();

if (type.DeclaringMethod () != null)
return context.MethodParameter (NormalizeMethodName (type.DeclaringMethod ()), type.GenericParameterPosition);
if (type.DeclaringMethod != null)
return context.MethodParameter (NormalizeMethodName (type.DeclaringMethod), type.GenericParameterPosition);

if (type.DeclaringType != null)
return context.TypeParameter (NormalizeTypeFullName (type.DeclaringType), type.GenericParameterPosition);
Expand Down Expand Up @@ -287,7 +287,7 @@ static bool IsTypeSpecification (Type type)

static bool IsGenericInstance (Type type)
{
return type.IsGenericType () && !type.IsGenericTypeDefinition ();
return type.IsGenericType && !type.IsGenericTypeDefinition;
}

static ElementType ImportElementType (Type type)
Expand Down Expand Up @@ -315,10 +315,8 @@ public virtual AssemblyNameReference ImportReference (SR.AssemblyName name)
reference = new AssemblyNameReference (name.Name, name.Version)
{
PublicKeyToken = name.GetPublicKeyToken (),
#if !NET_CORE
Culture = name.CultureInfo.Name,
HashAlgorithm = (AssemblyHashAlgorithm) name.HashAlgorithm,
#endif
};

module.AssemblyReferences.Add (reference);
Expand Down Expand Up @@ -364,20 +362,12 @@ FieldReference ImportField (SR.FieldInfo field, ImportGenericContext context)

static SR.FieldInfo ResolveFieldDefinition (SR.FieldInfo field)
{
#if NET_CORE
throw new NotImplementedException ();
#else
return field.Module.ResolveField (field.MetadataToken);
#endif
}

static SR.MethodBase ResolveMethodDefinition (SR.MethodBase method)
{
#if NET_CORE
throw new NotImplementedException ();
#else
return method.Module.ResolveMethod (method.MetadataToken);
#endif
}

MethodReference ImportMethod (SR.MethodBase method, ImportGenericContext context, ImportGenericKind import_kind)
Expand Down
22 changes: 0 additions & 22 deletions Mono.Cecil/ModuleDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,25 +183,7 @@ public ModuleParameters ()

static TargetRuntime GetCurrentRuntime ()
{
#if !NET_CORE
return typeof (object).Assembly.ImageRuntimeVersion.ParseRuntime ();
#else
var corlib_name = AssemblyNameReference.Parse (typeof (object).Assembly ().FullName);
var corlib_version = corlib_name.Version;

switch (corlib_version.Major) {
case 1:
return corlib_version.Minor == 0
? TargetRuntime.Net_1_0
: TargetRuntime.Net_1_1;
case 2:
return TargetRuntime.Net_2_0;
case 4:
return TargetRuntime.Net_4_0;
default:
throw new NotSupportedException ();
}
#endif
}
}

Expand All @@ -211,9 +193,7 @@ public sealed class WriterParameters {
Stream symbol_stream;
ISymbolWriterProvider symbol_writer_provider;
bool write_symbols;
#if !NET_CORE
SR.StrongNameKeyPair key_pair;
#endif

public uint? Timestamp {
get { return timestamp; }
Expand All @@ -235,12 +215,10 @@ public sealed class WriterParameters {
set { write_symbols = value; }
}

#if !NET_CORE
public SR.StrongNameKeyPair StrongNameKeyPair {
get { return key_pair; }
set { key_pair = value; }
}
#endif
}

#endif
Expand Down
5 changes: 0 additions & 5 deletions Mono.Security.Cryptography/CryptoConvert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

#if !READ_ONLY

#if !NET_CORE

using System;
using System.Security.Cryptography;

Expand Down Expand Up @@ -248,6 +246,3 @@ static public RSA FromCapiKeyBlob (byte[] blob, int offset)
}

#endif

#endif

4 changes: 0 additions & 4 deletions Mono.Security.Cryptography/CryptoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

#if !READ_ONLY

#if !NET_CORE

using System;
using System.IO;
using System.Reflection;
Expand Down Expand Up @@ -154,5 +152,3 @@ static bool TryGetKeyContainer (ISerializable key_pair, out byte [] key, out str
}

#endif

#endif
137 changes: 0 additions & 137 deletions Mono/Type.cs

This file was deleted.

0 comments on commit bde4fd3

Please sign in to comment.