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


C# AssemblyCache类代码示例

本文整理汇总了C#中AssemblyCache的典型用法代码示例。如果您正苦于以下问题:C# AssemblyCache类的具体用法?C# AssemblyCache怎么用?C# AssemblyCache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: GetAssemblyCache

 private AssemblyCache GetAssemblyCache(Type classType, IConfiguration config)
 {
     if (_assemblyCache == null)
     {
         _assemblyCache = new Dictionary<Assembly, AssemblyCache>();
     }
     AssemblyCache cache = null;
     if (!_assemblyCache.TryGetValue(classType.Assembly, out cache))
     {
         cache = new AssemblyCache(classType.Assembly);
         foreach (JsonExDefaultValuesAttribute attr in classType.Assembly.GetCustomAttributes(typeof(JsonExDefaultValuesAttribute), false))
         {
             if (attr.DefaultValueSetting != DefaultValueOption.InheritParentSetting)
                 cache.defaultOption = attr.DefaultValueSetting;
             if (attr.Type != null)
             {
                 if (cache.defaultValues == null)
                     cache.defaultValues = new DefaultValueCollection(config.DefaultValues);
                 cache.defaultValues[attr.Type] = attr.DefaultValue;
             }
         }
         if (cache.defaultOption == DefaultValueOption.InheritParentSetting && cache.defaultValues != null)
             cache.defaultOption = DefaultValueOption.SuppressDefaultValues;
         _assemblyCache[classType.Assembly] = cache;
     }
     return cache;
 }
开发者ID:AugustoAngeletti,项目名称:blockspaces,代码行数:27,代码来源:JsonDefaultAttributeProcessor.cs

示例2: IsThisCall

		/// <summary>Returns true if we're calling an instance method with caller's this
		/// pointer, or if we're calling a static method in caller's declaring
		/// type with caller's this pointer as an argument.</summary>
		public bool IsThisCall(AssemblyCache cache, MethodInfo caller, int callIndex)
		{
			DBC.Pre(cache != null, "cache is null");				
			DBC.Pre(caller != null, "caller is null");
				
			if (!m_isThisCall.HasValue)
			{
				m_isThisCall = false;

				MethodInfo target = cache.FindMethod(Target);
				if (target != null && !target.Method.IsConstructor)
				{
					if (target.Method.HasThis)
					{
						int nth = target.Method.Parameters.Count;
						int j = caller.Tracker.GetStackIndex(callIndex, nth);
						
						if (j >= 0)
							m_isThisCall = caller.Instructions.LoadsThisArg(j);
					}
					else if (target.Method.IsStatic)
					{
						for (int i = 0; i < target.Method.Parameters.Count && !m_isThisCall.Value; ++i)
						{
							int j = caller.Tracker.GetStackIndex(callIndex, i);				

							if (j >= 0)
								m_isThisCall = caller.Instructions.LoadsThisArg(j);
						}
					}
				}
			}
			return m_isThisCall.Value;
		}
开发者ID:dbremner,项目名称:smokey,代码行数:37,代码来源:Call.cs

示例3: DoCallsVirtual

		private int DoCallsVirtual(AssemblyCache cache, MethodInfo info)
		{
			int offset = -1;
			if (m_tested.IndexOf(info.Method.ToString()) >= 0)
				return offset;
				
			m_tested.Add(info.Method.ToString());

			Log.DebugLine(this, "checking:");
			Log.Indent();
			
			// If the class isn't sealed then,
			if (info.Method.Body != null && info.Instructions != null)
			{
				Log.DebugLine(this, "{0:F}", info.Instructions);

				// loop through every instruction,
				for (int i = 0; i < info.Instructions.Length && offset < 0; ++i)
				{
					// if it's a call,
					Call call = info.Instructions[i] as Call;
					if (call != null)
					{	
						// then we have a problem if we're calling a virtual method
						// on our instance,
						MethodInfo targetInfo = cache.FindMethod(call.Target);
						if (targetInfo != null)
						{
							if (call.IsThisCall(Cache, info, i))
							{
								if (targetInfo.Method.IsVirtual && !targetInfo.Method.IsFinal)
								{
									Log.DebugLine(this, "{0} is virtual", call.Target);
									{
										m_details = call.Target.ToString();			
										offset = call.Untyped.Offset;
										Log.DebugLine(this, "found virtual call at {0:X2}", offset);
									}
								}
								else
								{
									// or we're calling one of our methods which calls a virtual method
									// on our instance.
									offset = DoCallsVirtual(cache, targetInfo);
								}
							}
						}
					}
				}
			}
			Log.Unindent();
			
			if (offset >= 0)
				m_details = info.Method + " -> " + Environment.NewLine + "       " + m_details;			
			
			return offset;
		}
