public GenericClassSerializationInfo Create(TypeDefinition definition) { var messagePackAttribute = definition.CustomAttributes.SingleOrDefault(CustomAttributeHelper.IsMessagePackObjectAttribute); if (messagePackAttribute is null) { throw new MessagePackGeneratorResolveFailedException("invalid generic class type. type : " + definition.FullName); } var variations = finder.Find(definition).ToArray(); var customFormatter = definition.CustomAttributes.SingleOrDefault(CustomAttributeHelper.IsMessagePackFormatterAttribute); if (!(customFormatter is null)) { return(new GenericClassSerializationInfo(definition, CustomFormatterDetector.Detect(definition, customFormatter), variations)); } CustomAttributeHelper.IsMessagePackObjectAttribute(messagePackAttribute, out var isKeyAsPropertyName); var fieldInfos = MessagePackObjectHelper.CollectFieldInfos(definition, false); var propertyInfos = MessagePackObjectHelper.CollectPropertyInfos(definition, isKeyAsPropertyName); var(minIntKey, maxIntKey) = MessagePackObjectHelper.FindMinMaxIntKey(fieldInfos, propertyInfos); return(new GenericClassSerializationInfo(definition, fieldInfos, propertyInfos, minIntKey, maxIntKey, variations)); }
public CustomAttributeTreeNode(CustomAttributeDeclaration customAttribute) : base(customAttribute, TreeViewImage.CustomAttribute) { StringBuilder name = new StringBuilder(256); name.Append(CustomAttributeHelper.Render(customAttribute)); this.Text = name.ToString(); }
internal static void SetHiddenAttribute(TypeBuilder tb) { if (s_HiddenCABuilder == null) { s_HiddenCABuilder = CustomAttributeHelper.GetBuilderForTypeLibType(TypeLibTypeFlags.FHidden); } tb.SetCustomAttribute(s_HiddenCABuilder); }
internal static void SetClassInterfaceTypeToNone(TypeBuilder tb) { // Create the ClassInterface(ClassInterfaceType.None) CA builder if we haven't created it yet. if (s_NoClassItfCABuilder == null) { s_NoClassItfCABuilder = CustomAttributeHelper.GetBuilderForClassInterface(ClassInterfaceType.None); } // Set the class interface type to none. tb.SetCustomAttribute(s_NoClassItfCABuilder); }
/// <summary> /// Create an api element /// </summary> /// <param name="api">Description of the api via the ApiExplorer</param> /// <returns>A resource api</returns> public static ResourceApi CreateResourceApi(ApiDescription api) { ResourceApi rApi = new ResourceApi() { path = "/" + api.RelativePath, description = DocsService.GetXmlFromType(api.ActionDescriptor.ControllerDescriptor.ControllerType, false).InnerText, operations = new List <ResourceApiOperation>() }; CustomAttributeHelper.PrepareByOptionAttribute(rApi, api.ActionDescriptor); return(rApi); }
private IList <System.Reflection.PropertyInfo> GetGetPropertiesByAttrSkipFiliter(Type type) { var props = TypePropertiesCacheHelper.GetTypePropertiesCache(type); _customAttributes = CustomAttributeHelper.GetCustomAttributes(type); if (_customAttributes.FirstOrDefault() != null) { _customAttributes = _customAttributes.Where(attr => attr.Skip == false); var notSkipAttrsName = _customAttributes.Select(attr => attr.memberInfo.Name); props = props.Where(prop => notSkipAttrsName.Contains(prop.Name)).ToArray(); } return(props); }
public void NArgAttribute_ProtectedCopyConstructorWorkWithValidValues_DoesNotThrow() { object nattr = CustomAttributeHelper.GetCustomPropertiesFromMember <AttributeTests, NArgAttribute>( "NArgAttribute_ProtectedCopyConstructorWorkWithValidValues_DoesNotThrow"); GoodInheritFromNArgAttribute good = new GoodInheritFromNArgAttribute((NArgAttribute)nattr); Assert.That(good.AltName, Is.EqualTo("somethingelse")); Assert.That(good.IsOptional, Is.True); Assert.That(good.Rank, Is.EqualTo(5)); Assert.That(good.AllowedValues, Is.EqualTo(new string[] { "1", "2", "3" })); Assert.That(good.OptionalArgName, Is.EqualTo("avalue")); }
public void GenerateObjectCode(object o, string prevVarName, int level) { if (writeSimple(o)) { return; } Type t = o.GetType(); if (CustomAttributeHelper.Has <CodegenAsXmlAttribute>(t)) { StringWriter xml = new StringWriter(); using (XmlTextWriter tw = new XmlTextWriter(xml)) ((IXsElement)o).WriteXml(tw, null); MainCode.Write("new " + _re.GetTypeName(t) + "(@\"" + xml.ToString().Replace("\"", "\"\"") + "\")"); return; } // On the fly replace Code with CompiledCode Code originalCode = null; if (t == typeof(Code)) { if (((Code)o).Dynamic == false) { originalCode = (Code)o; string className = originalCode.GetClassName(); if (!_generated.ContainsKey(className)) { SnippetsCode.WriteLine(); SnippetsCode.WriteLine(originalCode.GenerateSourceCode(ScriptContextScope.Current, (_options & GeneratorOptions.IncludeSource) != 0, false)); SnippetsCode.WriteLine(); _generated[className] = true; } o = new CompiledCode(originalCode); } } if (_re.MaxAvailableNETVersion >= new Version(3, 5) && (_options & GeneratorOptions.ForceNet20) == 0) { graphSaveNET35(o, originalCode, level); } else { graphSaveNET20(o, prevVarName, originalCode, level); } }
/// <summary> /// Get the resource description of the api for swagger documentation /// </summary> /// <remarks>It is very convenient to have this information available for generating clients. This is the entry point for the swagger UI /// </remarks> /// <returns>JSON document representing structure of API</returns> public HttpResponseMessage Get() { //var formatter = RequestContext.Configuration.Formatters.JsonFormatter; //formatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); var docProvider = (XmlCommentDocumentationProvider)GlobalConfiguration.Configuration.Services.GetDocumentationProvider(); ResourceListing r = SwaggerGen.CreateResourceListing(ControllerContext); List <string> uniqueControllers = new List <string>(); foreach (var api in GlobalConfiguration.Configuration.Services.GetApiExplorer().ApiDescriptions) { if (!CustomAttributeHelper.HasIgnoreAttribute(api.ActionDescriptor.ControllerDescriptor) && ResourcesConfiguration.IsResourceMapped(api.ActionDescriptor.ControllerDescriptor)) { string controllerName = api.ActionDescriptor.ControllerDescriptor.ControllerName; if (uniqueControllers.Contains(controllerName) || controllerName.ToUpper().Equals(SwaggerGen.SWAGGER.ToUpper())) { continue; } uniqueControllers.Add(controllerName); ResourceApi rApi = SwaggerGen.CreateResourceApi(api); var queryIndex = rApi.path.IndexOf("?"); if (queryIndex > -1) { rApi.path = rApi.path.Substring(0, queryIndex); } r.AddApi(rApi); // Model foreach (var param in api.ParameterDescriptions) { r.Models.AddRange(SwaggerGen.CreateResourceModel(param, docProvider)); } } } HttpResponseMessage resp = new HttpResponseMessage(); resp.Content = new ObjectContent <ResourceListing>(r, ControllerContext.Configuration.Formatters.JsonFormatter); return(resp); }
public string ToHtmlTableByProperties <T>(IEnumerable <T> enums) { var firstData = enums.FirstOrDefault(); //done: First use type with GetType func then type with typeof var type = firstData != null ? firstData.GetType() : typeof(T); var props = GetPropertiesByAttrSkipFiliter(type); #region Check if (props.Count == 0) { throw new Exception("At least one Property"); } #endregion //Head var thead = new StringBuilder(); foreach (var p in props) { var costomAtt = CustomAttributeHelper.GetCustomAttributeByProperty(_customAttributes, p); string thInnerHTML = costomAtt != null ? costomAtt.DisplayName : Encode(p.Name); thead.Append($"<th{_ThAttHtml}>{thInnerHTML}</th>"); } //Body var tbody = new StringBuilder(); foreach (var e in enums) { tbody.Append($"<tr{_TrAttHtml}>"); foreach (var prop in props) { var value = prop.GetToStringValue(e); string tdInnerHTML = Encode(value); tbody.Append($"<td{_TdAttHtml}>{tdInnerHTML}</td>"); } tbody.Append("</tr>"); } //Table html var html = RenderHtmlTable(thead, tbody); return(html.ToString()); }
public List <Municipality> GetAll() { var result = new List <Municipality>(); var enumValues = Enum.GetValues(typeof(MunicipalityFeatureEnum)); foreach (MunicipalityFeatureEnum val in enumValues) { if (val != MunicipalityFeatureEnum.Undefined) { result.Add(new Municipality { Name = CustomAttributeHelper.GetEnumDisplayValue(val) }); } } return(result.OrderBy(x => x.Name).ToList()); }
public List <Province> GetAll() { var result = new List <Province>(); var enumValues = Enum.GetValues(typeof(ProvinceFeatureEnum)); foreach (ProvinceFeatureEnum val in enumValues) { if (val != ProvinceFeatureEnum.Undefined) { result.Add(new Province { Name = CustomAttributeHelper.GetEnumDisplayValue(val) }); } } return(result); }
public List <Stage> GetAll() { var result = new List <Stage>(); var enumValues = Enum.GetValues(typeof(StageEnum)); foreach (StageEnum val in enumValues) { if (val != StageEnum.Undefined) { result.Add(new Stage { Id = (int)val, Name = CustomAttributeHelper.GetEnumDisplayValue(val), }); } } return(result.OrderBy(x => x.Name).ToList()); }
/// <summary> /// Creates an operation parameter /// </summary> /// <param name="api">Description of the api via the ApiExplorer</param> /// <param name="param">Description of a parameter on an operation via the ApiExplorer</param> /// <param name="docProvider">Access to the XML docs written in code</param> /// <returns>An operation parameter</returns> public static ResourceApiOperationParameter CreateResourceApiOperationParameter(ApiDescription api, ApiParameterDescription param, XmlCommentDocumentationProvider docProvider) { string paramType = (param.Source.ToString().Equals(FROMURI)) ? QUERY : BODY; var parameter = new ResourceApiOperationParameter() { paramType = (paramType == "query" && api.RelativePath.IndexOf("{" + param.Name + "}") > -1) ? PATH : paramType, name = param.Name, description = param.Documentation, dataType = TypeParser.Parse(param.ParameterDescriptor.ParameterType), required = docProvider.GetRequired(param.ParameterDescriptor) }; parameter.allowMultiple = parameter.dataType.StartsWith("List["); parameter.allowableValues = CreateAllowableValues(param.ParameterDescriptor.ParameterType); CustomAttributeHelper.PrepareByOptionAttribute(parameter, param.ParameterDescriptor); return(parameter); }
protected IEnumerable <DynamicExcelColumn> GetExcelColumns <T>() where T : class { var columns = new List <DynamicExcelColumn>(); var dataTypeProperties = typeof(T).GetProperties(); dataTypeProperties.ToList().ForEach(x => { columns.Add(new DynamicExcelColumn { Name = CustomAttributeHelper.GetColumnName(x), Width = CustomAttributeHelper.GetColumnWidth(x), FontSize = CustomAttributeHelper.GetFontSize(x), HeaderBackgroundColor = CustomAttributeHelper.GetHeaderBackgroundColor(x), HeaderFontColor = CustomAttributeHelper.GetHeaderFont(x), Alignment = CustomAttributeHelper.GetColumnAlignment(x) }); }); return(columns); }
private ResourceListing GetDocs(HttpActionContext actionContext) { CollectApiDescriptions(); var resourceListing = SwaggerGen.CreateResourceListing(actionContext); var apis = GetApiDescriptionsByController(actionContext.ControllerContext.ControllerDescriptor.ControllerName); foreach (var api in apis) { if (ResourcesConfiguration.IsOperationMapped(api)) { var resourceApi = SwaggerGen.CreateResourceApi(api); resourceListing.AddApi(resourceApi); ResourceApiOperation resourceApiOperation = null; if (!CustomAttributeHelper.HasIgnoreAttribute(api.ActionDescriptor)) { resourceApiOperation = SwaggerGen.CreateResourceApiOperation(api, DocProvider); resourceApi.operations.Add(resourceApiOperation); } var reflectedActionDescriptor = api.ActionDescriptor as ReflectedHttpActionDescriptor; resourceListing.Models.AddRange(SwaggerGen.CreateResourceModel(reflectedActionDescriptor.MethodInfo.ReturnType, DocProvider)); foreach (var param in api.ParameterDescriptions) { if (resourceApiOperation != null) { ResourceApiOperationParameter parameter = SwaggerGen.CreateResourceApiOperationParameter(api, param, DocProvider); resourceApiOperation.parameters.Add(parameter); } resourceListing.Models.AddRange(SwaggerGen.CreateResourceModel(param, DocProvider)); } } } return(resourceListing); }
private static XmlSchema generateSchema(ScriptContext context) { // Ensure that all objects are from one namespace string ns = null; foreach (var type in context.GetKnownTypes()) { var na = (CustomAttributeHelper.First <XsTypeAttribute>(type)); if (na == null) { continue; } if (ns == null && na.Namespace != ScriptActionBase.XSharperNamespace) { ns = na.Namespace; } else if (ns != na.Namespace && na.Namespace != ScriptActionBase.XSharperNamespace) { context.Info.WriteLine("Warning: Object " + na.Name + " has unexpected namespace " + na.Namespace + ". All types must use the same namespace."); } } if (ns == null) { ns = ScriptActionBase.XSharperNamespace; } var xmlSchema = XsXsdGenerator.BuildSchema(ns, context.GetKnownTypes(), typeof(Script), new Type[] { typeof(IScriptAction) }); xmlSchema.Id = ns == ScriptActionBase.XSharperNamespace ? "xsharper" : "custom"; // Compile it, just to make sure it's valid XmlSchemaSet s = new XmlSchemaSet(); s.Add(xmlSchema); s.Compile(); return(xmlSchema); }
private static PropertyInfo[] getPropertiesToSave(object o) { List <PropertyInfo> ret = new List <PropertyInfo>(); Type t = o.GetType(); var def = Utils.CreateInstance(t); foreach (var pi in t.GetProperties(BindingFlags.Public | BindingFlags.Default | BindingFlags.Instance | BindingFlags.FlattenHierarchy)) { if (pi.PropertyType != typeof(ExecutableScriptBase)) { if (!CustomAttributeHelper.Has <XsElementAttribute>(pi) && XsAttributeAttribute.GetNames(pi, false) == null) { continue; } object propValue = pi.GetValue(o, null); var ea = CustomAttributeHelper.First <XsElementAttribute>(pi); if (ea != null && ea.SkipIfEmpty && ea.IsEmpty(propValue)) { continue; } // References are supposed to be resolved during initialization, they're not included into executable if (pi.Name == "From" && o is Reference && !((Reference)o).Dynamic) { continue; } if (propValue == null || propValue.Equals(pi.GetValue(def, null))) { if (pi.PropertyType != typeof(ExecutableScriptBase)) { continue; } } } ret.Add(pi); } return(ret.ToArray()); }
public string ToHtmlTableByProperties <T>(IEnumerable <T> enums) { var type = typeof(T); var props = GetGetPropertiesByAttrSkipFiliter(type); #region Check if (props.Count == 0) { throw new Exception("At least one Property"); } #endregion //Head var thead = new StringBuilder(); foreach (var p in props) { var costomAtt = CustomAttributeHelper.GetCustomAttributeByProperty(_customAttributes, p); string thInnerHTML = costomAtt != null ? costomAtt.DisplayName : Encode(p.Name); thead.Append($"<th>{thInnerHTML}</th>"); } //Body var tbody = new StringBuilder(); foreach (var e in enums) { tbody.Append($"<tr{_TrAttHtml}>"); foreach (var prop in props) { var value = TypePropertiesCacheHelper.GetValueFromExpressionCache(type, prop, e); string tdInnerHTML = Encode(value); tbody.Append($"<td{_TdAttHtml}>{tdInnerHTML}</td>"); } tbody.Append("</tr>"); } //Table html var html = RenderHtmlTable(thead, tbody); return(html.ToString()); }
public static int Help(ScriptContext context, UsageGenerator usage, CommandLineParameters xsParams) { context.WriteLine(OutputType.Bold, GetLogo(context)); context.WriteLine(); var command = context.GetStr(xs.help, null); if (!string.IsNullOrEmpty(command)) { var tt = new Dictionary <string, Type>(StringComparer.OrdinalIgnoreCase); tt["param"] = typeof(CommandLineParameter); tt["versionInfo"] = typeof(VersionInfo); tt["usage"] = typeof(UsageGenerator); foreach (var s in context.GetKnownTypes()) { foreach (var at in CustomAttributeHelper.All <XsTypeAttribute>(s)) { if (!string.IsNullOrEmpty(at.Name)) { tt[at.Name] = s; } } } Type type; if (tt.TryGetValue(command, out type)) { writeCommandHelp(context, type, usage.CorrectWidth(-1)); return(-2); } if (command == "*") { List <Var> v = new List <Var>(); v.Add(new Var("param", getDescr(typeof(CommandLineParameter)))); v.Add(new Var("versioninfo", getDescr(typeof(VersionInfo)))); v.Add(new Var("usage", getDescr(typeof(UsageGenerator)))); foreach (var s in context.GetKnownTypes()) { var xst = CustomAttributeHelper.First <XsTypeAttribute>(s); if (xst == null || string.IsNullOrEmpty(xst.Name)) { continue; } v.Add(new Var(xst.Name, getDescr(s))); } v.Sort((a, b) => string.Compare(a.Name, b.Name)); v.Insert(0, new Var("Actions:", null)); v.Insert(1, new Var("", null)); Utils.WrapTwoColumns(context.Out, v, 30, usage.CorrectWidth(-1)); return(-2); } if (command.StartsWith(".", StringComparison.Ordinal)) { bool success = false; foreach (var nn in ((IEvaluationContext)context).GetNonameObjects()) { success = writeTypeHelp(context, nn.Type, new StringFilter(command.Substring(1)), usage.CorrectWidth(-1)) || success; } if (!success) { context.Error.WriteLine("Cannot find method '" + command + "'. "); } return(-2); } Type t = context.FindType(command); if (t == null) { t = context.FindType("XS." + command); } if (t != null) { writeTypeHelp(context, t, null, usage.CorrectWidth(-1)); } else if (command.Contains("?") || command.Contains("*")) { var r = Utils.WildcardToRegex(command, RegexOptions.IgnoreCase); foreach (var a in AppDomain.CurrentDomain.GetAssemblies()) { foreach (var ttt in a.GetTypes()) { if (ttt != null && ttt.IsPublic && (r.IsMatch(ttt.Name) || r.IsMatch(Dump.GetFriendlyTypeName(ttt)))) { context.WriteLine(Dump.GetFriendlyTypeName(ttt, true)); } } } } else { context.Error.WriteLine("Cannot find command or type '" + command + "'. Use //help * to display the list of commands"); } } else { context.WriteLine(usage.GetUsage(context, null, null, -1, xsParams)); } return(-2); }
private static void writeCommandHelp(ScriptContext context, Type commandType, int width) { var desc = (DescriptionAttribute[])commandType.GetCustomAttributes(typeof(DescriptionAttribute), false); XsTypeAttribute xst = ((XsTypeAttribute[])commandType.GetCustomAttributes(typeof(XsTypeAttribute), false))[0]; string desct = (desc.Length == 0) ? commandType.FullName : desc[0].Description; context.Bold.WriteLine(xst.Name + " (" + commandType.FullName + ")"); context.WriteLine(Utils.Wrap(desct, width, string.Empty)); context.WriteLine(); bool hasValue = false; string hasValueName = null; var def = Utils.CreateInstance(commandType); for (int required = 1; required >= 0; required--) { List <Var> v = new List <Var>(); foreach (var p in commandType.GetProperties(BindingFlags.Public | BindingFlags.SetProperty | BindingFlags.Instance)) { var aa = XsAttributeAttribute.GetNames(p, false); if (aa == null) { continue; } // If more than 1 are returned, choose the preferred one string ba = null; var hs = false; foreach (var attribute in aa) { if (attribute.Length > 0 && ba == null) { ba = attribute; } if (attribute.Length == 0) { hasValue = true; hs = true; } } if (ba == null) { ba = aa[0]; } if (hasValue && hs) { hasValueName = ba; } if (CustomAttributeHelper.Has <XsRequiredAttribute>(p) != (required == 1)) { continue; } var type = p.PropertyType; string dv = null; string typeName; StringBuilder d = new StringBuilder(); var dd = CustomAttributeHelper.First <DescriptionAttribute>(p); if (dd != null) { d.Append(dd.Description); } if (type == typeof(bool)) { typeName = "bool"; dv = "false"; } else if (type == typeof(int)) { typeName = "int"; dv = "0"; } else if (type == typeof(object)) { typeName = CustomAttributeHelper.Has <XsNotTransformed>(p)?"object":"object*"; dv = "null"; } else if (type == typeof(string)) { typeName = CustomAttributeHelper.Has <XsNotTransformed>(p) ? "string" : "string*"; dv = "null"; } else if (type.IsEnum) { typeName = Dump.GetFriendlyTypeName(type); bool f = true; if (d.Length > 0) { d.Append(". "); } d.Append("Values: "); foreach (var s1 in Enum.GetNames(type)) { if (!f) { d.Append(CustomAttributeHelper.Has <FlagsAttribute>(type) ? " | " : " / "); } f = false; d.Append(Utils.LowercaseFirstLetter(s1)); } } else { typeName = Dump.GetFriendlyTypeName(type); } string vn = ba.PadRight(20, ' '); vn += typeName.PadRight(10, ' '); if (required == 0) { if (d.Length > 0) { d.Append(" "); } d.Append("(default: "); var ddd = p.GetValue(def, null); if (type == typeof(string) && (ddd != null || dv != "null")) { d.Append("'" + (ddd ?? dv) + "'"); } else if (type.IsEnum) { d.Append(Utils.LowercaseFirstLetter((ddd ?? dv).ToString())); } else { d.Append(ddd ?? dv); } d.Append(")"); } v.Add(new Var(" " + vn, d.ToString())); } v.Sort((a, b) => string.Compare(a.Name, b.Name)); if (v.Count == 0) { continue; } context.Bold.WriteLine((required == 1) ? "Required attributes:" : "Optional attributes:"); Utils.WrapTwoColumns(context.Out, v, 35, width); context.Out.WriteLine(); } //z1.Sort((a, b) => string.Compare(a.Name, b.Name)); //UsageGenerator ug = new UsageGenerator(); //ug.Options = UsageOptions.AutoSuffix; //context.WriteLine(ug.GetUsage(context, null, null, -1, z1)); context.Bold.WriteLine("Syntax:"); context.Bold.Write(" <" + xst.Name); context.Write(" ... attributes ... "); context.Bold.WriteLine(" >"); List <EleInfo> att = new List <EleInfo>(); foreach (var p in commandType.GetProperties(BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.SetProperty | BindingFlags.Instance)) { var aa = CustomAttributeHelper.First <XsElementAttribute>(p); if (aa == null) { continue; } var d = CustomAttributeHelper.First <DescriptionAttribute>(p); att.Add(new EleInfo() { Attr = aa, Description = (d == null) ? null : d.Description, Property = p }); } att.Sort((a, b) => (a.Attr.Ordering - b.Attr.Ordering) * 10000 + a.Attr.Name.CompareTo(b.Attr.Name)); foreach (var aa in att) { string pref = string.Empty; if (!string.IsNullOrEmpty(aa.Attr.Name)) { if (aa.Attr.SkipIfEmpty) { context.Bold.WriteLine(" [<" + aa.Attr.Name + ">"); } else { context.Bold.WriteLine(" <" + aa.Attr.Name + ">"); } pref = " "; if (aa.Description != null) { context.Info.Write(Utils.Wrap(pref + " " + aa.Description, width, pref + " ")); } } if (!string.IsNullOrEmpty(aa.Attr.CollectionItemElementName)) { for (int i = 0; i < 2; ++i) { context.Bold.Write(pref + " "); if (aa.Attr.SkipIfEmpty) { context.Bold.Write("["); } context.Bold.Write("<" + aa.Attr.CollectionItemElementName + " "); var xs = CustomAttributeHelper.First <XsTypeAttribute>(aa.Attr.CollectionItemType); var hv = false; if (xs != null && string.IsNullOrEmpty(xs.Name)) { // Write attributes here foreach (var pp in aa.Attr.CollectionItemType.GetProperties(BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.SetProperty | BindingFlags.Instance)) { var tt = XsAttributeAttribute.GetNames(pp, false); if (tt == null) { continue; } var bba = tt[0]; foreach (var attribute in tt) { if (attribute == tt[0] && attribute.Length > 0) { bba = attribute; } if (attribute.Length == 0) { hv = true; } } if (bba.Length > 0) { context.Write(bba + "=\"...\" "); } } } if (hv) { context.Bold.Write(">"); context.Write("..value.."); context.Bold.Write("</" + aa.Attr.CollectionItemElementName + ">"); } else { context.Bold.Write(" />"); } if (aa.Attr.SkipIfEmpty) { context.Bold.Write("]"); } context.Bold.WriteLine(); } } else if (aa.Attr.CollectionItemType != null) { var name = "action"; if (aa.Attr.CollectionItemType != typeof(IScriptAction)) { name = "<" + aa.Attr.CollectionItemType.Name + " />"; } context.WriteLine(pref + " " + name); context.WriteLine(pref + " " + name); context.WriteLine(pref + " ..."); } if (!string.IsNullOrEmpty(aa.Attr.Name)) { if (aa.Attr.SkipIfEmpty) { context.Bold.WriteLine(" </" + aa.Attr.Name + ">]"); } else { context.Bold.WriteLine(" </" + aa.Attr.Name + ">"); } } } if (hasValue) { context.WriteLine(" value (see " + hasValueName + " attribute)"); } context.Bold.WriteLine(" </" + xst.Name + ">"); }
public void NArgAttribute_CanSetRankPropertyOnADataMember_Is7() { Assert.That(CustomAttributeHelper.GetCustomPropertiesFromMember <Sample, NArgAttribute>("_one"), Has.Property("Rank").EqualTo(7)); }
public void NArgAttribute_CanSetAltNamePropertyOnAPropertyMember_IsBar() { Assert.That(CustomAttributeHelper.GetCustomPropertiesFromMember <Sample, NArgAttribute>("Foo"), Has.Property("AltName").EqualTo("Bar")); }
public void MemberAttribute_WhenOptionalSetWithAllowedValuesAndOptionalArgNameNotSet_HasOptionalArgumentIsTrue() { NArgAttribute nattr = (NArgAttribute)CustomAttributeHelper.GetCustomPropertiesFromMember <Sample, NArgAttribute>("_limitedValues"); Assert.That(nattr.HasOptionalArgument, Is.True); }
private void graphSaveNET35(object o, Code originalCode, int level) { bool first; Type t = o.GetType(); string indent = new string('\t', level); string indent1 = new string('\t', level + 1); if (o is IEnumerable && (CustomAttributeHelper.All <XsTypeAttribute>(o.GetType()).Length == 0)) { first = true; MainCode.Write("new " + _re.GetTypeName(t)); foreach (var obj in (o as IEnumerable)) { MainCode.WriteLine(first ? " {" : ","); MainCode.Write(indent1); first = false; GenerateObjectCode(obj, null, level + 1); } if (!first) { MainCode.WriteLine(); MainCode.Write(indent); MainCode.Write("}"); } else { MainCode.Write("()"); } MainCode.Write(" "); } else { newClass(o); first = true; foreach (var pi in getPropertiesToSave(o)) { object propValue = pi.GetValue(o, null); MainCode.WriteLine(first ? "{" : ","); MainCode.Write(indent1); first = false; MainCode.Write(pi.Name + " = "); if (pi.PropertyType == typeof(ExecutableScriptBase)) { MainCode.Write("new " + originalCode.GetClassName() + "()"); } else { GenerateObjectCode(propValue, null, level + 1); } } if (!first) { MainCode.WriteLine(); MainCode.Write(indent); MainCode.Write("}"); } } }
private void graphSaveNET20(object o, string prevVarName, Code originalCode, int level) { Type t = o.GetType(); string indent = new string('\t', level); if (o is IEnumerable && (CustomAttributeHelper.All <XsTypeAttribute>(o.GetType()).Length == 0)) { if (t.GetGenericArguments().Length == 0) { MainCode.Write("new " + _re.GetTypeName(t) + "()"); } else { string bestType = _re.GetTypeName(t.GetGenericArguments()[0]); MainCode.Write("new List<" + bestType + ">()"); } foreach (var obj in (o as IEnumerable)) { MainCode.WriteLine(";"); MainCode.Write(indent); string v = getNextVar(obj); if (obj is Code && ((Code)obj).Dynamic == false) { MainCode.Write(_re.GetTypeName(typeof(CompiledCode))); } else { MainCode.Write(_re.GetTypeName(obj.GetType())); } MainCode.Write(" " + v + " = "); GenerateObjectCode(obj, v, level + 1); MainCode.WriteLine(";"); MainCode.Write(indent + prevVarName + ".Add(" + v + ")"); } } else { newClass(o); foreach (var pi in getPropertiesToSave(o)) { MainCode.WriteLine(";"); MainCode.Write(indent); if (!pi.PropertyType.IsClass || pi.PropertyType == typeof(string) || pi.PropertyType == typeof(ExecutableScriptBase)) { MainCode.Write(prevVarName + "." + pi.Name + " = "); if (pi.PropertyType == typeof(ExecutableScriptBase)) { MainCode.Write("new " + originalCode.GetClassName() + "()"); } else { object propValue = pi.GetValue(o, null); writeSimple(propValue); } } else { object propValue = pi.GetValue(o, null); if (propValue != null) { string v = getNextVar(propValue); MainCode.Write(_re.GetTypeName(propValue.GetType()) + " " + v + " = "); GenerateObjectCode(propValue, v, level + 1); MainCode.WriteLine(";"); MainCode.Write(indent + prevVarName + "." + pi.Name + " = " + v); } } } } }