/// <summary> /// Gets the code for declaring the specified model as a parameter to a managed method. /// </summary> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetFormalParameterCode(ParameterModel model) { if (model.Flags.HasFlag(ParameterModelFlags.IsOutput)) return string.Format("out {0} {1}", model.Type.Name, model.Name); else return string.Format("{0} {1}", model.Type.Name, model.Name); }
/// <summary> /// Gets the code for passing the specified model as parameter to a trampoline method. /// </summary> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetTrampolineParameterCode(ParameterModel model) { if (model.Flags.HasFlag(ParameterModelFlags.IsOutput)) return string.Format("ref {0}", model.Name); else return string.Format("{0}", model.Name); }
/// <summary> /// Gets the code for setup of local variables related to the specified parameter. /// </summary> /// <param name="marshaller">The marshalling service interface.</param> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetLocalVariableSetupCode(MarshallingService marshaller, ParameterModel model) { if (model.Flags.HasFlag(ParameterModelFlags.IsOutput)) return string.Empty; var builder = new StringBuilder(); switch (marshaller.ResolveBehavior(model.Type)) { case MarshalBehavior.Structure: builder.AppendLine(string.Format("{0}Marshaller* _{1} = stackalloc {0}Marshaller[{1}.Length];", model.Type.Name, model.Name)); builder.AppendLine(string.Format("for(int i = 0; i < {0}.Length; ++i)", model.Name)); builder.AppendLine(string.Format("\t_{0}[i] = {1}.ToMarshaller({0}[i]);", model.Name, model.Type.Name)); break; case MarshalBehavior.Interface: builder.AppendLine(string.Format("System.IntPtr* _{1} = stackalloc System.IntPtr[{1}.Length];", model.Type.Name, model.Name)); builder.AppendLine(string.Format("for(int i = 0; i < {0}.Length; ++i)", model.Name)); builder.AppendLine(string.Format("\t_{0}[i] = {0}[i].NativePointer;", model.Name, model.Type.Name)); break; default: builder.AppendLine(string.Format("{0}* _{1} = stackalloc {0}[{1}.Length];", model.Type.Name, model.Name)); builder.AppendLine(string.Format("for(int i = 0; i < {0}.Length; ++i)", model.Name)); builder.AppendLine(string.Format("\t_{0}[i] = {0}[i];", model.Name, model.Type.Name)); break; } return builder.ToString(); }
/// <summary> /// Gets the code for declaring the specified model as a parameter to a managed method. /// </summary> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetFormalParameterCode(ParameterModel model) { if (model.Flags.HasFlag(ParameterModelFlags.IsOutput)) return string.Format("out System.IntPtr {0}", model.Name); else return string.Format("System.IntPtr {0}", model.Name); }
/// <summary> /// Gets the code for cleanup of local variables related to the specified parameter. /// </summary> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetLocalVariableCleanupCode(ParameterModel model) { if (model.Flags.HasFlag(ParameterModelFlags.IsOutput)) { return(string.Format("{0} = {1}.FromMarshaller(_{0});", model.Name, model.Type.Name)); } return(string.Format("_{0}.Release();", model.Name)); }
/// <summary> /// Gets the code for setup of local variables related to the specified parameter. /// </summary> /// <param name="marshaller">The marshalling service interface.</param> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetLocalVariableSetupCode(MarshallingService marshaller, ParameterModel model) { if (model.Flags.HasFlag(ParameterModelFlags.IsOutput)) { return(string.Format("{0}Marshaller _{1} = default({0}Marshaller);", model.Type.Name, model.Name)); } return(string.Format("{0}Marshaller _{1} = {0}.ToMarshaller({1});", model.Type.Name, model.Name)); }
/// <summary> /// Gets the code for passing the specified model as parameter to a trampoline method. /// </summary> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetTrampolineParameterCode(ParameterModel model) { if (model.Flags.HasFlag(ParameterModelFlags.IsOutput)) { return(string.Format("ref _{0}", model.Name)); } return(string.Format("{0} != null ? {0}.NativePointer : System.IntPtr.Zero", model.Name)); }
/// <summary> /// Gets the code for declaring the specified model as a parameter to a managed method. /// </summary> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetFormalParameterCode(ParameterModel model) { if (model.Flags.HasFlag(ParameterModelFlags.IsOutput)) { return(string.Format("out {0} {1}", model.Type.Name, model.Name)); } return(string.Format("{0} {1}", model.Type.Name, model.Name)); }
/// <summary> /// Gets the code for passing the specified model as parameter to a trampoline method. /// </summary> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetTrampolineParameterCode(ParameterModel model) { if (model.Flags.HasFlag(ParameterModelFlags.IsOutput)) { return("System.IntPtr.Zero"); } return(string.Format("new System.IntPtr(_{0})", model.Name)); }
/// <summary> /// Gets the code for setup of local variables related to the specified parameter. /// </summary> /// <param name="marshaller">The marshalling service interface.</param> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetLocalVariableSetupCode(MarshallingService marshaller, ParameterModel model) { if (model.Flags.HasFlag(ParameterModelFlags.IsOutput)) { return(string.Format("System.IntPtr _{0} = default(System.IntPtr);", model.Name)); } return(string.Empty); }
/// <summary> /// Gets the code for cleanup of local variables related to the specified parameter. /// </summary> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetLocalVariableCleanupCode(ParameterModel model) { if (model.Flags.HasFlag(ParameterModelFlags.IsOutput)) { return(string.Format("{0} = _{0};", model.Name)); } return(string.Empty); }
/// <summary> /// Gets the code for declaring the specified model as a parameter to a managed method. /// </summary> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetFormalParameterCode(ParameterModel model) { if (model.Flags.HasFlag(ParameterModelFlags.IsOutput)) { return(string.Format("out System.IntPtr {0}", model.Name)); } else { return(string.Format("System.IntPtr {0}", model.Name)); } }
/// <summary> /// Gets the code for passing the specified model as parameter to a trampoline method. /// </summary> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetTrampolineParameterCode(ParameterModel model) { if (model.Flags.HasFlag(ParameterModelFlags.IsOutput)) { return(string.Format("ref {0}", model.Name)); } else { return(string.Format("{0}", model.Name)); } }
public Type ResolveType(ParameterModel model) { if (model == null) { return(null); } var behavior = new MarshallingService().ResolveBehavior(model); if (behavior == MarshalBehavior.Array || behavior == MarshalBehavior.Indirect) { return(typeof(IntPtr)); } return(ResolveType(model.Type)); }
/// <summary> /// Gets the code for passing the specified model as parameter to a trampoline method. /// </summary> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetTrampolineParameterCode(ParameterModel model) { if (model.Flags.HasFlag(ParameterModelFlags.IsOutput)) return string.Format("ref _{0}", model.Name); TranslationModel translationModel = model.Type as TranslationModel; if (translationModel != null) { var type = Type.GetType(translationModel.TargetType); if (Marshal.SizeOf(type) > sizeof(long)) return string.Format("new System.IntPtr(&{0})", model.Name); } return model.Name; }
public MarshalBehavior ResolveBehavior(ParameterModel model) { if (model.SizeParameter != null) { if (model.Flags.HasFlag(ParameterModelFlags.HasElementCount)) return MarshalBehavior.Array; else return MarshalBehavior.Indirect; } var fallback = ResolveBehavior(model.Type); if (fallback == MarshalBehavior.Direct && model.IndirectionLevel > 0) return MarshalBehavior.Indirect; return fallback; }
/// <summary> /// Gets the code for cleanup of local variables related to the specified parameter. /// </summary> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetLocalVariableCleanupCode(ParameterModel model) { if (model.Flags.HasFlag(ParameterModelFlags.IsOutput)) { //TODO: This check against IUnknown is a hack for DXGISwapChain::GetBuffer. To remove the // hack, it must be made possible to mark a function for removal -- GetBuffer must be // hand-written in terms of the trampoline that would be generated for it, because it // does not make sense for the model layer to understand the relationship between the // output parameter in question, the IID parameter ("riid"), and the object factory. if (model.Type.Key == "IUnknown") return string.Format("{0} = SlimDX.ObjectFactory.Create(_{0}, riid);", model.Name); return string.Format("{0} = _{0} != System.IntPtr.Zero ? new {1}(_{0}) : null;", model.Name, model.Type.Name); } return string.Empty; }
/// <summary> /// Gets the code for cleanup of local variables related to the specified parameter. /// </summary> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetLocalVariableCleanupCode(ParameterModel model) { if (model.Flags.HasFlag(ParameterModelFlags.IsOutput)) { //TODO: This check against IUnknown is a hack for DXGISwapChain::GetBuffer. To remove the // hack, it must be made possible to mark a function for removal -- GetBuffer must be // hand-written in terms of the trampoline that would be generated for it, because it // does not make sense for the model layer to understand the relationship between the // output parameter in question, the IID parameter ("riid"), and the object factory. if (model.Type.Key == "IUnknown") { return(string.Format("{0} = SlimDX.ObjectFactory.Create(_{0}, riid);", model.Name)); } return(string.Format("{0} = _{0} != System.IntPtr.Zero ? new {1}(_{0}) : null;", model.Name, model.Type.Name)); } return(string.Empty); }
/// <summary> /// Gets the code for passing the specified model as parameter to a trampoline method. /// </summary> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetTrampolineParameterCode(ParameterModel model) { if (model.Flags.HasFlag(ParameterModelFlags.IsOutput)) { return(string.Format("ref _{0}", model.Name)); } TranslationModel translationModel = model.Type as TranslationModel; if (translationModel != null) { var type = Type.GetType(translationModel.TargetType); if (Marshal.SizeOf(type) > sizeof(long)) { return(string.Format("new System.IntPtr(&{0})", model.Name)); } } return(model.Name); }
public MarshalBehavior ResolveBehavior(ParameterModel model) { if (model.SizeParameter != null) { if (model.Flags.HasFlag(ParameterModelFlags.HasElementCount)) { return(MarshalBehavior.Array); } else { return(MarshalBehavior.Indirect); } } var fallback = ResolveBehavior(model.Type); if (fallback == MarshalBehavior.Direct && model.IndirectionLevel > 0) { return(MarshalBehavior.Indirect); } return(fallback); }
/// <summary> /// Gets the code for setup of local variables related to the specified parameter. /// </summary> /// <param name="marshaller">The marshalling service interface.</param> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetLocalVariableSetupCode(MarshallingService marshaller, ParameterModel model) { if (model.Flags.HasFlag(ParameterModelFlags.IsOutput)) return string.Format("int _{0} = default(int);", model.Name); return string.Empty; }
public void AddParameter(ParameterModel parameter) { parameters.Add(parameter); }
/// <summary> /// Gets the code for passing the specified model as parameter to a trampoline method. /// </summary> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetTrampolineParameterCode(ParameterModel model) { if (model.Flags.HasFlag(ParameterModelFlags.IsOutput)) return string.Format("ref _{0}", model.Name); return string.Format("{0} != null ? {0}.NativePointer : System.IntPtr.Zero", model.Name); }
/// <summary> /// Gets the code for cleanup of local variables related to the specified parameter. /// </summary> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetLocalVariableCleanupCode(ParameterModel model) { return(string.Format("System.Runtime.InteropServices.Marshal.FreeHGlobal(_{0});", model.Name)); }
/// <summary> /// Gets the code for setup of local variables related to the specified parameter. /// </summary> /// <param name="marshaller">The marshalling service interface.</param> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetLocalVariableSetupCode(MarshallingService marshaller, ParameterModel model) { return(string.Format("System.IntPtr _{0} = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi({0});", model.Name)); }
/// <summary> /// Gets the code for declaring the specified model as a parameter to a managed method. /// </summary> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetFormalParameterCode(ParameterModel model) { return string.Format("System.String {0}", model.Name); }
/// <summary> /// Gets the code for setup of local variables related to the specified parameter. /// </summary> /// <param name="marshaller">The marshalling service interface.</param> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetLocalVariableSetupCode(MarshallingService marshaller, ParameterModel model) { return string.Format("{0} = default(System.IntPtr);", model.Name); }
/// <summary> /// Gets the code for setup of local variables related to the specified parameter. /// </summary> /// <param name="marshaller">The marshalling service interface.</param> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetLocalVariableSetupCode(MarshallingService marshaller, ParameterModel model) { return(string.Format("{0} = default(System.IntPtr);", model.Name)); }
/// <summary> /// Gets the code for passing the specified model as parameter to a trampoline method. /// </summary> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetTrampolineParameterCode(ParameterModel model) { if (model.Flags.HasFlag(ParameterModelFlags.IsOutput)) return "System.IntPtr.Zero"; return string.Format("new System.IntPtr(_{0})", model.Name); }
/// <summary> /// Gets the code for cleanup of local variables related to the specified parameter. /// </summary> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetLocalVariableCleanupCode(ParameterModel model) { if (model.Flags.HasFlag(ParameterModelFlags.IsOutput)) return string.Format("{0} = null;", model.Name); return string.Empty; }
/// <summary> /// Gets the code for passing the specified model as parameter to a trampoline method. /// </summary> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetTrampolineParameterCode(ParameterModel model) { return string.Format("_{0}", model.Name); }
/// <summary> /// Gets the code for setup of local variables related to the specified parameter. /// </summary> /// <param name="marshaller">The marshalling service interface.</param> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetLocalVariableSetupCode(MarshallingService marshaller, ParameterModel model) { return string.Format("System.IntPtr _{0} = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi({0});", model.Name); }
/// <summary> /// Gets the code for passing the specified model as parameter to a trampoline method. /// </summary> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetTrampolineParameterCode(ParameterModel model) { return(string.Format("new System.IntPtr(&_{0})", model.Name)); }
/// <summary> /// Gets the code for passing the specified model as parameter to a trampoline method. /// </summary> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetTrampolineParameterCode(ParameterModel model) { return(string.Format("_{0}", model.Name)); }
/// <summary> /// Gets the code for cleanup of local variables related to the specified parameter. /// </summary> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetLocalVariableCleanupCode(ParameterModel model) { if (model.Flags.HasFlag(ParameterModelFlags.IsOutput)) return string.Format("{0} = {1}.FromMarshaller(_{0});", model.Name, model.Type.Name); return string.Format("_{0}.Release();", model.Name); }
public Type ResolveType(ParameterModel model) { if (model == null) return null; var behavior = new MarshallingService().ResolveBehavior(model); if (behavior == MarshalBehavior.Array || behavior == MarshalBehavior.Indirect) return typeof(IntPtr); return ResolveType(model.Type); }
/// <summary> /// Gets the code for cleanup of local variables related to the specified parameter. /// </summary> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetLocalVariableCleanupCode(ParameterModel model) { return(string.Empty); }
/// <summary> /// Gets the code for setup of local variables related to the specified parameter. /// </summary> /// <param name="marshaller">The marshalling service interface.</param> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetLocalVariableSetupCode(MarshallingService marshaller, ParameterModel model) { if (model.Flags.HasFlag(ParameterModelFlags.IsOutput)) return string.Format("{0}Marshaller _{1} = default({0}Marshaller);", model.Type.Name, model.Name); return string.Format("{0}Marshaller _{1} = {0}.ToMarshaller({1});", model.Type.Name, model.Name); }
/// <summary> /// Gets the code for passing the specified model as parameter to a trampoline method. /// </summary> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetTrampolineParameterCode(ParameterModel model) { return string.Format("new System.IntPtr(&_{0})", model.Name); }
/// <summary> /// Gets the code for declaring the specified model as a parameter to a managed method. /// </summary> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetFormalParameterCode(ParameterModel model) { return(string.Format("System.String {0}", model.Name)); }
/// <summary> /// Gets the code for cleanup of local variables related to the specified parameter. /// </summary> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetLocalVariableCleanupCode(ParameterModel model) { return string.Format("System.Runtime.InteropServices.Marshal.FreeHGlobal(_{0});", model.Name); }
/// <summary> /// Gets the code for cleanup of local variables related to the specified parameter. /// </summary> /// <param name="model">The model.</param> /// <returns>The code.</returns> public string GetLocalVariableCleanupCode(ParameterModel model) { return string.Empty; }