开发者ID:dbremner,项目名称:smokey,代码行数:57,代码来源:CtorCallsVirtualRule.cs

示例4: DoGetStructSize

		// There doesn't seem to be a way to get this via Cecil: all of the obvious
		// candidates like TypeDefinition::PackingSize, TypeDefinition::ClassSize,
		// and FieldDefinition::Offset return zero.
		private int DoGetStructSize(AssemblyCache cache, TypeDefinition type, int level)
		{
			int size = 0;
			DBC.Assert(level < 100, "LargeStructRule didn't terminate for type {0}", type.FullName);
//			Console.WriteLine(prefix + type.FullName);
			
			// For each field,
			foreach (FieldDefinition field in type.Fields)
			{
				Log.WarningLine(this, "checking field of type {0}{1}", new string(' ', 3*level), field.FieldType.FullName);
				
				// if it isn't static,
				if (!field.IsStatic)
				{
					// if it's a value type,
					if (field.FieldType.IsValueType)
					{
						// if it's a standard system struct then we know the size,
						int temp = DoGetSystemTypeSize(field.FieldType.FullName);
						if (temp > 0)
							size += temp;
						else 
						{
							// otherwise if it's one of our types we can figure the
							// size out,
							TypeDefinition t = cache.FindType(field.FieldType);
							if (t != null && t.FullName != type.FullName)	// TODO: shouldn't need the name check (but mscorlib.dll infinitely recurses w/o it)
							{
								if (t.IsEnum || !t.IsValueType)
									size += 4;
								else
									size += DoGetStructSize(cache, t, level + 1);
							}
							
							// if it's not one of our types then we appear to be hosed
							// (this should rarely happen now that we load dependant
							// assemblies).
							else
							{
								Log.TraceLine(this, "couldn't find the size for {0}", field.FieldType.FullName);
								size += 1;		
							}
						}
					}
					
					// if it's not a value type then for our purposes its size is 4 
					// (pointers may be 8 bytes on a 64-bit platform but we don't want
					// to report errors just because they happen to be running on a 
					// 64-bit system).
					else
						size += 4;
				}
			}
						
			return size;
		}
开发者ID:dbremner,项目名称:smokey,代码行数:59,代码来源:LargeStructRule.cs

示例5: MakeTest

 protected ComparisonTest MakeTest (
     string filename, string[] stubbedAssemblies = null,
     TypeInfoProvider typeInfo = null,
     AssemblyCache assemblyCache = null
 ) {
     return new ComparisonTest(
         EvaluatorPool,
         Portability.NormalizeDirectorySeparators(filename), stubbedAssemblies,
         typeInfo, assemblyCache
     );
 }
开发者ID:cbsistem,项目名称:JSIL,代码行数:11,代码来源:GenericTestFixture.cs

示例6: Rule

		protected Rule(AssemblyCache cache, IReportViolations reporter, string checkID)
		{
			DBC.Pre(cache != null, "cache is null");
			DBC.Pre(reporter != null, "reporter is null");
			DBC.Pre(!string.IsNullOrEmpty(checkID), "checkID is null or empty");

			Cache = cache;
			Reporter = reporter;
			CheckID = checkID;
			Runtime = TargetRuntime.NET_1_0;
		}
开发者ID:dbremner,项目名称:smokey,代码行数:11,代码来源:Rule.cs

