protected override IExpression ConvertMethodInvoke(IMethodInvokeExpression imie) { int methodIndex; if (analysis.IndexOfMethod.TryGetValue(imie.Method.Method, out methodIndex)) { MethodDetails methodDetails = detailsOfMethod[methodIndex]; if (!methodDetails.liveFieldsAtEndOfMethod.ContainsAll(liveFields)) { methodDetails.liveFieldsAtEndOfMethod.AddRange(liveFields); methodsToAnalyze.Add(methodIndex); } if (methodsToAnalyze.Contains(methodIndex)) { var liveFieldsAfterInvoke = (Set <IFieldDeclaration>)liveFields.Clone(); var liveVariablesAfterInvoke = (Set <IVariableDeclaration>)liveVariables.Clone(); var usedVariablesAfterInvoke = (Set <IVariableDeclaration>)usedVariables.Clone(); AnalyzeMethod(methodIndex); liveFields = liveFieldsAfterInvoke; liveVariables = liveVariablesAfterInvoke; usedVariables = usedVariablesAfterInvoke; } liveFields.AddRange(methodDetails.fieldsReadBeforeWritten); liveFields.Remove(methodDetails.fieldsWrittenBeforeRead); } return(base.ConvertMethodInvoke(imie)); }
public GraphElementSearcherDatabase AddConstructors(Type type, BindingFlags bindingFlags) { SearcherItem parent = null; foreach (ConstructorInfo constructorInfo in type.GetConstructors(bindingFlags)) { if (parent == null) { parent = SearcherItemUtility.GetItemFromPath(Items, type.FriendlyName(false)); } MethodDetails details = constructorInfo.GetMethodDetails(); parent.AddChild(new GraphNodeModelSearcherItem( new ConstructorSearcherItemData(constructorInfo), data => ((VSGraphModel)data.GraphModel).CreateFunctionCallNode( constructorInfo, data.Position, data.SpawnFlags ), details.MethodName, details.Details )); } return(this); }
/// <summary> /// Returns true if FraudFieldsShippingDetails instances are equal /// </summary> /// <param name="other">Instance of FraudFieldsShippingDetails to be compared</param> /// <returns>Boolean</returns> public bool Equals(FraudFieldsShippingDetails other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( MethodDetails == other.MethodDetails || MethodDetails != null && MethodDetails.Equals(other.MethodDetails) ) && ( MethodSpeed == other.MethodSpeed || MethodSpeed != null && MethodSpeed.Equals(other.MethodSpeed) ) && ( MethodType == other.MethodType || MethodType != null && MethodType.Equals(other.MethodType) )); }
public GraphElementSearcherDatabase AddMethods( Type type, BindingFlags bindingFlags, Dictionary <string, List <Type> > blackList = null ) { SearcherItem parent = null; foreach (MethodInfo methodInfo in type.GetMethods(bindingFlags) .Where(m => !m.IsSpecialName && m.GetCustomAttribute <ObsoleteAttribute>() == null && m.GetCustomAttribute <HiddenAttribute>() == null && !m.Name.StartsWith("get_", StringComparison.Ordinal) && !m.Name.StartsWith("set_", StringComparison.Ordinal) && !m.GetParameters().Any(p => p.ParameterType.IsByRef || p.IsOut || p.ParameterType.IsPointer) && !SearcherItemCollectionUtility.IsMethodBlackListed(m, blackList)) .OrderBy(m => m.Name)) { if (parent == null) { parent = SearcherItemUtility.GetItemFromPath(Items, type.FriendlyName(false)); } MethodDetails details = methodInfo.GetMethodDetails(); if (methodInfo.ReturnType == typeof(void)) { parent.AddChild(new StackNodeModelSearcherItem( new MethodSearcherItemData(methodInfo), data => ((StackBaseModel)data.StackModel).CreateFunctionCallNode( methodInfo, data.Index, data.SpawnFlags ), details.MethodName, details.Details )); continue; } if (!methodInfo.ReturnType.IsPointer) { parent.AddChild(new GraphNodeModelSearcherItem( new MethodSearcherItemData(methodInfo), data => ((VSGraphModel)data.GraphModel).CreateFunctionCallNode( methodInfo, data.Position, data.SpawnFlags ), details.MethodName, details.Details )); } } return(this); }
// Update(): is called once per frame void Update() { while (s_list_methodDetails.Count > 0) { MethodDetails methodDetails = s_list_methodDetails[0]; methodDetails.MethodName.Invoke(methodDetails.Instance, methodDetails.Parameters); s_list_methodDetails.RemoveAt(0); } }
public override string AddMethod(MethodDetails methodDetails, string parentHash) { var parameters = methodDetails.Parameters; StringMapper(ref parameters); Function function = new(methodDetails.Identifier, methodDetails.Modifier, string.Empty, parameters, methodDetails.ReturnType, parentHash); function.Hash = Tools.ByteToHex(Tools.GetSha256Hash(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(function)))); Memory.Add(function); return(function.Hash); }
public void CalculateMutationScore() { MutationScore.Survived = MethodDetails.SelectMany(x => x.SurvivedMutants).Count(); MutationScore.Killed = MethodDetails.SelectMany(x => x.KilledMutants).Count(); MutationScore.Uncovered = MethodDetails.SelectMany(x => x.NotCoveredMutants).Count(); MutationScore.Timeout = MethodDetails.SelectMany(x => x.TimeoutMutants).Count(); MutationScore.BuildErrors = MethodDetails.SelectMany(x => x.BuildErrorMutants).Count(); MutationScore.Skipped = MethodDetails.SelectMany(x => x.SkippedMutants).Count(); MutationScore.Covered = MethodDetails.SelectMany(x => x.CoveredMutants).Count() - MutationScore.Timeout - MutationScore.BuildErrors - MutationScore.Skipped; MutationScore.Coverage = decimal.Divide(MutationScore.Killed, MutationScore.Covered == 0 ? 1 : MutationScore.Covered); }
public GraphElementSearcherDatabase AddExtensionMethods(Type type) { Dictionary <Type, List <MethodInfo> > extensions = TypeSystem.GetExtensionMethods(Stencil.GetAssemblies()); if (!extensions.TryGetValue(type, out var methodInfos)) { return(this); } SearcherItem parent = null; foreach (MethodInfo methodInfo in methodInfos .Where(m => !m.GetParameters().Any(p => p.ParameterType.IsByRef || p.IsOut))) { if (parent == null) { parent = SearcherItemUtility.GetItemFromPath(Items, type.FriendlyName(false)); } MethodDetails details = methodInfo.GetMethodDetails(); if (methodInfo.ReturnType != typeof(void)) { parent.AddChild(new GraphNodeModelSearcherItem( new MethodSearcherItemData(methodInfo), data => ((VSGraphModel)data.GraphModel).CreateFunctionCallNode( methodInfo, data.Position, data.SpawnFlags ), details.MethodName, details.Details )); continue; } parent.AddChild(new StackNodeModelSearcherItem( new MethodSearcherItemData(methodInfo), data => ((StackBaseModel)data.StackModel).CreateFunctionCallNode( methodInfo, data.Index, data.SpawnFlags ), details.MethodName, details.Details )); } return(this); }
// Public-Static Functions /// <summary> /// Execute the method once every frame, prevents method to be called multiple times /// </summary> /// <param name="_methodString"> The method to be executed in string format </param> /// <param name="_parameters"> The array of parameters to executed with the method </param> /// <param name="_instance"> The instance of the object that the method is called upon, if the method is static, this will be ignored </param> public static bool OnceInUpdate(string _methodString, object[] _parameters, object _instance) { MethodDetails methodDetails = new MethodDetails(_methodString, _parameters, _instance); for (int i = 0; i < s_list_methodDetails.Count; i++) { if (s_list_methodDetails.Contains(methodDetails)) { return(false); } } s_list_methodDetails.Add(methodDetails); return(true); }
public GraphElementSearcherDatabase AddConstructors(IEnumerable <ConstructorInfo> constructors) { foreach (var constructor in constructors) { var parent = SearcherItemUtility.GetItemFromPath(Items, constructor.ReflectedType.FriendlyName(false)); MethodDetails details = constructor.GetMethodDetails(); parent.AddChild(new GraphNodeModelSearcherItem( new ConstructorSearcherItemData(constructor), data => data.CreateFunctionCallNode(constructor), details.MethodName )); } return(this); }
public static IInterceptor Create(dynamic data) { MethodInfo methodInfo = (MethodInfo)data; var attribute = methodInfo.GetCustomAttributes(typeof(MethodDetailLoggingAttribute), false); //string method = methodInfo.ReflectedType.FullName + "." + methodInfo.Name; MethodDetails methodDetails = new MethodDetails() { Property = "X", Stage = "both", Name = "Baz" }; return(new MethodDetailsInterceptor <TListener>(methodDetails)); }
public override void AddMethodReturnTypes(MethodDetails methodDetails, string methodHash, Func <string, string, List <string> > generateReturnTypes, List <string> modelTypes) { var mainMethodReturnType = methodDetails.ReturnType; var returnTypesList = generateReturnTypes(Constants.XOnEthereumChain, mainMethodReturnType); var xCallReturnTypes = string.Join(", ", returnTypesList.Select(returnType => returnType.ToString().CheckRequiresMemorySyntax(modelTypes))); StringMapper(ref xCallReturnTypes); Memory.ForEach(@object => { if (@object.Hash.Equals(methodHash)) { ((Function)@object).ReturnTypes = xCallReturnTypes; } }); }
public override string AddMethod(MethodDetails methodDetails, string parentHash) { var parameters = methodDetails.Parameters; StringMapper(ref parameters); var parameterAnchor = methodDetails.ParameterAnchor; StringMapper(ref parameterAnchor); Method method = new(methodDetails.Modifier, methodDetails.ReturnType, methodDetails.Identifier, parameters, parameterAnchor, parentHash); method.Hash = Tools.ByteToHex(Tools.GetSha256Hash(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(method)))); Memory.Add(method); return(method.Hash); }
public GraphElementSearcherDatabase AddMethods(IEnumerable <MethodInfo> methods) { SearcherItem parent = null; foreach (var method in methods.Where(m => !m.IsSpecialName && !m.Name.StartsWith("get_", StringComparison.Ordinal) && !m.Name.StartsWith("set_", StringComparison.Ordinal) && !m.GetParameters().Any(p => p.ParameterType.IsByRef || p.IsOut || p.ParameterType.IsPointer) && m.GetCustomAttribute <ObsoleteAttribute>() == null && m.GetCustomAttribute <HiddenAttribute>() == null)) { if (parent == null) { parent = SearcherItemUtility.GetItemFromPath(Items, method.ReflectedType.FriendlyName(false)); } MethodDetails details = method.GetMethodDetails(); if (method.ReturnType == typeof(void)) { parent.AddChild(new StackNodeModelSearcherItem( new MethodSearcherItemData(method), data => data.CreateFunctionCallNode(method), details.MethodName, details.Details )); continue; } if (!method.ReturnType.IsPointer) { parent.AddChild(new GraphNodeModelSearcherItem( new MethodSearcherItemData(method), data => data.CreateFunctionCallNode(method), details.MethodName )); } } return(this); }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { var hashCode = 41; // Suitable nullity checks etc, of course :) if (MethodDetails != null) { hashCode = hashCode * 59 + MethodDetails.GetHashCode(); } if (MethodSpeed != null) { hashCode = hashCode * 59 + MethodSpeed.GetHashCode(); } if (MethodType != null) { hashCode = hashCode * 59 + MethodType.GetHashCode(); } return(hashCode); } }
public override void AddMethodReturnTypes(MethodDetails methodDetails, string methodHash, Func <string, string, List <string> > generateReturnTypes, List <string> modelTypes) { return; }
public abstract void AddMethodReturnTypes(MethodDetails methodDetails, string methodHash, Func <string, string, List <string> > generateReturnTypes, List <string> modelTypes);
/// <summary> /// Returns documentation in standard Markdown format for the assembly at the `assemblyPath` provided. The referenced assemblie's /// generated documentation `.xml` file must be present in the same folder. /// /// ###### Usage: /// <code> /// var markdown = docBuilder.BuildDocumentation("c:\SampleAssembly.dll"); /// </code> /// </summary> /// <param name="assemblyPath">The absolute path of the assembly to document.</param> /// <returns>Markdown formated documentation</returns> public string BuildDocumentation(string assemblyPath) { List <ClassDocumentation> classDocuments = new List <ClassDocumentation>(); try { var assembly = Assembly.LoadFile(assemblyPath); var xml = XDocument.Load(assemblyPath.Replace(".dll", ".xml")); var memberInfos = xml.Descendants("member") .Select(m => new MemberInfo(m, typeName => FindType(assembly, typeName))) .ToArray(); var builder = new StringBuilder(); builder.AppendLine($"# {assembly.GetName().Name} `assembly`"); GenerateLinkTree(memberInfos, builder); foreach (var member in memberInfos.Where(m => m.Type == MemberTypes.Class)) { var relatedType = FindType(assembly, member.FullName); if (relatedType == null) { throw new Exception($"Unable to find type {member.FullName}."); } var doc = new ClassDocumentation() { Name = member.Name, Namespace = relatedType.Namespace, Summary = ConvertSummary(member.Summary), Interfaces = relatedType.GetInterfaces().Select(i => i.Name).ToArray() }; foreach (var subItem in memberInfos.Where(m => m.ParentName == member.FullName)) { DocumentationItem newItem = null; if (subItem.Type == MemberTypes.Property) { newItem = new PropertyDocumentation(); } else if (subItem.Type == MemberTypes.Function) { MethodDetails relatedMethod = subItem.GetMethod(relatedType); newItem = new MethodDocumentation() { Signature = relatedMethod.GetSignature(), ReturnType = relatedMethod.ReturnType, ReturnSummary = subItem.Returns, Arguments = relatedMethod.Arguments.Select(a => { return(new ArgumentDocumentation() { Name = a.Name, Type = a.ParameterType.Name, Required = !a.HasDefaultValue, DefaultValue = a.DefaultValue, Summary = subItem.Parameters.FirstOrDefault(p => p.Attribute("name").Value == a.Name)?.Value ?? "", }); }).ToList() }; } if (newItem != null) { newItem.Name = subItem.Name; newItem.Summary = ConvertSummary(subItem.Summary); } doc.Items.Add(newItem); } builder.AppendLine(doc.ToMarkdown()); } return(builder.ToString()); } catch (Exception e) { throw new Exception($"Unable to build documentaiton for '{assemblyPath}'. {e.Message}", e); } }
public string Test_ConvertDouble(double number) { var result = MethodDetails.ConvertDoubleToBinaryString(number); return(result); }
public MethodDef(SourceFileContext ctx, ServiceDetails svc, MethodDetails method) => (Ctx, Svc, Method) = (ctx, svc, method);
public abstract string AddMethod(MethodDetails methodDetails, string parentHash);
/// <summary> /// Return the method signature as a string. /// </summary> /// <param name="method">The Method</param> /// <param name="callable">Return as an callable string(public void a(string b) would return a(b))</param> /// <returns>Method signature</returns> public static string GetSignature(this MethodDetails method, bool callable = false) { var firstParam = true; var sigBuilder = new StringBuilder(); if (callable == false) { if (method.IsPublic) { sigBuilder.Append("public "); } else if (method.IsPrivate) { sigBuilder.Append("private "); } else if (method.IsAssembly) { sigBuilder.Append("internal "); } if (method.IsFamily) { sigBuilder.Append("protected "); } if (method.IsStatic) { sigBuilder.Append("static "); } sigBuilder.Append(method.ReturnType); sigBuilder.Append(' '); } sigBuilder.Append(method.Name); // Add method generics if (method.IsGenericMethod) { sigBuilder.Append("<"); foreach (var g in method.GenericArguments) { if (firstParam) { firstParam = false; } else { sigBuilder.Append(", "); } sigBuilder.Append(TypeName(g)); } sigBuilder.Append(">"); } sigBuilder.Append("("); firstParam = true; var secondParam = false; foreach (var param in method.Arguments) { if (firstParam) { firstParam = false; if (method.IsDefined(typeof(System.Runtime.CompilerServices.ExtensionAttribute), false)) { if (callable) { secondParam = true; continue; } sigBuilder.Append("this "); } } else if (secondParam == true) { secondParam = false; } else { sigBuilder.Append(", "); } if (param.ParameterType.IsByRef) { sigBuilder.Append("ref "); } else if (param.IsOut) { sigBuilder.Append("out "); } if (!callable) { sigBuilder.Append(TypeName(param.ParameterType)); sigBuilder.Append(' '); } sigBuilder.Append(param.Name); } sigBuilder.Append(")"); return(sigBuilder.ToString()); }
public MethodDef(SourceFileContext ctx, string ns, MethodDetails methodDetails) => (Ctx, Namespace, MethodDetails) = (ctx, ns, methodDetails);
// Public-Static Functions /// <summary> /// Execute the method once every frame, prevents method to be called multiple times /// </summary> /// <param name="_methodString"> The method to be executed in string format </param> /// <param name="_parameters"> The array of parameters to executed with the method </param> /// <param name="_instance"> The instance of the object that the method is called upon, if the method is static, this will be ignored </param> public static bool OnceInUpdate(string _methodString, object[] _parameters, object _instance) { MethodDetails methodDetails = new MethodDetails(_methodString, _parameters, _instance); for (int i = 0; i < s_list_methodDetails.Count; i++) { if (s_list_methodDetails.Contains(methodDetails)) return false; } s_list_methodDetails.Add(methodDetails); return true; }