Exemplo n.º 1
0
        public MethodDeclaration(MethodDesc method, BaseTypeDeclaration container, AccessModifierType accessModifier, bool isNew = false, TextBlock code = null, string nameOverride = null)
            : base(container, 0)
        {
            string additionalModifier = (accessModifier == AccessModifierType.Empty ? "" : " ") + ((method.Dll != null) ? "static extern " : "") + "unsafe " + (isNew ? "new " : "");

            if (code == null)
            {
                if (method.Dll != null)
                    WriteLine(() => "[DllImport(\"" + method.Dll + "\", EntryPoint = \"" + method.EntryPoint + "\", CallingConvention = CallingConvention." + method.Convention.ToString() + ", CharSet = CharSet.Unicode, SetLastError = true)]");
                else
                    WriteLine(() => "[PreserveSig]");
            }

            WriteLine(() => accessModifier + additionalModifier + GetReturnValue(method) + " " + ((nameOverride == null) ? method.Name : nameOverride) + "(" + GetParameters(method) + ")" + ((code == null) ? ";" : ""));
            if (code != null)
                AddTextBlock(code);
        }
Exemplo n.º 2
0
 public static string GetReturnValue(MethodDesc method)
 {
     return GetParameterTypeDeclaration(method.ReturnValue);
 }
Exemplo n.º 3
0
 public static string GetParameters(MethodDesc method)
 {
     return string.Join(", ", method.Parameters.Select(x => GetParameterTypeDeclaration(x) + " " + x.Name + (x.HasValue ? (" = " + GetValueInitializer(x)) : "")));
 }
Exemplo n.º 4
0
 public static IEnumerable<string> GetParameterNames(MethodDesc method)
 {
     return method.Parameters.Select(x => x.Name);
 }
Exemplo n.º 5
0
 public DelegateDeclaration(TypeDesc type, TextBlock container, AccessModifierType accessModifier)
     : base(new TypeDesc("void"), container, accessModifier)
 {
     this.method = type.Methods.Single(x => x.Name == type.Name);
     prefix = "_";
 }
Exemplo n.º 6
0
 public DelegateDeclaration(MethodDesc method, TextBlock container, AccessModifierType accessModifier)
     : base(new TypeDesc("void"), container, accessModifier)
 {
     this.method = method;
 }
            public DelegateCaller(MethodDesc method, DelegateWrapperDeclaration container)
                : base(container, 0)
            {
                DelegateDeclaration delegateDeclaration = new DelegateDeclaration(container.Type, container, container.AccessModifier);

                string returnDecl = MethodDeclaration.GetReturnValue(method);
                IEnumerable<string> argumentNames = MethodDeclaration.GetParameterNames(method);

                WriteLine(() => "{");
                WriteLine(() => "    if (reference == IntPtr.Zero)");
                WriteLine(() => "        throw new InvalidComObjectException();");
                WriteLine(() => "    Delegate genericDelegate = Marshal.GetDelegateForFunctionPointer(reference, typeof(" + delegateDeclaration.DelegateTypeName + "));");
                WriteLine(() => "    " + delegateDeclaration.DelegateTypeName + " method = (" + delegateDeclaration.DelegateTypeName + ")genericDelegate;");
                WriteLine(() => "    " + ((returnDecl == "void") ? "" : "return ") + "method(" + string.Join(", ", argumentNames) + ");");
                WriteLine(() => "}");
            }
            public DelegateCaller(int index, MethodDesc method, InterfaceWrapperDeclaration container)
                : base(container, 0)
            {
                string delegateName = container.GetDelegateName(index);
                string vtblMethodName = container.GetMethodName(index);

                string returnDecl = MethodDeclaration.GetReturnValue(method);
                IEnumerable<string> argumentNames = MethodDeclaration.GetParameterNames(method);

                WriteLine(() => "{");
                WriteLine(() => "    " + container.vtbl.TypeName + "** @this = (" + container.vtbl.TypeName + "**)reference;");
                WriteLine(() => "    " + container.vtbl.TypeName + "* vtbl = *@this;");
                WriteLine(() => "    if (vtbl == null)");
                WriteLine(() => "        throw new InvalidComObjectException();");
                WriteLine(() => "    Delegate genericDelegate = Marshal.GetDelegateForFunctionPointer(vtbl->" + vtblMethodName + ", typeof(" + delegateName + "));");
                WriteLine(() => "    " + delegateName + " method = (" + delegateName + ")genericDelegate;");
                WriteLine(() => "    " + ((returnDecl == "void") ? "" : "return ") + "method(" + string.Join(", ", new string[] { "@this" }.Union(argumentNames)) + ");");
                WriteLine(() => "}");
            }
Exemplo n.º 9
0
        private static bool IsInherited(MethodDesc method, TypeDesc type)
        {
            string[] array1 = new string[] { method.Name, method.ReturnValue.TypeDeclaration }.Union(method.Parameters.Select(x => x.TypeDeclaration)).ToArray();

            foreach (MethodDesc currentMethod in type.Methods)
            {
                string[] array2 = new string[] { currentMethod.Name, currentMethod.ReturnValue.TypeDeclaration }.Union(currentMethod.Parameters.Select(x => x.TypeDeclaration)).ToArray();

                if (array1.SequenceEqual(array2))
                    return false;
            }
            return true;
        }