示例7: UseFlagsAttributeRule

		public UseFlagsAttributeRule(AssemblyCache cache, IReportViolations reporter) 
			: base(cache, reporter, "D1019")
		{
			long mask = 1;
			for (int i = 0; i < 63; ++i)
			{
				m_powers.Add(mask);
				mask = mask << 1;
			}
			m_powers.Add(mask);
		}
开发者ID:dbremner,项目名称:smokey,代码行数:11,代码来源:UseFlagsAttributeRule.cs

示例8: ComparisonTest

        public ComparisonTest(
            EvaluatorPool pool,
            IEnumerable<string> filenames, string outputPath, 
            string[] stubbedAssemblies = null, TypeInfoProvider typeInfo = null,
            AssemblyCache assemblyCache = null
        )
        {
            var started = DateTime.UtcNow.Ticks;
            OutputPath = outputPath;
            EvaluatorPool = pool;

            var extensions = (from f in filenames select Path.GetExtension(f).ToLower()).Distinct().ToArray();
            var absoluteFilenames = (from f in filenames select Path.Combine(TestSourceFolder, f));

            if (extensions.Length != 1)
                throw new InvalidOperationException("Mixture of different source languages provided.");

            var assemblyNamePrefix = Path.GetDirectoryName(outputPath).Split(new char[] { '\\', '/' }).Last();
            var assemblyName = Path.Combine(
                assemblyNamePrefix,
                Path.GetFileName(outputPath).Replace(".js", "")
            );

            switch (extensions[0]) {
                case ".cs":
                    Assembly = CompilerUtil.CompileCS(absoluteFilenames, assemblyName);
                    break;
                case ".vb":
                    Assembly = CompilerUtil.CompileVB(absoluteFilenames, assemblyName);
                    break;
                case ".exe":
                case ".dll":
                    var fns = absoluteFilenames.ToArray();
                    if (fns.Length > 1)
                        throw new InvalidOperationException("Multiple binary assemblies provided.");

                    Assembly = Assembly.LoadFile(fns[0]);
                    break;
                default:
                    throw new ArgumentException("Unsupported source file type for test");
            }

            if (typeInfo != null)
                typeInfo.ClearCaches();

            StubbedAssemblies = stubbedAssemblies;
            TypeInfo = typeInfo;
            AssemblyCache = assemblyCache;

            var ended = DateTime.UtcNow.Ticks;
            CompilationElapsed = TimeSpan.FromTicks(ended - started);
        }
开发者ID:xen2,项目名称:JSIL,代码行数:52,代码来源:TestUtil.cs

示例9: NonLocalizedGuiRule

		public NonLocalizedGuiRule(AssemblyCache cache, IReportViolations reporter) 
			: base(cache, reporter, "G1002")
		{
			m_enabled = Settings.Get("*localized*", "true") == "true";
			Log.TraceLine(this, "enabled: {0}", m_enabled);
			
			string custom = Settings.Get("localize", string.Empty);
			foreach (string name in custom.Split(';'))
			{
				Log.TraceLine(this, "using custom: {0}", name);
				m_custom.Add(" " + name + "(");		// add some goo so we match only what we should
			}
		}
开发者ID:dbremner,项目名称:smokey,代码行数:13,代码来源:NonLocalizedGuiRule.cs

示例10: OperatorAlternativeRule

		public OperatorAlternativeRule(AssemblyCache cache, IReportViolations reporter) 
			: base(cache, reporter, "D1033")
		{
			m_table.Add("op_Addition", "Add");
			m_table.Add("op_Subtraction", "Subtract");
			m_table.Add("op_Multiply", "Multiply");
			m_table.Add("op_Division", "Divide");
			m_table.Add("op_Modulus", "Mod");
			m_table.Add("op_GreaterThan", "Compare");
			m_table.Add("op_GreaterThanOrEqual", "Compare");
			m_table.Add("op_LessThan", "Compare");
			m_table.Add("op_LessThanOrEqual", "Compare");
			m_table.Add("op_Inequality", "Equals");
			m_table.Add("op_Equality", "Equals");
		}
