public object Read(Type returnType, AccessorTypeDeclaration accessorTypeDeclaration, AccessorFieldDeclaration accessorFieldDeclaration) { var commandlineName = GetCommandlineName(accessorTypeDeclaration, accessorFieldDeclaration); var args = GetCommandlineArguments(); string val = null; for (var i = 0; i < args.Length; i++) { if (args[i] == commandlineName && i + 1 < args.Length) { val = args[i + 1]; break; } if (args[i].StartsWith($"{commandlineName}=")) { val = args[i].Substring($"{commandlineName}=".Length); break; } } if (val == null) { return(null); } return(Convert.ChangeType(val, returnType)); }
public string Format(AccessorTypeDeclaration typeDeclaration, AccessorFieldDeclaration fieldDeclaration) { var data = XmlFileAccessor.GetPropertyData(typeDeclaration, fieldDeclaration); var exampleValue = ""; if (fieldDeclaration.Type == typeof(int)) { exampleValue = "integer"; } else if (fieldDeclaration.Type == typeof(string)) { exampleValue = "string"; } var result = $@" <h3>{Title}</h3> <div class=""registry""> <pre><code>{data.FilePath} XPath: {data.XmlRootPath} ValuePath: {data.XmlValuePath} Type: {exampleValue} </code></pre> </div>"; return(result); }
public string Format(AccessorTypeDeclaration typeDeclaration, AccessorFieldDeclaration fieldDeclaration) { var data = RegistoryAccessor.GetPropertyData( _root, typeDeclaration, fieldDeclaration); var exampleValue = ""; if (fieldDeclaration.Type == typeof(int)) { exampleValue = "dword:(Value)"; } else if (fieldDeclaration.Type == typeof(string)) { exampleValue = "text:(Value)"; } var result = $@" <h3>{Title}</h3> <div class=""registry""> <pre><code>[{data.Key}] ""{data.ValueName}""={exampleValue}</code></pre> </div>"; return(result); }
public object Read(Type returnType, AccessorTypeDeclaration accessorTypeDeclaration, AccessorFieldDeclaration accessorFieldDeclaration) { var defaultValueAttribute = accessorFieldDeclaration.GetAttribute <DefaultValueAttribute>(); if (defaultValueAttribute == null) { throw new DataNotFoundException(); } return(Convert.ChangeType(defaultValueAttribute.DefaultValue, returnType)); }
public object Read(Type returnType, AccessorTypeDeclaration accessorTypeDeclaration, AccessorFieldDeclaration accessorFieldDeclaration) { var environmentVariableName = GetEnvironmentVariableName(accessorTypeDeclaration, accessorFieldDeclaration); var val = Environment.GetEnvironmentVariable(environmentVariableName); if (val == null) { throw new DataNotFoundException(); } return(Convert.ChangeType(val, returnType)); }
public object Read(Type returnType, AccessorTypeDeclaration accessorTypeDeclaration, AccessorFieldDeclaration accessorFieldDeclaration) { var propertyData = GetPropertyData(accessorTypeDeclaration, accessorFieldDeclaration); if (File.Exists(propertyData.FilePath) == false) { return(false); } var doc = XDocument.Load(propertyData.FilePath); var root = doc.XPathSelectElement(propertyData.XmlRootPath); var element = root?.XPathSelectElement(propertyData.XmlValuePath); return(element == null ? null : Convert.ChangeType(element.Value, returnType)); }
public object Read(Type returnType, AccessorTypeDeclaration accessorTypeDeclaration, AccessorFieldDeclaration accessorFieldDeclaration) { var data = GetPropertyData(_registryRoot, accessorTypeDeclaration, accessorFieldDeclaration); using (var registrykey = _registryRoot == RegistryRoot.LocalMachine ? Registry.LocalMachine.OpenSubKey(data.Key) : Registry.CurrentUser.OpenSubKey(data.Key)) { if (registrykey?.GetValueNames().All(_ => _ != data.ValueName) ?? true) { return(null); } return(Convert.ChangeType(registrykey.GetValue(data.ValueName), returnType)); } }
private static string GetCommandlineName(AccessorTypeDeclaration accessorTypeDeclaration, AccessorFieldDeclaration accessorFieldDeclaration) { var interfaceName = accessorTypeDeclaration.TargetInterfaceType.Name; var commandlineArgumentPrefixAttribute = accessorTypeDeclaration.GetAttribute <CommandlineArgumentPrefixAttribute>(); var prefix = commandlineArgumentPrefixAttribute?.Prefix ?? interfaceName; var commandlineArgumentNameAttribute = accessorFieldDeclaration.GetAttribute <CommandlineArgumentNameAttribute>(); var name = string.IsNullOrEmpty(commandlineArgumentNameAttribute?.Name) ? accessorFieldDeclaration.Name : commandlineArgumentNameAttribute.Name; return(prefix == "" ? $"--{name}" : $"--{prefix}_{name}"); }
private static string GetEnvironmentVariableName(AccessorTypeDeclaration accessorTypeDeclaration, AccessorFieldDeclaration accessorFieldDeclaration) { var assemblyName = accessorTypeDeclaration.TargetInterfaceType.Assembly.GetName().Name; var interfaceName = accessorTypeDeclaration.TargetInterfaceType.Name; var environmentVariablePrefixAttribute = accessorTypeDeclaration.GetAttribute <EnvironmentVariablePrefixAttribute>(); var prefix = environmentVariablePrefixAttribute?.Prefix ?? $@"{assemblyName}_{interfaceName}"; var environmentVariableNameAttribute = accessorFieldDeclaration.GetAttribute <EnvironmentVariableNameAttribute>(); var name = string.IsNullOrEmpty(environmentVariableNameAttribute?.Name) ? accessorFieldDeclaration.Name : environmentVariableNameAttribute.Name; return(string.IsNullOrEmpty(prefix) ? name : $"{prefix}_{name}"); }
public string Format(AccessorTypeDeclaration typeDeclaration, AccessorFieldDeclaration fieldDeclaration) { var data = CommandlineArgumentsAccessor.GetPropertyData(typeDeclaration, fieldDeclaration); var exampleValue = ""; if (fieldDeclaration.Type == typeof(int)) { exampleValue = "(integer)"; } else if (fieldDeclaration.Type == typeof(string)) { exampleValue = "(string)"; } var result = $@" <h3>{Title}</h3> <div class=""commandline""> <pre><code> {data.CommandlineArgumentName}={exampleValue} </code></pre> </div>"; return(result); }
public bool Exists(Type fieldType, AccessorTypeDeclaration accessorTypeDeclaration, AccessorFieldDeclaration accessorFieldDeclaration) { var propertyData = GetPropertyData(accessorTypeDeclaration, accessorFieldDeclaration); if (File.Exists(propertyData.FilePath) == false) { return(false); } var doc = XDocument.Load(propertyData.FilePath); var root = doc.XPathSelectElement(propertyData.XmlRootPath); var element = root?.XPathSelectElement(propertyData.XmlValuePath); return(element != null); }
public bool Exists(Type fieldType, AccessorTypeDeclaration accessorTypeDeclaration, AccessorFieldDeclaration accessorFieldDeclaration) { return(accessorFieldDeclaration.Name == "AssemblyName"); }
public SummaryPropertyReportData(AccessorFieldDeclaration fieldDeclaration, string description) { FieldDeclaration = fieldDeclaration; Description = description; }
internal static CommandlineArgumentsAccessorReportData GetPropertyData(AccessorTypeDeclaration accessorTypeDeclaration, AccessorFieldDeclaration field) { var name = GetCommandlineName(accessorTypeDeclaration, field); return(new CommandlineArgumentsAccessorReportData(name)); }
public PropertyReportData(AccessorTypeDeclaration accessorTypeDeclaration, AccessorFieldDeclaration accessorFieldDeclaration, string description) { AccessorTypeDeclaration = accessorTypeDeclaration; FieldDeclaration = accessorFieldDeclaration; Description = description; }
public object Read(Type returnType, AccessorTypeDeclaration accessorTypeDeclaration, AccessorFieldDeclaration accessorFieldDeclaration) { if (accessorFieldDeclaration.Name == "AssemblyName") { return(Assembly.GetExecutingAssembly().GetName().Name); } throw new DataNotFoundException(); }
public static DefaultValueAccessorReportData GetPropertyData(AccessorTypeDeclaration accessorTypeDeclaration, AccessorFieldDeclaration accessorFieldDeclaration) { var defaultValueAttribute = accessorFieldDeclaration.GetAttribute <DefaultValueAttribute>(); if (defaultValueAttribute == null) { throw new DataNotFoundException(); } return(new DefaultValueAccessorReportData(defaultValueAttribute.DefaultValue)); }
public static XmlFileAccessorReportData GetPropertyData(AccessorTypeDeclaration accessorTypeDeclaration, AccessorFieldDeclaration accessorFieldDeclaration) { var xmlFileAttribute = accessorTypeDeclaration.GetAttribute <XmlFileAttribute>(); var filePath = Path.Combine( Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? throw new InvalidOperationException(), string.IsNullOrEmpty(xmlFileAttribute?.FilePath) ? @".\ApplicationRegisties.xml" : xmlFileAttribute.FilePath); var xrootPath = string.IsNullOrEmpty(xmlFileAttribute?.XRootPath) ? "/ApplicationRegisties/" + accessorTypeDeclaration.Name : xmlFileAttribute.XRootPath; var xmlNameAttribute = accessorFieldDeclaration.GetAttribute <XmlNameAttribute>(); var xPath = string.IsNullOrEmpty(xmlNameAttribute?.XPath) ? accessorFieldDeclaration.Name : xmlNameAttribute.XPath; return(new XmlFileAccessorReportData(filePath, xrootPath, xPath)); }
public bool Exists(Type fieldType, AccessorTypeDeclaration accessorDeclaration, AccessorFieldDeclaration accessorFieldDeclaration) { throw new NotImplementedException(); }
public bool Exists(Type fieldType, AccessorTypeDeclaration accessorTypeDeclaration, AccessorFieldDeclaration accessorFieldDeclaration) { var environmentVariableName = GetEnvironmentVariableName(accessorTypeDeclaration, accessorFieldDeclaration); var val = Environment.GetEnvironmentVariable(environmentVariableName); return(val != null); }
public static EnvironmentVariableAccessorReportData GetPropertyData(AccessorTypeDeclaration accessorTypeDeclaration, AccessorFieldDeclaration accessorFieldDeclaration) { return(new EnvironmentVariableAccessorReportData(GetEnvironmentVariableName(accessorTypeDeclaration, accessorFieldDeclaration))); }
public bool Exists(Type fieldType, AccessorTypeDeclaration accessorTypeDeclaration, AccessorFieldDeclaration accessorFieldDeclaration) { var defaultValueAttribute = accessorFieldDeclaration.GetAttribute <DefaultValueAttribute>(); return(defaultValueAttribute != null); }
public static RegistryAccessorReportData GetPropertyData(RegistryRoot registryRoot, AccessorTypeDeclaration accessorTypeDeclaration, AccessorFieldDeclaration accessorFieldDeclaration) { var assemblyName = accessorTypeDeclaration.TargetInterfaceType.Assembly.GetName().Name; var interfaceName = accessorTypeDeclaration.TargetInterfaceType.Name; var registoKeyAttribute = accessorTypeDeclaration.GetAttribute <RegistryKeyAttribute>(); var key = string.IsNullOrEmpty(registoKeyAttribute?.Key) ? $@"Software\ApplicationRegistries\{assemblyName}\{interfaceName}" : registoKeyAttribute.Key; var registoNameAttribute = accessorFieldDeclaration.GetAttribute <RegistryNameAttribute>(); var name = string.IsNullOrEmpty(registoNameAttribute?.Name) ? accessorFieldDeclaration.Name : registoNameAttribute.Name; return(new RegistryAccessorReportData(key, name )); }
public string Format(AccessorTypeDeclaration typeDeclaration, AccessorFieldDeclaration fieldDeclaration) { return("<h3>Custom Settings</h3>"); }
public bool Exists(Type fieldType, AccessorTypeDeclaration accessorTypeDeclaration, AccessorFieldDeclaration field) { var commandlineName = GetCommandlineName(accessorTypeDeclaration, field); var args = GetCommandlineArguments(); for (var i = 0; i < args.Length; i++) { if (args[i] == commandlineName && i + 1 < args.Length) { return(true); } if (args[i].StartsWith($"{commandlineName}=")) { return(true); } } return(false); }
public bool Exists(Type fieldType, AccessorTypeDeclaration accessorTypeDeclaration, AccessorFieldDeclaration accessorFieldDeclaration) { var data = GetPropertyData(_registryRoot, accessorTypeDeclaration, accessorFieldDeclaration); using (var registrykey = _registryRoot == RegistryRoot.LocalMachine ? Registry.LocalMachine.OpenSubKey(data.Key) : Registry.CurrentUser.OpenSubKey(data.Key)) { if (registrykey?.GetValueNames().All(_ => _ != data.ValueName) ?? true) { return(false); } } return(true); }
public object Read(Type returnType, AccessorTypeDeclaration accessorDeclaration, AccessorFieldDeclaration accessorFieldDeclaration) { throw new NotImplementedException(); }
private static string GetDescription(AccessorTypeDeclaration accessorTypeDeclaration, AccessorFieldDeclaration accessorFieldDeclaration, XElement xDoc) { if (xDoc == null) { return(""); } var summaryElements = xDoc.XPathSelectElements( "/members/member/summary"); return(summaryElements.FirstOrDefault(_ => _?.Parent?.Attribute("name")?.Value == $"P:{accessorTypeDeclaration.TargetInterfaceType.FullName}.{accessorFieldDeclaration.Name}")?.Value ?? ""); }
public string FormatProperty(AccessorTypeDeclaration accessorTypeDeclaration, AccessorFieldDeclaration accessorFieldDeclaration, string key) { var formatter = PropertyFormatters.First(_ => _.Key == key); return(formatter.Format(accessorTypeDeclaration, accessorFieldDeclaration)); }