当前位置: 首页>>代码示例>>C#>>正文


C# FileStream.ToBytes方法代码示例

本文整理汇总了C#中System.IO.FileStream.ToBytes方法的典型用法代码示例。如果您正苦于以下问题:C# FileStream.ToBytes方法的具体用法?C# FileStream.ToBytes怎么用?C# FileStream.ToBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.FileStream的用法示例。


在下文中一共展示了FileStream.ToBytes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ResolveAsm

        private static void ResolveAsm(string assemblyPath)
        {
            ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

            log.Info(string.Format("load source {0}", assemblyPath));

            // 复制路径
            var directoryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "aoptemp");
            var targetPath = Path.Combine(directoryPath, Path.GetFileName(assemblyPath));

            log.Info(string.Format("copy {0} to {1}", assemblyPath, targetPath));

            File.Copy(assemblyPath, targetPath, true);
            // copy pdb
            string oPath = Path.GetDirectoryName(assemblyPath);

            var sourceSymbol = oPath + @"\" + Path.GetFileNameWithoutExtension(assemblyPath) + ".pdb";
            var symbolPath = directoryPath + @"\" + Path.GetFileNameWithoutExtension(targetPath) + ".pdb";
            try
            {
                File.Copy(sourceSymbol, symbolPath, true);
            }
            catch (Exception ex)
            {
                log.Error(string.Format("copy {0} to {1}", assemblyPath, targetPath));
                return;
            }

            Stream stream = new FileStream(targetPath, FileMode.Open);
            var clrAsm = Assembly.Load(stream.ToBytes());
            if (clrAsm.GetCustomAttributes(typeof(AopAssembly), false).Length == 0)
                return;

            AssemblyDefinition asm = AssemblyDefinition.ReadAssembly(stream, new ReaderParameters() { ReadSymbols = true });

            MethodReference il2 = asm.MainModule.Import(typeof(Type).GetMethod("GetTypeFromHandle", new Type[1] { typeof(RuntimeTypeHandle) }));
            MethodReference il3 = asm.MainModule.Import(typeof(Type).GetMethod("GetMethod", new Type[1] { typeof(String) }));
            MethodReference il4 = asm.MainModule.Import(typeof(TypeService).GetMethod("GetAttribute", new Type[2] { typeof(Type), typeof(MemberInfo) }));
            MethodReference il5 = asm.MainModule.Import(typeof(AopAttribute).GetMethod("Invoke"));

            // 搜索并插入调用的il代码
            foreach (TypeDefinition type in asm.MainModule.Types)
            {
                if (!type.HasCustomAttributes) continue;

                foreach (CustomAttribute attribute in type.CustomAttributes)
                {
                    // 查找到实现aop标签的类
                    if (IsAssignableFromAopAttribute(attribute.Constructor.DeclaringType))
                    {
                        var clrType = clrAsm.GetType(type.FullName);
                        if (clrType == null) continue;

                        // 查找其实现基于aop标签的方法
                        foreach (MethodDefinition method in type.Methods)
                        {
                            if (!method.HasCustomAttributes) continue;

                            MethodInfo clrMethod = null;
                            try
                            {
                                clrMethod = clrType.GetMethod(method.Name, method.Parameters.Select(X => Type.GetType(X.ParameterType.GetAssemblyQualifiedName())).ToArray());
                            }
                            catch (Exception ex) { }
                            if (clrMethod == null) continue;

                            foreach (CustomAttribute methodAttribute in method.CustomAttributes)
                            {
                                if (IsAssignableFromAopAttribute(methodAttribute.Constructor.DeclaringType))
                                {
                                    var clrAttributeType = Type.GetType(methodAttribute.Constructor.DeclaringType.GetAssemblyQualifiedName());
                                    if (clrAttributeType == null) continue;

                                    var clrAttribute = clrMethod.GetCustomAttributes(clrAttributeType, true)[0] as AopAttribute;
                                    var aopTypes = clrAttribute.AopType;

                                    List<Instruction> fixedOffset = new List<Instruction>();

                                    if (aopTypes == AopTypes.Packed)
                                    {
                                        foreach (Instruction il in method.Body.Instructions)
                                        {
                                            if (il.OpCode == OpCodes.Ret || il.Offset == 0)
                                            {
                                                fixedOffset.Add(il);
                                            }
                                        }
                                    }
                                    else if (aopTypes == AopTypes.Prefixed)
                                    {
                                        foreach (Instruction il in method.Body.Instructions)
                                        {
                                            if (il.Offset == 1)
                                            {
                                                fixedOffset.Add(il);
                                            }
                                        }
                                    }
                                    else if (aopTypes == AopTypes.Suffixed)
                                    {
//.........这里部分代码省略.........
开发者ID:Gameman,项目名称:PlayStudio,代码行数:101,代码来源:AOP.cs

示例2: GetImageBytesFromFilePath

		private byte[] GetImageBytesFromFilePath(string fileName, string rootPath)
		{
			byte[] content = null;
			string filePath = ImageUploadHelper.GetUploadRootPath(rootPath) + "Temp\\" + fileName;

			if (File.Exists(filePath))
			{
				using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
				{
					content = fs.ToBytes();
				}
			}

			return content;
		}
开发者ID:jerryshi2007,项目名称:AK47Source,代码行数:15,代码来源:ShowUEditorImage.ashx.cs

示例3: GetImageBytesFromFilePath

		private static byte[] GetImageBytesFromFilePath(string filePath, out string fileName)
		{
			byte[] content = null;

			fileName = Path.GetFileName(filePath);

			if (File.Exists(filePath))
			{
				using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
				{
					content = fs.ToBytes();
				}
			}

			return content;
		}
开发者ID:jerryshi2007,项目名称:AK47Source,代码行数:16,代码来源:ImageUploader.cs


注:本文中的System.IO.FileStream.ToBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。