开发者ID:dbremner,项目名称:smokey,代码行数:15,代码来源:OperatorAlternativeRule.cs

示例11: CreateTranslator

        static AssemblyTranslator CreateTranslator(
            Configuration configuration, AssemblyManifest manifest, AssemblyCache assemblyCache
        )
        {
            TypeInfoProvider typeInfoProvider = null;

            if (
                configuration.ReuseTypeInfoAcrossAssemblies.GetValueOrDefault(true) &&
                (CachedTypeInfoProvider != null)
            ) {
                if (CachedTypeInfoProviderConfiguration.Assemblies.Equals(configuration.Assemblies))
                    typeInfoProvider = CachedTypeInfoProvider;
            }

            var translator = new AssemblyTranslator(
                configuration, typeInfoProvider, manifest, assemblyCache,
                onProxyAssemblyLoaded: (name) => {
                    Console.Error.WriteLine("// Loaded proxies from '{0}'", ShortenPath(name));
                }
            );

            translator.Decompiling += MakeProgressHandler       ("Decompiling ");
            translator.RunningTransforms += MakeProgressHandler ("Translating ");
            translator.Writing += MakeProgressHandler           ("Writing JS  ");

            translator.AssemblyLoaded += (fn) => {
                Console.Error.WriteLine("// Loaded {0}", ShortenPath(fn));
            };
            translator.CouldNotLoadSymbols += (fn, ex) => {
            };
            translator.CouldNotResolveAssembly += (fn, ex) => {
                Console.Error.WriteLine("// Could not load module {0}: {1}", fn, ex.Message);
            };
            translator.CouldNotDecompileMethod += (fn, ex) => {
                Console.Error.WriteLine("// Could not decompile method {0}: {1}", fn, ex.Message);
            };

            if (typeInfoProvider == null) {
                if (CachedTypeInfoProvider != null)
                    CachedTypeInfoProvider.Dispose();

                CachedTypeInfoProvider = translator.GetTypeInfoProvider();
                CachedTypeInfoProviderConfiguration = configuration;
            }

            return translator;
        }
开发者ID:simon-heinen,项目名称:JSIL,代码行数:47,代码来源:Program.cs

示例12: SpecialFolderRule

		public SpecialFolderRule(AssemblyCache cache, IReportViolations reporter) 
			: base(cache, reporter, "PO1003")
		{
			string user = Environment.UserName;
			
			Array values = Enum.GetValues(typeof(Environment.SpecialFolder));			
			foreach (object o in values)
			{
				Environment.SpecialFolder name = (Environment.SpecialFolder) o;
				string path = Environment.GetFolderPath(name);
				if (path.Length > 0)
				{
					path = path.Replace(user, "*");
					if (!m_globs.ContainsKey(name))
						m_globs.Add(name, path.Split(Path.DirectorySeparatorChar));
				}
			}
		}
开发者ID:dbremner,项目名称:smokey,代码行数:18,代码来源:SpecialFolderRule.cs

示例13: FilenameTestSource

        protected IEnumerable<TestCaseData> FilenameTestSource(string[] filenames, TypeInfoProvider typeInfo = null, AssemblyCache asmCache = null)
        {
            var testNames = filenames.OrderBy((s) => s).ToArray();

            for (int i = 0, l = testNames.Length; i < l; i++) {
                var testName = testNames[i];

                bool isIgnored = testName.StartsWith("ignored:", StringComparison.OrdinalIgnoreCase);
                var actualTestName = testName;

                if (isIgnored)
                    actualTestName = actualTestName.Substring(actualTestName.IndexOf(":") + 1);

                var item = (new TestCaseData(new object[] { new object[] { actualTestName, typeInfo, asmCache, null, i == (l - 1) } }))
                    .SetName(Path.GetFileName(actualTestName));

                if (isIgnored)
                    item.Ignore();

                yield return item;
            }
        }
