/// <summary> /// Tries to get a property that returns a given field. Needs to go base classes /// also /// </summary> /// <param name="host"></param> /// <param name="type"></param> /// <param name="field"></param> /// <param name="property"></param> /// <returns></returns> public static bool TryGetPropertyReadingField(IPexComponent host, TypeEx type, Field field, out Property property) { foreach (Property prop in type.DeclaredProperties) { Method getter = prop.Getter; if (getter == null) { continue; } MethodEffects me; if (TryComputeMethodEffects(host, type, getter, null, out me) && me.ReturnFields.Contains(field)) { property = prop; return(true); } } var baseType = type.BaseType; if (baseType != null) { TryGetPropertyReadingField(host, baseType, field, out property); } property = null; return(false); }
public TargetBranchAnalyzer(PexMeDynamicDatabase pmd, IPexComponentServices services, IPexExplorationComponent explorationComponent) { this.pmd = pmd; this.host = pmd; this.services = services; this.explorationComponent = explorationComponent; }
/// <summary> /// Gets the type definition of a field /// </summary> /// <param name="host"></param> /// <param name="field"></param> /// <param name="ftex"></param> /// <returns></returns> public static bool TryGetDeclaringTypeDefinition(IPexComponent host, Field field, out TypeEx ftex) { var fdefinition = field.Definition; TypeDefinition td; if (!fdefinition.TryGetDeclaringType(out td)) { host.Log.LogError(WikiTopics.MissingWikiTopic, "fieldanalyzer", "Failed to retrieve the declaring type of the field " + field.FullName); ftex = null; return(false); } try { ftex = td.Instantiate(new TypeEx[0]); } catch (ArgumentException argEx) { ftex = td.Instantiate(new TypeEx[] { MetadataFromReflection.GetType(typeof(object)) }); } catch (Exception ex) { ftex = null; Log.AppendLine("Instantiate typeEx fail: " + ex); } return(true); }
/// <summary> /// parses the predefined effects described above /// </summary> /// <returns></returns> public static bool ParsePredefinedEffects(IPexComponent host) { //already parsed if (isPredefinedEffectsParsed) { return(true); } effectsStore = new Dictionary <PreDefinedMethodEffectsStore, PreDefinedMethodEffectsStore>(); //parse each record int numRecords = NumRecords; for (int count = 0; count < numRecords; count++) { string assemblyname = predefinedEffects[count, 0]; string typename = predefinedEffects[count, 1]; string fieldname = predefinedEffects[count, 2]; string fmttype = predefinedEffects[count, 3]; string methodname = predefinedEffects[count, 4]; ParseRecord(host, assemblyname, typename, fieldname, fmttype, methodname); } isPredefinedEffectsParsed = true; return(true); }
public PexMeFactoryGuesser(IPexComponent host) : base(host) { this.host = host; this.pmd = host.GetService <IPexMeDynamicDatabase>() as PexMeDynamicDatabase; this.psd = host.GetService <IPexMeStaticDatabase>() as PexMeStaticDatabase; }
private static SafeDictionary <Method, MethodStore> GetMethodDictionary(IPexComponent host, System.Collections.Generic.Dictionary <string, PersistentMethodStore> pmethoddic) { var methoddic = new SafeDictionary <Method, MethodStore>(); foreach (var methodstr in pmethoddic.Keys) { Method method; bool bresult = MethodOrFieldAnalyzer.TryGetMethodFromPersistentStringForm(host, methodstr, out method); if (!bresult) { continue; } MethodStore ms; bresult = PersistentMethodStore.TryGetMethodStore(host, pmethoddic[methodstr], out ms); if (!bresult) { continue; } //SafeDebug.Assume(bresult, "Failed to get method from persistent store!!!"); methoddic[method] = ms; } return(methoddic); }
/// <summary> /// Function that retrieves associated method store /// </summary> /// <param name="pms"></param> /// <param name="ms"></param> /// <returns></returns> public static bool TryGetFieldStore(IPexComponent host, PersistentFieldStore pfs, out FieldStore fs) { fs = new FieldStore(); bool bresult = MethodOrFieldAnalyzer.TryGetFieldFromPersistentStringForm(host, pfs.FieldName, out fs.FieldName); SafeDebug.Assume(bresult, "Failed to get field from the persistent store"); fs.FieldValues.AddRange(pfs.FieldValues); //TODO: Performance can be improved via caching over here foreach (var mname in pfs.ReadMethods) { Method m; bresult = MethodOrFieldAnalyzer.TryGetMethodFromPersistentStringForm(host, mname, out m); SafeDebug.Assume(bresult, "Failed to get method from persistent string form "); fs.ReadMethods.Add(m); } foreach (var typeex in pfs.WriteMethods.Keys) { SafeSet<Method> wmethods = new SafeSet<Method>(); TypeEx typeEx; bresult = MethodOrFieldAnalyzer.TryGetTypeExFromPersistentStringForm(host, typeex, out typeEx); SafeDebug.Assume(bresult, "Failed to get type from persistent string form " + typeex); fs.WriteMethods.Add(typeEx, wmethods); HashSet<string> methods; bresult = pfs.WriteMethods.TryGetValue(typeex, out methods); SafeDebug.Assume(bresult, "Failed to get associated set of methods for a type " + typeex); foreach (var m in methods) { Method method; bresult = MethodOrFieldAnalyzer.TryGetMethodFromPersistentStringForm(host, m, out method); SafeDebug.Assume(bresult, "Failed to get method from string form " + m); wmethods.Add(method); } } foreach (var m in pfs.ModificationTypeDictionary.Keys) { var value = pfs.ModificationTypeDictionary[m]; Method method; bresult = MethodOrFieldAnalyzer.TryGetMethodFromPersistentStringForm(host, m, out method); SafeDebug.Assume(bresult, "Failed to get method from string form " + m); fs.ModificationTypeDictionary.Add(method, value); } foreach (var m in pfs.PreciseModificationTypeDictionary.Keys) { var value = pfs.PreciseModificationTypeDictionary[m]; Method method; bresult = MethodOrFieldAnalyzer.TryGetMethodFromPersistentStringForm(host, m, out method); SafeDebug.Assume(bresult, "Failed to get method from string form " + m); fs.PreciseModificationTypeDictionary.Add(method, value); } return true; }
/// <summary> /// Method is allowed to be invoked only once. Therefore the order of loading classes into the Dictionary is /// quite important. /// </summary> /// <param name="host"></param> public static bool LoadPredefinedGenericClasses(IPexComponent host, string assemblyName) { //QuickGraph: TEdge -> Edge<int> TypeEx edgeTypeEx; PreDefinedGenericClassesStore tedgePdgc = new PreDefinedGenericClassesStore(); predefinedClasses.Add("TEdge", tedgePdgc); if (MethodOrFieldAnalyzer.TryGetTypeExFromName(host, assemblyName, "QuickGraph.Edge`1", out edgeTypeEx)) { tedgePdgc.AddToPredinedStore("QuickGraph.AdjacencyGraph`2", edgeTypeEx); tedgePdgc.AddToPredinedStore("QuickGraph.IGraph`2", edgeTypeEx); } //Dsa: TNode for BinarySearchTree -> Dsa.DataStructures.BinaryTreeNode`1 PreDefinedGenericClassesStore tnodePdgc = new PreDefinedGenericClassesStore(); predefinedClasses.Add("TNode", tnodePdgc); TypeEx binNodeEx; if (MethodOrFieldAnalyzer.TryGetTypeExFromName(host, assemblyName, "Dsa.DataStructures.BinaryTreeNode`1", out binNodeEx)) { tnodePdgc.AddToPredinedStore("Dsa.DataStructures.BinarySearchTree`1", binNodeEx); tnodePdgc.AddToPredinedStore("Dsa.DataStructures.CommonBinaryTree`2", binNodeEx); tnodePdgc.AddToPredinedStore("System.Collections.Generic.Queue`1", binNodeEx); } TypeEx avltreeNodeEx = null; if (MethodOrFieldAnalyzer.TryGetTypeExFromName(host, assemblyName, "Dsa.DataStructures.AvlTreeNode`1", out avltreeNodeEx)) { tnodePdgc.AddToPredinedStore("Dsa.DataStructures.AvlTree`1", avltreeNodeEx); tnodePdgc.AddToPredinedStore("Dsa.DataStructures.CommonBinaryTree`2", avltreeNodeEx); tnodePdgc.AddToPredinedStore("System.Collections.Generic.Queue`1", avltreeNodeEx); } return true; }
public XunitTestFramework_2_1(IPexComponent host) : base(host, name: "xunit-2.0", prettyName: "xUnit.net 2.1", xunitPackageVersion: "2.1.0", visualStudioRunnerPackageVersion: "2.1.0") { }
/// <summary> /// Accepts a field in the form "assemblyname#typename#fieldname" and returns the actual field /// </summary> /// <param name="Field"></param> /// <returns></returns> public static bool TryGetFieldFromPersistentStringForm(IPexComponent host, string fstr, out Field field) { field = null; var splitarr = fstr.Split(new char[] { PexMeConstants.PexMePersistenceFormSeparator }); SafeDebug.Assume(splitarr.Length == 3, "Incorrect persistent store field name"); var assemblyname = splitarr[0]; var typename = splitarr[1]; var signature = splitarr[2]; FieldDefinition fdef; if (!TryGetFieldDefinition(host, assemblyname, typename, signature, out fdef)) { return(false); } TypeDefinition tdef; if (!fdef.TryGetDeclaringType(out tdef)) { return(false); } field = fdef.Instantiate(GetGenericTypeParameters(host, tdef)); return(true); }
public void AfterExecution(IPexComponent host, object data) { if (this.pmd.CurrentPUTMethod == null) { this.host.Log.LogWarning(WikiTopics.MissingWikiTopic, "PUTExploration", "Return, not current PUT method is set"); WriteStopStatus(); return; } SafeDebug.AssertNotNull(this.pmd.CurrentPUTMethod, "CurrentPUTMethod should be set by this time"); var currPUTSignature = MethodOrFieldAnalyzer.GetMethodSignature(this.pmd.CurrentPUTMethod); if (this.pmd.AllExploredMethods.Contains(currPUTSignature)) { this.host.Log.LogWarning(WikiTopics.MissingWikiTopic, "PUTExploration", "Ignoring the post processing of the PUT " + currPUTSignature + " since it is explored earlier!!!"); WriteStopStatus(); return; } //Add this to pending methods PexMePostProcessor ppp = new PexMePostProcessor(host); ppp.AfterExecution(); }
/// <summary> /// Function that retrieves associated method store /// </summary> /// <param name="pms"></param> /// <param name="ms"></param> /// <returns></returns> public static bool TryGetMethodStore(IPexComponent host, PersistentMethodStore pms, out MethodStore ms) { ms = new MethodStore(); bool bresult = MethodOrFieldAnalyzer.TryGetMethodFromPersistentStringForm(host, pms.methodName, out ms.methodName); SafeDebug.Assume(bresult, "Failed to get the method from persistent form " + pms.methodName); foreach (var fieldstr in pms.ReadFields) { Field field; bresult = MethodOrFieldAnalyzer.TryGetFieldFromPersistentStringForm(host, fieldstr, out field); SafeDebug.Assume(bresult, "Failed to get the field from persistent form " + fieldstr); ms.ReadFields.Add(field); } foreach (var fieldstr in pms.WriteFields) { Field field; bresult = MethodOrFieldAnalyzer.TryGetFieldFromPersistentStringForm(host, fieldstr, out field); SafeDebug.Assume(bresult, "Failed to get the field from persistent form " + fieldstr); ms.WriteFields.Add(field); } foreach (var typeexstr in pms.CallingMethods.Keys) { SafeSet<Method> wmethods = new SafeSet<Method>(); TypeEx typeEx; bresult = MethodOrFieldAnalyzer.TryGetTypeExFromPersistentStringForm(host, typeexstr, out typeEx); if (!bresult) { //No strict safedebugging cannot be added for calling methods since there //can be several dummy methods from Pex side continue; } ms.CallingMethods.Add(typeEx, wmethods); var methods = pms.CallingMethods[typeexstr]; foreach (var mstr in methods) { Method method; bresult = MethodOrFieldAnalyzer.TryGetMethodFromPersistentStringForm(host, mstr, out method); if (!bresult) continue; wmethods.Add(method); } } foreach (var calledMethodStr in pms.CalledMethods) { Method method; bresult = MethodOrFieldAnalyzer.TryGetMethodFromPersistentStringForm(host, calledMethodStr, out method); if (!bresult) continue; ms.CalledMethods.Add(method); } return true; }
public static SafeList <TypeEx> GetInvolvedTypes(IPexComponent host, TermManager termManager, Term t) { using (var ofc = new ObjectFieldCollector(host, termManager)) { ofc.VisitTerm(default(TVoid), t); return(ofc.Types); } }
public static SafeList<TypeEx> GetInvolvedTypes(IPexComponent host, TermManager termManager, Term t) { using (var ofc = new ObjectFieldCollector(host, termManager)) { ofc.VisitTerm(default(TVoid), t); return ofc.Types; } }
public XunitTestFramework_2_2(IPexComponent host) : base(host, name: "xunit-2.2", prettyName: "xUnit.net 2.2", xunitPackageVersion: "2.2.0", visualStudioRunnerPackageVersion: "2.2.0") { }
public NewTestLogger(IPexComponent host) : base(host) { Host.Log.ProblemHandler += Log_ProblemHandler; outputFile = InfoFileDirectory + Host.Services.CurrentAssembly.Assembly.Assembly.ShortName + ".problem.txt"; // this.outputFile = Path.Combine(host.Services.ReportManager.ReportPath, "newtests.txt"); }
public static bool TryGetTypeExFromName(IPexComponent host, string assemblyname, string typename, out TypeEx typeEx) { typeEx = null; AssemblyEx assembly; ReflectionHelper.TryLoadAssemblyEx(assemblyname, out assembly); return(TryGetTypeExFromName(host, assembly, typename, out typeEx)); }
protected override object BeforeExecution(IPexComponent host) { Host = host; host.Log.ExplorableHandler += Log_ExplorableHandler; host.Log.UninstrumentedMethodHandler += Log_UninstrumentedMethodHandler; host.Log.ExplorationBoundaryHandler += new RemoteEventHandler <ExplorationBoundaryEventArgs>(Log_ExplorationBoundaryHandler); return(null); }
protected override object BeforeExecution(IPexComponent host) { host.Services.CoverageManager.BeforePublishAssemblyCoverage += Handler(host); locations = host.GetService <ProblemTrackDatabase>().UnCoveredBranchCodeLocations; Log = new StringBuilder(); ErrorLog = host.GetService <ProblemTrackDatabase>().ErrorLog; return(null); }
public void AfterExecution(IPexComponent host, object data) { var problemTrackDatabase = host.GetService <ProblemTrackDatabase>(); problemTrackDatabase.ReportPath = host.Services.ReportManager.ReportPath; // host.Services.ReportManager.GeneratePexReport problemTrackDatabase.RelativePath = host.Services.ReportManager.RelativeRootPath; problemTrackDatabase.AssemblyUnderTest = assemblyUnderTest; problemTrackDatabase.AfterExecution(); }
public static SafeList<Field> GetInvolvedFields(IPexComponent host, TermManager termManager, Term t, out SafeDictionary<Field, FieldValueHolder> fieldValues, out SafeList<TypeEx> allFieldTypes) { using (var ofc = new ObjectFieldCollector(host, termManager)) { ofc.VisitTerm(default(TVoid), t); fieldValues = ofc.FieldValues; allFieldTypes = ofc.Types; return ofc.Fields; } }
/// <summary> /// Gets predefined types. Here tdef can be null. In that scenario, if a dictionary exists for the generic /// name, than the first element in the dictionary is returned /// </summary> /// <param name="host"></param> /// <param name="genericname"></param> /// <param name="tdef"></param> /// <param name="genericType"></param> /// <returns></returns> public static bool TryGetInstantiatedClass(IPexComponent host, string genericname, TypeDefinition tdef, out TypeEx genericType) { genericType = null; if (!bClassLoaded) { if (host != null) { string assemblyName = null; PexMeDynamicDatabase pmd = host.GetService <IPexMeDynamicDatabase>() as PexMeDynamicDatabase; if (pmd != null) { assemblyName = pmd.AssemblyName; } else { PexMeStaticDatabase psd = host.GetService <IPexMeStaticDatabase>() as PexMeStaticDatabase; if (psd != null) { assemblyName = psd.AssemblyName; } } //One of PMD or PSD should be available by this time. If not nothing can be done if (assemblyName == null) { host.Log.LogWarning(WikiTopics.MissingWikiTopic, "Hardcoded", "Could not load predefined generic classes data"); return(false); } bClassLoaded = true; LoadPredefinedGenericClasses(host, assemblyName); } } PreDefinedGenericClassesStore pdgc; if (predefinedClasses.TryGetValue(genericname, out pdgc)) { if (tdef != null) { if (pdgc.TryGetTypeExForTypename(tdef.FullName, out genericType)) { return(true); } } //tdef can be null in the case of instantiating methods and fields having generic arguments if (pdgc.TryGetSomeTypeEx(out genericType)) { return(true); } } return(false); }
public static SafeList <Field> GetInvolvedFields(IPexComponent host, TermManager termManager, Term t, out SafeDictionary <Field, FieldValueHolder> fieldValues, out SafeList <TypeEx> allFieldTypes) { using (var ofc = new ObjectFieldCollector(host, termManager)) { ofc.VisitTerm(default(TVoid), t); fieldValues = ofc.FieldValues; allFieldTypes = ofc.Types; return(ofc.Fields); } }
/// <summary> /// Initializes a new instance of the <see cref="XunitTestFramework"/> class. /// </summary> /// <param name="host">The IntelliTest host</param> /// <param name="name">The name of the test framework</param> /// <param name="prettyName">The display name of the test framework</param> /// <param name="xunitPackageVersion">The package version of xunit to be installed</param> /// <param name="visualStudioRunnerPackageVersion">The package version of xunit.runner.visualstudio to be installed</param> public XunitTestFramework(IPexComponent host, string name, string prettyName, string xunitPackageVersion, string visualStudioRunnerPackageVersion) : base(host) { this.name = name; this.prettyName = prettyName; this.xunitPackageVersion = xunitPackageVersion; this.visualStudioRunnerPackageVersion = visualStudioRunnerPackageVersion; }
public PexMePostProcessor(IPexComponent host) : base(host) { this.host = host; this.pmd = host.GetService<IPexMeDynamicDatabase>() as PexMeDynamicDatabase; this.psd = host.GetService<IPexMeStaticDatabase>() as PexMeStaticDatabase; this.pdw = new PexMeDumpWriter(host); this.currAssembly = this.pmd.Services.CurrentAssembly.Assembly.Assembly; var nestingdepth = System.Environment.GetEnvironmentVariable("PEXME_NESTED_DEPTH"); if (nestingdepth != null) ndepth = Convert.ToInt32(nestingdepth, 10); }
public void DumpAssemblyCoverage(IPexComponent host) { StringBuilder sb = new StringBuilder(); foreach (var item in UnCoveredBranchCodeLocations) { CodeLocation codeLocation = item.Location; ISymbolManager sm = host.Services.SymbolManager; SequencePoint sp; MethodDefinitionBodyInstrumentationInfo info; if (sm.TryGetSequencePoint(codeLocation.Method, codeLocation.Offset, out sp) && codeLocation.Method.TryGetBodyInstrumentationInfo(out info)) { sb.AppendLine(codeLocation.Method.FullName + "," + sp.Document + "," + sp.Line + "," + sp.Column + " outgoingbranch label: " + item.OutgointBranchLabel + " offset: " + codeLocation.Offset.ToString("x")); var branchInfo = new BranchInfo(sp.Document, sp.Line, sp.Column, sp.EndColumn, codeLocation.Method.FullName, codeLocation.Offset); _nonCoveredBranchInfo.Branches.Add(branchInfo); } } DumpInfoToDebugFile(sb.ToString(), assemblyCovFileName + TXT); DumpInfoToFile(_nonCoveredBranchInfo, assemblyCovFileName); StringBuilder sb2 = new StringBuilder("instruction cov: \n"); foreach (var cov in InstructionCov) { sb2.AppendLine("method: " + cov.Key); foreach (var pair in cov.Value) { sb2.AppendLine("offset: " + pair.Key.ToString("x") + " covered: " + pair.Value); } } DumpInfoToDebugFile(sb2.ToString(), instructionCovFileName + TXT); DumpInfoToFile(InstructionCov, instructionCovFileName); StringBuilder sb3 = new StringBuilder("basicblockOffsets cov: \n"); foreach (var offset in BasicBlocksOffsets) { sb3.AppendLine("method: " + offset.Key); foreach (var pair in offset.Value) { sb3.AppendLine("offset: " + pair.ToString("x")); } } DumpInfoToDebugFile(sb3.ToString(), basicBlockOffsetFileName + TXT); }
/// <summary> /// Gets the type definition of a field /// </summary> /// <param name="host"></param> /// <param name="field"></param> /// <param name="ftex"></param> /// <returns></returns> public static bool TryGetDeclaringTypeDefinition(IPexComponent host, Field field, out TypeDefinition td) { var fdefinition = field.Definition; if (!fdefinition.TryGetDeclaringType(out td)) { host.Log.LogError(WikiTopics.MissingWikiTopic, "fieldanalyzer", "Failed to retrieve the declaring type of the field " + field.FullName); td = null; return(false); } return(true); }
public OrderedMethodEffects(IPexComponent host, Method method) { SafeDebug.AssumeNotNull(method, "method"); this.Method = method; TypeEx declaringType; if (!method.TryGetDeclaringType(out declaringType)) { //TODO: error } MethodOrFieldAnalyzer.TryComputeMethodEffects(host, declaringType, method, null, out this.Effects); }
public PexMePostProcessor(IPexComponent host) : base(host) { this.host = host; this.pmd = host.GetService <IPexMeDynamicDatabase>() as PexMeDynamicDatabase; this.psd = host.GetService <IPexMeStaticDatabase>() as PexMeStaticDatabase; this.pdw = new PexMeDumpWriter(host); this.currAssembly = this.pmd.Services.CurrentAssembly.Assembly.Assembly; var nestingdepth = System.Environment.GetEnvironmentVariable("PEXME_NESTED_DEPTH"); if (nestingdepth != null) { ndepth = Convert.ToInt32(nestingdepth, 10); } }
/// <summary> /// Retrieves the method object back from the signature /// </summary> /// <param name="typename"></param> /// <param name="methodsignature"></param> /// <returns></returns> public static bool TryGetMethodDefinition(IPexComponent host, string assemblyname, string typename, string methodsignature, out MethodDefinition methoddef) { methoddef = null; TypeDefinition typeDef = null; try { bool result = TryGetTypeDefinitionFromName(host, assemblyname, typename, out typeDef); if (typeDef == null || !result) { return(false); } } catch (Exception) { return(false); } foreach (var constructor in typeDef.DeclaredInstanceConstructors) { if (GetMethodSignature(constructor) == methodsignature) { methoddef = constructor; return(true); } } foreach (var definition in typeDef.DeclaredInstanceMethods) { if (GetMethodSignature(definition) == methodsignature) { methoddef = definition; return(true); } } foreach (var definition in typeDef.DeclaredStaticMethods) { if (GetMethodSignature(definition) == methodsignature) { methoddef = definition; return(true); } } return(false); }
/// <summary> /// Gets the type definition of a field /// </summary> /// <param name="host"></param> /// <param name="field"></param> /// <param name="ftex"></param> /// <returns></returns> public static bool TryGetDeclaringTypeEx(IPexComponent host, Field field, out TypeEx ftex) { var fdefinition = field.Definition; TypeDefinition td; if (!fdefinition.TryGetDeclaringType(out td)) { host.Log.LogError(WikiTopics.MissingWikiTopic, "fieldanalyzer", "Failed to retrieve the declaring type of the field " + field.FullName); ftex = null; return(false); } ftex = td.Instantiate(GetGenericTypeParameters(host, td)); return(true); }
/// <summary> /// Function the retrieves associated Persistent store for each MethodStore /// </summary> /// <param name="ms"></param> /// <param name="pms"></param> /// <returns></returns> public static bool TryGetPersistentFieldStore(IPexComponent host, FieldStore fs, out PersistentFieldStore pfs) { pfs = new PersistentFieldStore(); pfs.FieldName = MethodOrFieldAnalyzer.GetPersistentStringFormOfField(fs.FieldName); //foreach(var value in fs.FieldValues) // pfs.FieldValues.Add(value); //TODO: Performance can be improved via caching over here foreach (var m in fs.ReadMethods) { pfs.ReadMethods.Add(MethodOrFieldAnalyzer.GetPersistentStringFormOfMethod(m)); } foreach (var typeex in fs.WriteMethods.Keys) { HashSet <string> wmethods = new HashSet <string>(); pfs.WriteMethods.Add(MethodOrFieldAnalyzer.GetPersistentStringFormOfTypeEx(typeex), wmethods); SafeSet <Method> methods; bool bresult = fs.WriteMethods.TryGetValue(typeex, out methods); SafeDebug.Assume(bresult, "Failed to get associated set of methods for a type"); var assemblyname = typeex.Definition.Module.Assembly.Location; var typename = typeex.FullName; foreach (var m in methods) { wmethods.Add(assemblyname + PexMeConstants.PexMePersistenceFormSeparator + typename + PexMeConstants.PexMePersistenceFormSeparator + MethodOrFieldAnalyzer.GetMethodSignature(m)); } } foreach (var m in fs.ModificationTypeDictionary.Keys) { var value = fs.ModificationTypeDictionary[m]; pfs.ModificationTypeDictionary.Add(MethodOrFieldAnalyzer.GetPersistentStringFormOfMethod(m), value); } foreach (var m in fs.PreciseModificationTypeDictionary.Keys) { var value = fs.PreciseModificationTypeDictionary[m]; pfs.PreciseModificationTypeDictionary.Add(MethodOrFieldAnalyzer.GetPersistentStringFormOfMethod(m), value); } return(true); }
public static bool TryGetTypeDefinitionFromName(IPexComponent host, string assemblyname, string typename, out TypeDefinition typeDef) { typeDef = null; AssemblyEx assembly; ReflectionHelper.TryLoadAssemblyEx(assemblyname, out assembly); foreach (var assemtype in assembly.TypeDefinitions) { if (assemtype.FullName == typename) { typeDef = assemtype; return(true); } } return(false); }
/// <summary> /// Computes fitness values /// </summary> /// <param name="host"></param> /// <param name="binOp"></param> /// <param name="left"></param> /// <param name="right"></param> /// <param name="bNegated"></param> /// <returns></returns> public static int ComputeFitnessValue(IPexComponent host, BinaryOperator binOp, int left, int right, bool bNegated) { int fitnessval = -1; //TODO: How to handle <= or >= operators. How did they come??? switch (binOp) { case BinaryOperator.Ceq: if (!bNegated) { //a == b fitnessval = Math.Abs(left - right); } else { //a != b //TODO: How to define the fitness measure? host.Log.LogWarning(WikiTopics.MissingWikiTopic, "fitness measure", "encountered the condition a != b"); } break; case BinaryOperator.Clt: if (!bNegated) { //a < b fitnessval = (left - right) + FitnessMeasure.FitnessConstant; } else { //a > b fitnessval = (right - left) + FitnessMeasure.FitnessConstant; } break; default: host.Log.LogWarning(WikiTopics.MissingWikiTopic, "fitness measure", "Unknown binary operator. Failed to compute the fitness measure"); break; } return(fitnessval); }
private static SafeDictionary <Field, FieldStore> GetFieldDictionary(IPexComponent host, System.Collections.Generic.Dictionary <string, PersistentFieldStore> pfielddic) { var fielddic = new SafeDictionary <Field, FieldStore>(); foreach (var fieldstr in pfielddic.Keys) { Field field; bool bresult = MethodOrFieldAnalyzer.TryGetFieldFromPersistentStringForm(host, fieldstr, out field); SafeDebug.Assume(bresult, "Failed to get field from persistent store!!!"); FieldStore fs; bresult = PersistentFieldStore.TryGetFieldStore(host, pfielddic[fieldstr], out fs); SafeDebug.Assume(bresult, "Failed to get field store!!!"); fielddic[field] = fs; } return(fielddic); }
public static bool TryGetTypeExFromName(IPexComponent host, AssemblyEx assembly, string typename, out TypeEx typeEx) { if (typeExCache.TryGetValue(typename, out typeEx)) { return(true); } typeEx = null; foreach (var assemtype in assembly.TypeDefinitions) { if (assemtype.FullName == typename) { typeEx = assemtype.Instantiate(GetGenericTypeParameters(host, assemtype)); typeExCache.Add(typename, typeEx); return(true); } } return(false); }
/// <summary> /// Computes fitness values /// </summary> /// <param name="host"></param> /// <param name="binOp"></param> /// <param name="left"></param> /// <param name="right"></param> /// <param name="bNegated"></param> /// <returns></returns> public static int ComputeFitnessValue(IPexComponent host, BinaryOperator binOp, int left, int right, bool bNegated) { int fitnessval = -1; //TODO: How to handle <= or >= operators. How did they come??? switch (binOp) { case BinaryOperator.Ceq: if(!bNegated) { //a == b fitnessval = Math.Abs(left - right); } else { //a != b //TODO: How to define the fitness measure? host.Log.LogWarning(WikiTopics.MissingWikiTopic, "fitness measure", "encountered the condition a != b"); } break; case BinaryOperator.Clt: if (!bNegated) { //a < b fitnessval = (left - right) + FitnessMeasure.FitnessConstant; } else { //a > b fitnessval = (right - left) + FitnessMeasure.FitnessConstant; } break; default: host.Log.LogWarning(WikiTopics.MissingWikiTopic, "fitness measure", "Unknown binary operator. Failed to compute the fitness measure"); break; } return fitnessval; }
/// <summary> /// Retrieves the write methods for a field, if exists from the predefined settings. /// </summary> public static bool TryGetWriteMethods(IPexComponent host, Field field, FieldModificationType desiredFmt, out SafeSet<Method> writeMethods) { if (!isPredefinedEffectsParsed) ParsePredefinedEffects(host); PreDefinedMethodEffectsStore pdme = new PreDefinedMethodEffectsStore(field, desiredFmt); PreDefinedMethodEffectsStore existingPdme; if (effectsStore.TryGetValue(pdme, out existingPdme)) { writeMethods = new SafeSet<Method>(); writeMethods.AddRange(existingPdme.suggestedmethodList); return true; } else { writeMethods = null; return false; } }
/// <summary> /// Gets invoked before execution /// </summary> /// <param name="host"></param> /// <returns></returns> protected override object BeforeExecution(IPexComponent host) { this.host = host; //register all explorables foreach (IPexExplorableGuesser guesser in this.CreateExplorableGuessers(host)) { host.Services.ExplorableGuesserManager.AddExplorableGuesser(guesser); } this.host.Log.ExplorableHandler += Log_ExplorableHandler; this.host.Log.ProblemHandler += Log_ProblemHandler; this.pmd = host.GetService<IPexMeDynamicDatabase>() as PexMeDynamicDatabase; //TargetBranch Handler cannot be instantiated with ExplorationServices from here if TERM_SOLVER //functionality is required if(!PexMeConstants.USE_TERM_SOLVER) this.tba = new TargetBranchAnalyzer(this.pmd, this.host.Services, null); return null; }
/// <summary> /// Retrieves the field from the given fields /// </summary> /// <param name="typename"></param> /// <param name="methodsignature"></param> /// <returns></returns> public static bool TryGetField(IPexComponent host, string assemblyname, string typename, string fieldname, out Field field) { field = null; FieldDefinition fdef; if (!TryGetFieldDefinition(host, assemblyname, typename, fieldname, out fdef)) { return(false); } TypeDefinition tdef; if (!fdef.TryGetDeclaringType(out tdef)) { return(false); } field = fdef.Instantiate(GetGenericTypeParameters(host, tdef)); return(true); }
/// <summary> /// parses the predefined effects described above /// </summary> /// <returns></returns> public static bool ParsePredefinedEffects(IPexComponent host) { //already parsed if (isPredefinedEffectsParsed) return true; effectsStore = new Dictionary<PreDefinedMethodEffectsStore, PreDefinedMethodEffectsStore>(); //parse each record int numRecords = NumRecords; for (int count = 0; count < numRecords; count++ ) { string assemblyname = predefinedEffects[count, 0]; string typename = predefinedEffects[count, 1]; string fieldname = predefinedEffects[count, 2]; string fmttype = predefinedEffects[count, 3]; string methodname = predefinedEffects[count, 4]; ParseRecord(host, assemblyname, typename, fieldname, fmttype, methodname); } isPredefinedEffectsParsed = true; return true; }
public static bool TryGetTypeExFromName(IPexComponent host, AssemblyEx assembly, string typename, out TypeEx typeEx) { if(typeExCache.TryGetValue(typename, out typeEx)) return true; typeEx = null; foreach (var assemtype in assembly.TypeDefinitions) { if (assemtype.FullName == typename) { typeEx = assemtype.Instantiate(GetGenericTypeParameters(host, assemtype)); typeExCache.Add(typename, typeEx); return true; } } return false; }
/// <summary> /// Returns true if the field is visible externally of the given type /// </summary> /// <param name="field"></param> /// <returns></returns> public static bool IsFieldExternallyVisible(IPexComponent host, TypeEx type, Field field) { var visibilityContext = VisibilityContext.Exported; //Step 1: Is field visible externally? if (field.IsVisible(visibilityContext)) return true; //Step 2: Check whether this is an associated property and see whether it is public Property property; if (TryGetPropertyModifyingField(host, type, field, out property)) { if (property.IsVisible(visibilityContext)) return true; } //Step 3: Check whether any constructor directly sets this field foreach (Method constructor in type.GetVisibleInstanceConstructors(visibilityContext)) { MethodEffects me; if (TryComputeMethodEffects(host, type, constructor, null, out me)) { if (me.DirectSetterFields.Contains(field.ShortName)) return true; } } return false; }
/// <summary> /// Computes method effects statically. All written fields of a method. /// Can be imprecise and conservative /// </summary> /// <param name="declaringType"></param> /// <param name="method"></param> /// <param name="effects"></param> /// <returns></returns> public static bool TryComputeMethodEffects(IPexComponent host, TypeEx declaringType, Method method, SafeSet<Method> visitedMethods, out MethodEffects effects) { SafeDebug.AssumeNotNull(declaringType, "declaringType"); SafeDebug.AssumeNotNull(method, "method"); try { if (visitedMethods == null) visitedMethods = new SafeSet<Method>(); if (visitedMethods.Contains(method)) { effects = null; return false; } visitedMethods.Add(method); //Check whether this has been computed before var psd = host.GetService<IPexMeStaticDatabase>() as PexMeStaticDatabase; if (psd.MethodEffectsDic.TryGetValue(method.GlobalIndex, out effects)) return true; var res = new SafeSet<string>(); var directSetFields = new SafeSet<string>(); var directCalledMethods = new SafeSet<Method>(); var returnFields = new SafeSet<Field>(); var modificationTypeDic = new SafeDictionary<string, FieldModificationType>(); var parameters = method.Parameters; MethodBodyEx body; if (!method.TryGetBody(out body) || !body.HasInstructions) { effects = null; return false; } int callDepth = 0; int offset = 0; Instruction instruction; OpCode prevOpcode = OpCodes.Nop; //Stack for load instructions Field lastAccessedArrayField = null; Field lastAccessedField = null; while (body.TryGetInstruction(offset, out instruction)) { SafeDebug.AssumeNotNull(instruction, "instruction"); OpCode opCode = instruction.OpCode; if (LdcOpCodes.Contains(opCode)) { //topIsConstant = true; } else if (ConvOpCodes.Contains(opCode)) { // do not change topIsConstant } else { if (opCode == OpCodes.Stfld) { SafeDebug.Assume(opCode.OperandType == OperandType.InlineField, "opCode.OperandType == OperandType.InlineField"); Field field = instruction.Field; AddFieldToMethodEffects(host, declaringType, res, directSetFields, modificationTypeDic, prevOpcode, field, field.Type); } else if (opCode == OpCodes.Ldfld || opCode == OpCodes.Ldflda) { SafeDebug.Assume(opCode.OperandType == OperandType.InlineField, "opCode.OperandType == OperandType.InlineField"); Field accessedField = instruction.Field; if (accessedField.Type.Spec == TypeSpec.SzArray) { lastAccessedArrayField = accessedField; } else lastAccessedField = accessedField; } else if (StElemOpCodes.Contains(opCode)) { if (lastAccessedArrayField != null) { //Indicates that there is n array type modified AddFieldToMethodEffects(host, declaringType, res, directSetFields, modificationTypeDic, prevOpcode, lastAccessedArrayField, lastAccessedArrayField.Type); lastAccessedArrayField = null; } } else if (opCode == OpCodes.Call || opCode == OpCodes.Callvirt) { SafeDebug.Assume(opCode.OperandType == OperandType.InlineMethod, "opCode.OperandType == OperandType.InlineMethod"); Method methodinner = instruction.Method; SafeDebug.AssumeNotNull(method, "method"); directCalledMethods.Add(methodinner); TypeEx methodDeclaringType; //are these function calls are within the parent types if (methodinner.TryGetDeclaringType(out methodDeclaringType) && declaringType.IsAssignableTo(methodDeclaringType)) { MethodEffects methodEffects; if (TryComputeMethodEffects(host, methodDeclaringType, methodinner, visitedMethods, out methodEffects)) { res.AddRange(methodEffects.WrittenInstanceFields); foreach (var key in methodEffects.ModificationTypeDictionary.Keys) modificationTypeDic[key] = methodEffects.ModificationTypeDictionary[key]; directSetFields.AddRange(methodEffects.DirectSetterFields); if (methodEffects.CallDepth > callDepth) callDepth = methodEffects.CallDepth; } } else { //introducing heuristics for inter-procedural static analysis if (lastAccessedField != null && lastAccessedField.Type.IsReferenceType && !(methodinner.ShortName.StartsWith("Get") || methodinner.ShortName.StartsWith("get") || methodinner.ShortName.StartsWith("Set") || methodinner.ShortName.StartsWith("set"))) { AddFieldToMethodEffects(host, declaringType, res, directSetFields, modificationTypeDic, prevOpcode, lastAccessedField, lastAccessedField.Type); } } } else if (opCode == OpCodes.Ret) { if (instruction.Field != null) returnFields.Add(instruction.Field); } //topIsConstant = false; } prevOpcode = opCode; offset = instruction.NextOffset; } effects = new MethodEffects((IFiniteSet<string>)res, directSetFields, directCalledMethods, returnFields, modificationTypeDic, callDepth + 1); psd.MethodEffectsDic[method.GlobalIndex] = effects; return true; } catch (Exception ex) { host.Log.LogErrorFromException(ex, WikiTopics.MissingWikiTopic, "methodeffects", "Failed to compute method effects for method " + method.FullName + "," + ex.Message); effects = null; return false; } }
/// <summary> /// Gets the type definition of a field /// </summary> /// <param name="host"></param> /// <param name="field"></param> /// <param name="ftex"></param> /// <returns></returns> public static bool TryGetDeclaringTypeDefinition(IPexComponent host, Field field, out TypeDefinition td) { var fdefinition = field.Definition; if (!fdefinition.TryGetDeclaringType(out td)) { host.Log.LogError(WikiTopics.MissingWikiTopic, "fieldanalyzer", "Failed to retrieve the declaring type of the field " + field.FullName); td = null; return false; } return true; }
/// <summary> /// Gets the type definition of a field /// </summary> /// <param name="host"></param> /// <param name="field"></param> /// <param name="ftex"></param> /// <returns></returns> public static bool TryGetDeclaringTypeEx(IPexComponent host, Field field, out TypeEx ftex) { var fdefinition = field.Definition; TypeDefinition td; if (!fdefinition.TryGetDeclaringType(out td)) { host.Log.LogError(WikiTopics.MissingWikiTopic, "fieldanalyzer", "Failed to retrieve the declaring type of the field " + field.FullName); ftex = null; return false; } ftex = td.Instantiate(GetGenericTypeParameters(host, td)); return true; }
public static TypeEx AddFieldToMethodEffects(IPexComponent host, TypeEx declaringType, SafeSet<string> res, SafeSet<string> directSetFields, SafeDictionary<string, FieldModificationType> modificationTypeDic, OpCode prevOpcode, Field field, TypeEx fieldType) { SafeDebug.AssumeNotNull(field, "field"); SafeDebug.Assume(!field.IsStatic, "!field.IsStatic"); TypeEx fieldDeclaringType; //The following check ensures that the field belongs to this class //or its base classes if (field.TryGetDeclaringType(out fieldDeclaringType) && declaringType.IsAssignableTo(fieldDeclaringType)) { res.Add(field.ShortName); FieldModificationType fmt = FieldModificationType.UNKNOWN; if (fieldType == SystemTypes.Int32 || fieldType == SystemTypes.Int64 || fieldType == SystemTypes.Int16) { if (prevOpcode == OpCodes.Add) fmt = FieldModificationType.INCREMENT; else if (prevOpcode == OpCodes.Sub) fmt = FieldModificationType.DECREMENT; else if (prevOpcode == OpCodes.Call || prevOpcode == OpCodes.Calli || prevOpcode == OpCodes.Callvirt) fmt = FieldModificationType.METHOD_CALL; else host.Log.LogWarning(WikiTopics.MissingWikiTopic, "fieldmodificationtype", "Encountered unknown modification type for integer type " + prevOpcode); } else { if (field.Type.IsReferenceType) { if (prevOpcode == OpCodes.Ldnull) fmt = FieldModificationType.NULL_SET; else if (prevOpcode == OpCodes.Newarr || prevOpcode == OpCodes.Newobj) fmt = FieldModificationType.NON_NULL_SET; else if (LdArgOpCodes.Contains(prevOpcode)) fmt = FieldModificationType.NON_NULL_SET; else { fmt = FieldModificationType.METHOD_CALL; //A method call is invoked on this field, which updates this field } } else if (fieldType == SystemTypes.Bool) { if (prevOpcode == OpCodes.Ldc_I4_0) fmt = FieldModificationType.FALSE_SET; else if (prevOpcode == OpCodes.Ldc_I4_1) fmt = FieldModificationType.TRUE_SET; else host.Log.LogWarning(WikiTopics.MissingWikiTopic, "fieldmodificationtype", "Encountered unknown modification type for boolean type " + prevOpcode); } } //Store the value of fmt. Sometimes, the same field //can be modified in different ways within the method, for example //setting a boolean field to both true or false. In that case, the modification //type is left as unknown FieldModificationType prevFMT; if (modificationTypeDic.TryGetValue(field.ShortName, out prevFMT)) { //There is some entry for this field if (prevFMT != FieldModificationType.UNKNOWN && prevFMT != fmt) { modificationTypeDic[field.ShortName] = FieldModificationType.UNKNOWN; } } else { modificationTypeDic[field.ShortName] = fmt; } //A heuristic based approach for aliasing analysis for checking whether the field is directly //assigned any parameters if (LdArgOpCodes.Contains(prevOpcode)) directSetFields.Add(field.ShortName); } return fieldDeclaringType; }
/// <summary> /// Retrieves the field from the given fields /// </summary> /// <param name="typename"></param> /// <param name="methodsignature"></param> /// <returns></returns> public static bool TryGetField(IPexComponent host, string assemblyname, string typename, string fieldname, out Field field) { field = null; FieldDefinition fdef; if (!TryGetFieldDefinition(host, assemblyname, typename, fieldname, out fdef)) return false; TypeDefinition tdef; if (!fdef.TryGetDeclaringType(out tdef)) return false; field = fdef.Instantiate(GetGenericTypeParameters(host, tdef)); return true; }
/// <summary> /// Retrieves the method object back from the signature /// </summary> /// <param name="typename"></param> /// <param name="methodsignature"></param> /// <returns></returns> public static bool TryGetMethod(IPexComponent host, string assemblyname, string typename, string methodsignature, out Method method) { method = null; MethodDefinition mdef; if (!TryGetMethodDefinition(host, assemblyname, typename, methodsignature, out mdef)) return false; TypeDefinition tdef; if (!mdef.TryGetDeclaringType(out tdef)) return false; method = mdef.Instantiate(GetGenericTypeParameters(host, tdef), GetGenericMethodParameters(host, mdef)); return true; }
public static bool TryGetTypeExFromName(IPexComponent host, string assemblyname, string typename, out TypeEx typeEx) { typeEx = null; AssemblyEx assembly; ReflectionHelper.TryLoadAssemblyEx(assemblyname, out assembly); return TryGetTypeExFromName(host, assembly, typename, out typeEx); }
public static bool TryGetTypeDefinitionFromName(IPexComponent host, string assemblyname, string typename, out TypeDefinition typeDef) { typeDef = null; AssemblyEx assembly; ReflectionHelper.TryLoadAssemblyEx(assemblyname, out assembly); foreach (var assemtype in assembly.TypeDefinitions) { if (assemtype.FullName == typename) { typeDef = assemtype; return true; } } return false; }
/// <summary> /// Tries to get a property that returns a given field. Needs to go base classes /// also /// </summary> /// <param name="host"></param> /// <param name="type"></param> /// <param name="field"></param> /// <param name="property"></param> /// <returns></returns> public static bool TryGetPropertyReadingField(IPexComponent host, TypeEx type, Field field, out Property property) { if (type == null) { property = null; return false; } if (type.DeclaredProperties != null) { foreach (Property prop in type.DeclaredProperties) { Method getter = prop.Getter; if (getter == null) continue; MethodEffects me; if (TryComputeMethodEffects(host, type, getter, null, out me) && me.ReturnFields.Contains(field)) { property = prop; return true; } } } var baseType = type.BaseType; if (baseType != null) { if (TryGetPropertyReadingField(host, baseType, field, out property)) return true; } property = null; return false; }
/// <summary> /// Tries to get a property that modifies the given field /// </summary> /// <param name="host"></param> /// <param name="type"></param> /// <param name="field"></param> /// <param name="property"></param> /// <returns></returns> public static bool TryGetPropertyModifyingField(IPexComponent host, TypeEx type, Field field, out Property property) { foreach (Property prop in type.DeclaredProperties) { Method setter = prop.Setter; if (setter == null) continue; MethodEffects me; if (TryComputeMethodEffects(host, type, setter, null, out me) && me.WrittenInstanceFields.Contains(field.ShortName)) { FieldModificationType fmt; if (me.ModificationTypeDictionary.TryGetValue(field.ShortName, out fmt) && fmt != FieldModificationType.METHOD_CALL && fmt != FieldModificationType.UNKNOWN) { property = prop; return true; } } } var baseType = type.BaseType; if (baseType != null) { if (TryGetPropertyModifyingField(host, baseType, field, out property)) return true; } property = null; return false; }
/// <summary> /// Accepts a method in the form "assemblyname#typename#methodsignature" and returns the actual method /// </summary> /// <param name="method"></param> /// <returns></returns> public static bool TryGetMethodFromPersistentStringForm(IPexComponent host, string mstr, out Method m) { m = null; var splitarr = mstr.Split(new char[] { PexMeConstants.PexMePersistenceFormSeparator }); SafeDebug.Assume(splitarr.Length == 3, "Incorrect persistent store method name"); var assemblyname = splitarr[0]; var typename = splitarr[1]; var signature = splitarr[2]; MethodDefinition mdef; if (!TryGetMethodDefinition(host, assemblyname, typename, signature, out mdef)) return false; TypeDefinition tdef; if (!mdef.TryGetDeclaringType(out tdef)) return false; m = mdef.Instantiate(GetGenericTypeParameters(host, tdef), GetGenericMethodParameters(host, mdef)); return true; }
/// <summary> /// Retrieves the method object back from the signature /// </summary> /// <param name="typename"></param> /// <param name="methodsignature"></param> /// <returns></returns> public static bool TryGetMethodDefinition(IPexComponent host, string assemblyname, string typename, string methodsignature, out MethodDefinition methoddef) { methoddef = null; TypeDefinition typeDef = null; try { bool result = TryGetTypeDefinitionFromName(host, assemblyname, typename, out typeDef); if (typeDef == null || !result) return false; } catch (Exception) { return false; } foreach (var constructor in typeDef.DeclaredInstanceConstructors) { if (GetMethodSignature(constructor) == methodsignature) { methoddef = constructor; return true; } } foreach (var definition in typeDef.DeclaredInstanceMethods) { if (GetMethodSignature(definition) == methodsignature) { methoddef = definition; return true; } } foreach (var definition in typeDef.DeclaredStaticMethods) { if (GetMethodSignature(definition) == methodsignature) { methoddef = definition; return true; } } return false; }
/// <summary> /// Accepts a type in the form "assemblyname#typename" and returns the type name /// </summary> /// <param name="Field"></param> /// <returns></returns> public static bool TryGetTypeExFromPersistentStringForm(IPexComponent host, string typename, out TypeEx typeEx) { typeEx = null; var splitarr = typename.Split(new char[] { PexMeConstants.PexMePersistenceFormSeparator }); SafeDebug.Assume(splitarr.Length == 2, "Incorrect persistent store type name"); try { bool result = TryGetTypeExFromName(host, splitarr[0], splitarr[1], out typeEx); if (typeEx == null || !result) return false; return true; } catch (Exception) { return false; } }
/// <summary> /// Retrieves the method object back from the signature /// </summary> /// <param name="typename"></param> /// <param name="methodsignature"></param> /// <returns></returns> public static bool TryGetFieldDefinition(IPexComponent host, string assemblyname, string typename, string fieldname, out FieldDefinition fielddef) { fielddef = null; TypeDefinition typeDef = null; try { bool result = TryGetTypeDefinitionFromName(host, assemblyname, typename, out typeDef); if (typeDef == null || !result) return false; } catch (Exception) { return false; } foreach (var definition in typeDef.DeclaredInstanceFields) { if (definition.FullName == fieldname) { fielddef = definition; return true; } } foreach (var definition in typeDef.DeclaredStaticFields) { if (definition.FullName == fieldname) { fielddef = definition; return true; } } return false; }