static void WrapperToDirectory(string outputDir, WrapperOptions options, IEnumerable <MyFileInfo> inputFiles) { if (Directory.Exists(outputDir)) { if (options.HasFlag(WrapperOptions.ClearOutputDir)) { Directory.Delete(outputDir, true); } Directory.CreateDirectory(outputDir); } foreach (var myFileInfo in inputFiles) { string newOutDir = Path.Combine(outputDir, myFileInfo.SubPath); if (!Directory.Exists(newOutDir)) { Directory.CreateDirectory(newOutDir); } string newOutputFile = Path.Combine(newOutDir, myFileInfo.Info.Name.Replace('.', '_') + ".cpp"); // newOutputFile = Path.ChangeExtension(newOutputFile, ".cpp"); WrapperToFile(newOutputFile, options, new List <MyFileInfo>() { myFileInfo }); } }
public PoseWrapper(Delegate entryPoint, Type entryPointType, WrapperOptions options = WrapperOptions.None) : base(entryPoint, entryPoint.Method.ReturnType, entryPointType, options: options) { if (entryPoint.Method.ReturnType == null || entryPoint.Method.ReturnType != typeof(T)) { throw new ArgumentException("Return type of entry point and generic type must match."); } }
private void Init(Delegate entryPoint, WrapperOptions options, Type returnType = null, Type entryPointType = null, ParameterInfo[] entryPointParameters = null) { Options = options; EntryPoint = entryPoint ?? throw new ArgumentException("Cannot convert entryPoint to Action. Did you mean to use PoseWrapper<>?"); EntryPointParameters = entryPointParameters ?? entryPoint.Method.GetParameters(); EntryPointType = entryPointType ?? DelegateTypeHelper.GetTypeForDelegate(EntryPointParameters.Select(epp => epp.ParameterType).ToArray(), returnType); GenerateShimmedMethods(); }
public PoseWrapper(Delegate entryPoint, Type returnType = null, Type entryPointType = null, ParameterInfo[] entryPointParameters = null, WrapperOptions options = WrapperOptions.None) : base(entryPoint, returnType, entryPointType, entryPointParameters, options) { if (returnType == null || returnType != typeof(T)) { throw new ArgumentException("Return type of entry point and generic type must match."); } }
// todo: support constructors, getters vs. setters, etc. from here // and from the equivalent for GetPoseWrapper<T> public static PoseWrapper GetPoseWrapper(Expression <Action> expression, WrapperOptions options = DefaultOptions) { var method = (MethodInfo)MethodHelper.GetMethodFromExpression(expression.Body, false, out object instance); if (instance is Type) { return(GetPoseWrapper(method, options)); } else { return(GetPoseWrapper(method, instance, options)); } }
static void WrapperToFile(string outputFile, WrapperOptions options, IEnumerable<MyFileInfo> inputFiles) { StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); if (options.HasFlag(WrapperOptions.Append)) { if (File.Exists(outputFile)) { string temp = File.ReadAllText(outputFile); sw.Write(temp); } } else { string version = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion; sw.WriteLine("//This file was created by FileWrapper {0}", version); sw.WriteLine("//DO NOT EDIT"); sw.WriteLine("#include \"MedusaPreCompiled.h\""); sw.WriteLine("#include \"Core/IO/MemoryFileAutoRegister.h\""); } foreach (var inputFile in inputFiles) { if (options.HasFlag(WrapperOptions.Binary)) { WrapperBinary(sw, inputFile.Info.FullName, options.HasFlag(WrapperOptions.Manually)); } else { WrapperString(sw, inputFile.Info.FullName, options.HasFlag(WrapperOptions.Manually)); } } sw.Close(); String result = sb.ToString(); if (options.HasFlag(WrapperOptions.Append)) { System.IO.File.WriteAllText(outputFile, result); } else { if (File.Exists(outputFile)) { string temp = File.ReadAllText(outputFile); if (temp != result) { System.IO.File.WriteAllText(outputFile, result); } } else { System.IO.File.WriteAllText(outputFile, result); } } }
static void WrapperToDirectory(string outputDir, WrapperOptions options, IEnumerable<MyFileInfo> inputFiles) { if (Directory.Exists(outputDir)) { if (options.HasFlag(WrapperOptions.ClearOutputDir)) { Directory.Delete(outputDir, true); } Directory.CreateDirectory(outputDir); } foreach (var myFileInfo in inputFiles) { string newOutDir = Path.Combine(outputDir, myFileInfo.SubPath); if (!Directory.Exists(newOutDir)) { Directory.CreateDirectory(newOutDir); } string newOutputFile = Path.Combine(newOutDir, myFileInfo.Info.Name.Replace('.', '_') + ".cpp"); // newOutputFile = Path.ChangeExtension(newOutputFile, ".cpp"); WrapperToFile(newOutputFile, options, new List<MyFileInfo>() { myFileInfo }); } }
static void WrapperToFile(string outputFile, WrapperOptions options, IEnumerable <MyFileInfo> inputFiles) { StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); if (options.HasFlag(WrapperOptions.Append)) { if (File.Exists(outputFile)) { string temp = File.ReadAllText(outputFile); sw.Write(temp); } } else { string version = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion; sw.WriteLine("//This file was created by FileWrapper {0}", version); sw.WriteLine("//DO NOT EDIT"); sw.WriteLine("#include \"MedusaPreCompiled.h\""); sw.WriteLine("#include \"Core/IO/MemoryFileAutoRegister.h\""); } foreach (var inputFile in inputFiles) { if (options.HasFlag(WrapperOptions.Binary)) { WrapperBinary(sw, inputFile.Info.FullName, options.HasFlag(WrapperOptions.Manually)); } else { WrapperString(sw, inputFile.Info.FullName, options.HasFlag(WrapperOptions.Manually)); } } sw.Close(); String result = sb.ToString(); if (options.HasFlag(WrapperOptions.Append)) { System.IO.File.WriteAllText(outputFile, result); } else { if (File.Exists(outputFile)) { string temp = File.ReadAllText(outputFile); if (temp != result) { System.IO.File.WriteAllText(outputFile, result); } } else { System.IO.File.WriteAllText(outputFile, result); } } }
public PoseWrapper(Delegate entryPoint, Type returnType = null, Type entryPointType = null, ParameterInfo[] entryPointParameters = null, WrapperOptions options = WrapperOptions.None) { Init(entryPoint, options, returnType, entryPointType, entryPointParameters); }
public PoseWrapper(Delegate entryPoint, WrapperOptions options) { Init(entryPoint, options); }
public PoseWrapper(Action entryPoint, WrapperOptions options) { Init(entryPoint, options); }
public static PoseWrapper <T> GetPoseWrapper <T>(Delegate entryPoint, Type delegateType = null, WrapperOptions options = DefaultOptions) { var returnType = entryPoint.Method.ReturnType; if (returnType == null || returnType != typeof(T)) { throw new ArgumentException(NonMatchingReturnType); } var parameters = entryPoint.Method.GetParameters(); delegateType = delegateType ?? DelegateTypeHelper.GetTypeForDelegate(parameters, returnType); return(new PoseWrapper <T>(entryPoint, returnType, delegateType, parameters, options)); }
public static PoseWrapper <T> GetPoseWrapper <T>(MethodInfo method, object instance = null, WrapperOptions options = DefaultOptions) { var methodDelegate = GetDelegateFromMethodInfo(method, instance, out Type delegateType); return(GetPoseWrapper <T>(methodDelegate, delegateType, options)); }
public static PoseWrapper GetPoseWrapper(Delegate entryPoint, Type delegateType = null, WrapperOptions options = DefaultOptions) { var returnType = entryPoint.Method.ReturnType; var parameters = entryPoint.Method.GetParameters(); if (returnType == null || returnType != typeof(void)) { throw new ArgumentException(ReturnlessWrapperInvalidDelegate); } if (parameters.Length == 0) { return(new PoseWrapper(entryPoint, options)); } delegateType = delegateType ?? DelegateTypeHelper.GetTypeForDelegate(parameters, returnType); return(new PoseWrapper(entryPoint, null, delegateType, parameters, options)); }