开发者ID:Ocelloid,项目名称:JSIL,代码行数:22,代码来源:GenericTestFixture.cs

示例14: CreateTranslator

        static AssemblyTranslator CreateTranslator(Configuration configuration, AssemblyManifest manifest, AssemblyCache assemblyCache)
        {
            var translator = new AssemblyTranslator(configuration, null, manifest, assemblyCache);

            translator.Decompiling += MakeProgressHandler("Decompiling   ");
            translator.Optimizing += MakeProgressHandler ("Optimizing    ");
            translator.Writing += MakeProgressHandler    ("Generating JS ");

            translator.AssemblyLoaded += (fn) => {
                Console.Error.WriteLine("// Loaded {0}", ShortenPath(fn));
            };
            translator.CouldNotLoadSymbols += (fn, ex) => {
            };
            translator.CouldNotResolveAssembly += (fn, ex) => {
                Console.Error.WriteLine("// Could not load module {0}: {1}", fn, ex.Message);
            };
            translator.CouldNotDecompileMethod += (fn, ex) => {
                Console.Error.WriteLine("// Could not decompile method {0}: {1}", fn, ex.Message);
            };

            return translator;
        }
开发者ID:c444b774,项目名称:JSIL,代码行数:22,代码来源:Program.cs

示例15: NoStaticRemoveRule

		public NoStaticRemoveRule(AssemblyCache cache, IReportViolations reporter) 
			: base(cache, reporter, "C1026")
		{
			// Collections.Generic
			m_adders.Add  ("System.Collections.Generic.Dictionary`", new List<string>{"Add", "set_Item"});
			m_removers.Add("System.Collections.Generic.Dictionary`", new List<string>{"Clear", "Remove"});
			
			m_adders.Add  ("System.Collections.Generic.HashSet`", new List<string>{"Add", "UnionWith"});
			m_removers.Add("System.Collections.Generic.HashSet`", new List<string>{"Clear", "ExceptWith", "IntersectWith", "Remove", "RemoveWhere", "SymmetricExceptWith"});
			
			m_adders.Add  ("System.Collections.Generic.List`", new List<string>{"Add", "AddRange", "Insert", "InsertRange"});
			m_removers.Add("System.Collections.Generic.List`", new List<string>{"Clear", "Remove", "RemoveAll", "RemoveAt", "RemoveRange"});
			
			m_adders.Add  ("System.Collections.Generic.Queue`", new List<string>{"Enqueue"});
			m_removers.Add("System.Collections.Generic.Queue`", new List<string>{"Clear", "Dequeue"});
			
			m_adders.Add  ("System.Collections.Generic.SortedDictionary`", new List<string>{"Add", "set_Item"});
			m_removers.Add("System.Collections.Generic.SortedDictionary`", new List<string>{"Clear", "Remove"});
			
			m_adders.Add  ("System.Collections.Generic.Stack`", new List<string>{"Push"});
			m_removers.Add("System.Collections.Generic.Stack`", new List<string>{"Clear", "Pop"});
			
			// Collections
			m_adders.Add  ("System.Collections.ArrayList", new List<string>{"Add", "AddRange", "Insert", "InsertRange"});
			m_removers.Add("System.Collections.ArrayList", new List<string>{"Clear", "Remove", "RemoveAt", "RemoveRange"});
			
			m_adders.Add  ("System.Collections.Hashtable", new List<string>{"Add", "set_Item"});
			m_removers.Add("System.Collections.Hashtable", new List<string>{"Clear", "Remove"});
			
			m_adders.Add  ("System.Collections.Queue", new List<string>{"Enqueue"});
			m_removers.Add("System.Collections.Queue", new List<string>{"Clear", "Dequeue"});
			
			m_adders.Add  ("System.Collections.SortedList", new List<string>{"Add", "set_Item"});
			m_removers.Add("System.Collections.SortedList", new List<string>{"Clear", "Remove", "RemoveAt"});
			
		}
开发者ID:dbremner,项目名称:smokey,代码行数:36,代码来源:NoStaticRemoveRule.cs


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