コード例 #1
0
ファイル: InteropManager.cs プロジェクト: Nezz/SharpDX
        public InteropMethodSignature Add(InteropMethodSignature method)
        {
            method.Index = Methods.Count;
            int indexOf = Methods.IndexOf(method);
            if (indexOf>=0)
                return Methods[indexOf];

            Methods.Add(method);
            return method;
        }
コード例 #2
0
ファイル: InteropManager.cs プロジェクト: oeoen/SharpDX
        public InteropMethodSignature Add(InteropMethodSignature method)
        {
            method.Index = Methods.Count;
            int indexOf = Methods.IndexOf(method);

            if (indexOf >= 0)
            {
                return(Methods[indexOf]);
            }

            Methods.Add(method);
            return(method);
        }
コード例 #3
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            InteropMethodSignature against = obj as InteropMethodSignature;

            if (against == null)
            {
                return(false);
            }
            if (this.ReturnType != against.ReturnType)
            {
                return(false);
            }
            if (this.IsFunction != against.IsFunction)
            {
                return(false);
            }
            if (this.ParameterTypes.Count != against.ParameterTypes.Count)
            {
                return(false);
            }
            if (this.IsLocal != against.IsLocal)
            {
                return(false);
            }

            for (int i = 0; i < ParameterTypes.Count; i++)
            {
                if (ParameterTypes[i] != against.ParameterTypes[i])
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #4
0
        /// <summary>
        /// Registers the native interop signature.
        /// </summary>
        /// <param name="csMethod">The cs method.</param>
        private void RegisterNativeInteropSignature(CsMethod csMethod)
        {
            // Tag if the method is a function
            var cSharpInteropCalliSignature = new InteropMethodSignature { IsFunction = (csMethod is CsFunction) };

            // Handle Return Type parameter
            // MarshalType.Type == null, then check that it is a structure
            if (csMethod.ReturnType.PublicType is CsStruct || csMethod.ReturnType.PublicType is CsEnum)
            {
                // Return type and 1st parameter are implicitly a pointer to the structure to fill 
                if (csMethod.IsReturnStructLarge)
                {
                    cSharpInteropCalliSignature.ReturnType = typeof(void*);
                    cSharpInteropCalliSignature.ParameterTypes.Add(typeof(void*));
                }
                else
                {
                    // Patch for Mono bug with structs marshalling and calli. TEMPORARY
                    var returnQualifiedName = csMethod.ReturnType.PublicType.QualifiedName;
                    if (returnQualifiedName == "SharpDX.Result")
                        cSharpInteropCalliSignature.ReturnType = typeof (int);
                    else if (returnQualifiedName == "SharpDX.PointerSize" || returnQualifiedName == "SharpDX.Direct3D9.EffectHandle")
                        cSharpInteropCalliSignature.ReturnType = typeof(void*);
                    else
                        cSharpInteropCalliSignature.ReturnType = csMethod.ReturnType.PublicType.QualifiedName;
                }
            }
            else if (csMethod.ReturnType.MarshalType.Type != null)
            {
                Type type = csMethod.ReturnType.MarshalType.Type;
                //if (type == typeof(IntPtr))
                //    type = typeof(void*);
                cSharpInteropCalliSignature.ReturnType = type;
            }
            else
            {
                throw new ArgumentException(string.Format(System.Globalization.CultureInfo.InvariantCulture, "Invalid return type {0} for method {1}", csMethod.ReturnType.PublicType.QualifiedName, csMethod.CppElement));
            }

            // Handle Parameters
            foreach (var param in csMethod.Parameters)
            {
                InteropType interopType;
                string publicName = param.PublicType.QualifiedName;
                // Patch for Mono bug with structs marshalling and calli. TEMPORARY
                if (publicName == "SharpDX.PointerSize" || param.PublicType.QualifiedName == "SharpDX.Direct3D9.EffectHandle")
                {
                    interopType = typeof(void*);
                }
                else if (param.MarshalType.Type == null)
                {
                    if (param.PublicType is CsStruct)
                    {
                        // If parameter is a struct, then a LocalInterop is needed
                        interopType = param.PublicType.QualifiedName;
                        cSharpInteropCalliSignature.IsLocal = true;
                    }
                    else
                    {
                        throw new ArgumentException(string.Format(System.Globalization.CultureInfo.InvariantCulture, "Invalid parameter {0} for method {1}", param.PublicType.QualifiedName, csMethod.CppElement));
                    }
                }
                else
                {
                    Type type = param.MarshalType.Type;
                    // Patch for Mono bug with structs marshalling and calli. TEMPORARY
                    if (type == typeof(IntPtr))
                        type = typeof(void*);
                    interopType = type;
                }

                cSharpInteropCalliSignature.ParameterTypes.Add(interopType);
            }

            var assembly = csMethod.GetParent<CsAssembly>();
            cSharpInteropCalliSignature = assembly.Interop.Add(cSharpInteropCalliSignature);

            csMethod.Interop = cSharpInteropCalliSignature;
        }
コード例 #5
0
 public InteropMethodSignature Add(InteropMethodSignature method)
 {
     methods.Add(method);
     return(methods.First(mthd => mthd.Equals(method)));
 }