static string GetCanonicalLocale(UTF8String locale) => GetCanonicalLocale(UTF8String.ToSystemStringOrEmpty(locale));
void Add(UTF8String a) { }
/// <summary> /// Gets the hash code of a locale /// </summary> /// <param name="a">Value</param> /// <returns>The hash code</returns> internal static int GetHashCodeLocale(UTF8String a) => GetCanonicalLocale(a).GetHashCode();
/// <summary> /// Compares two locales (cultures) /// </summary> /// <param name="a">First</param> /// <param name="b">Second</param> /// <returns><c>true</c> if same, <c>false</c> otherwise</returns> internal static bool LocaleEquals(UTF8String a, string b) => LocaleCompareTo(a, b) == 0;
/// <summary> /// Compares two locales (cultures) /// </summary> /// <param name="a">First</param> /// <param name="b">Second</param> /// <returns>< 0 if a < b, 0 if a == b, > 0 if a > b</returns> internal static int LocaleCompareTo(UTF8String a, string b) => GetCanonicalLocale(a).CompareTo(GetCanonicalLocale(b));
/// <summary> /// Returns an assembly name string /// </summary> /// <param name="name">Simple assembly name</param> /// <param name="version">Version or <c>null</c></param> /// <param name="culture">Culture or <c>null</c></param> /// <param name="publicKey">Public key / public key token or <c>null</c></param> /// <param name="attributes">Assembly attributes</param> /// <returns>An assembly name string</returns> internal static string GetAssemblyNameString(UTF8String name, Version version, UTF8String culture, PublicKeyBase publicKey, AssemblyAttributes attributes) { var sb = new StringBuilder(); foreach (var c in UTF8String.ToSystemStringOrEmpty(name)) { if (c == ',' || c == '=') { sb.Append('\\'); } sb.Append(c); } if (version != null) { sb.Append(", Version="); sb.Append(CreateVersionWithNoUndefinedValues(version).ToString()); } if ((object)culture != null) { sb.Append(", Culture="); sb.Append(UTF8String.IsNullOrEmpty(culture) ? "neutral" : culture.String); } sb.Append(", "); sb.Append(publicKey == null || publicKey is PublicKeyToken ? "PublicKeyToken=" : "PublicKey="); sb.Append(publicKey == null ? "null" : publicKey.ToString()); if ((attributes & AssemblyAttributes.Retargetable) != 0) { sb.Append(", Retargetable=Yes"); } if ((attributes & AssemblyAttributes.ContentType_Mask) == AssemblyAttributes.ContentType_WindowsRuntime) { sb.Append(", ContentType=WindowsRuntime"); } return(sb.ToString()); }
MarshalType Read() { MarshalType returnValue; try { var nativeType = (NativeType)reader.ReadByte(); NativeType nt; int size; switch (nativeType) { case NativeType.FixedSysString: size = CanRead() ? (int)reader.ReadCompressedUInt32() : -1; returnValue = new FixedSysStringMarshalType(size); break; case NativeType.SafeArray: var vt = CanRead() ? (VariantType)reader.ReadCompressedUInt32() : VariantType.NotInitialized; var udtName = CanRead() ? ReadUTF8String() : null; var udtRef = (object)udtName == null ? null : TypeNameParser.ParseReflection(module, UTF8String.ToSystemStringOrEmpty(udtName), null, gpContext); returnValue = new SafeArrayMarshalType(vt, udtRef); break; case NativeType.FixedArray: size = CanRead() ? (int)reader.ReadCompressedUInt32() : -1; nt = CanRead() ? (NativeType)reader.ReadCompressedUInt32() : NativeType.NotInitialized; returnValue = new FixedArrayMarshalType(size, nt); break; case NativeType.Array: nt = CanRead() ? (NativeType)reader.ReadCompressedUInt32() : NativeType.NotInitialized; int paramNum = CanRead() ? (int)reader.ReadCompressedUInt32() : -1; size = CanRead() ? (int)reader.ReadCompressedUInt32() : -1; int flags = CanRead() ? (int)reader.ReadCompressedUInt32() : -1; returnValue = new ArrayMarshalType(nt, paramNum, size, flags); break; case NativeType.CustomMarshaler: var guid = ReadUTF8String(); var nativeTypeName = ReadUTF8String(); var custMarshalerName = ReadUTF8String(); var cmRef = custMarshalerName.DataLength == 0 ? null : TypeNameParser.ParseReflection(module, UTF8String.ToSystemStringOrEmpty(custMarshalerName), new CAAssemblyRefFinder(module), gpContext); var cookie = ReadUTF8String(); returnValue = new CustomMarshalType(guid, nativeTypeName, cmRef, cookie); break; case NativeType.IUnknown: case NativeType.IDispatch: case NativeType.IntF: int iidParamIndex = CanRead() ? (int)reader.ReadCompressedUInt32() : -1; return(new InterfaceMarshalType(nativeType, iidParamIndex)); default: returnValue = new MarshalType(nativeType); break; } } catch { returnValue = new RawMarshalType(reader.ToArray()); } return(returnValue); }