Ejemplo n.º 1
0
 public override int GetHashCode() =>
 // Don't use IsValueType
 UTF8String.GetHashCode(Namespace) ^ UTF8String.GetHashCode(Name);
Ejemplo n.º 2
0
 public ClassName(string ns, string name, bool isValueType = false)
 {
     Namespace   = ns;
     Name        = name;
     IsValueType = isValueType;
 }
Ejemplo n.º 3
0
 public bool Equals(ClassName other) =>
 // Don't check IsValueType
 UTF8String.Equals(Namespace, other.Namespace) && UTF8String.Equals(Name, other.Name);
        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  = udtName is 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);
        }
Ejemplo n.º 5
0
        static Info?GetInfo(TypeDef td)
        {
            if (td is null)
            {
                return(null);
            }
            if (td.IsWindowsRuntime)
            {
                return(null);
            }

            UTF8String scope = null, identifier = null;
            var        tia = td.CustomAttributes.Find("System.Runtime.InteropServices.TypeIdentifierAttribute");

            if (tia is not null)
            {
                if (tia.ConstructorArguments.Count >= 2)
                {
                    if (tia.ConstructorArguments[0].Type.GetElementType() != ElementType.String)
                    {
                        return(null);
                    }
                    if (tia.ConstructorArguments[1].Type.GetElementType() != ElementType.String)
                    {
                        return(null);
                    }
                    scope      = tia.ConstructorArguments[0].Value as UTF8String ?? tia.ConstructorArguments[0].Value as string;
                    identifier = tia.ConstructorArguments[1].Value as UTF8String ?? tia.ConstructorArguments[1].Value as string;
                }
            }
            else
            {
                var asm = td.Module?.Assembly;
                if (asm is null)
                {
                    return(null);
                }
                bool isTypeLib = asm.CustomAttributes.IsDefined("System.Runtime.InteropServices.ImportedFromTypeLibAttribute") ||
                                 asm.CustomAttributes.IsDefined("System.Runtime.InteropServices.PrimaryInteropAssemblyAttribute");
                if (!isTypeLib)
                {
                    return(null);
                }
            }

            if (UTF8String.IsNull(identifier))
            {
                CustomAttribute gca;
                if (td.IsInterface && td.IsImport)
                {
                    gca = td.CustomAttributes.Find("System.Runtime.InteropServices.GuidAttribute");
                }
                else
                {
                    var asm = td.Module?.Assembly;
                    if (asm is null)
                    {
                        return(null);
                    }
                    gca = asm.CustomAttributes.Find("System.Runtime.InteropServices.GuidAttribute");
                }
                if (gca is null)
                {
                    return(null);
                }
                if (gca.ConstructorArguments.Count < 1)
                {
                    return(null);
                }
                if (gca.ConstructorArguments[0].Type.GetElementType() != ElementType.String)
                {
                    return(null);
                }
                scope = gca.ConstructorArguments[0].Value as UTF8String ?? gca.ConstructorArguments[0].Value as string;
                var ns   = td.Namespace;
                var name = td.Name;
                if (UTF8String.IsNullOrEmpty(ns))
                {
                    identifier = name;
                }
                else if (UTF8String.IsNullOrEmpty(name))
                {
                    identifier = new UTF8String(Concat(ns.Data, (byte)'.', Array2.Empty <byte>()));
                }
                else
                {
                    identifier = new UTF8String(Concat(ns.Data, (byte)'.', name.Data));
                }
            }
            return(new Info(scope, identifier));
        }
Ejemplo n.º 6
0
 public bool Equals(Info other) => stricmp(Scope, other.Scope) && UTF8String.Equals(Identifier, other.Identifier);
Ejemplo n.º 7
0
 public Info(UTF8String scope, UTF8String identifier)
 {
     Scope      = scope;
     Identifier = identifier;
 }
Ejemplo n.º 8
0
 void Add(UTF8String a)
 {
 }