public static XmlNode WriteInstance(Instance instance, XmlDocument doc, XmlRobloxFile file) { if (!instance.Archivable) { return(null); } XmlElement instNode = doc.CreateElement("Item"); instNode.SetAttribute("class", instance.ClassName); instNode.SetAttribute("referent", instance.Referent); XmlElement propsNode = doc.CreateElement("Properties"); instNode.AppendChild(propsNode); var props = instance.RefreshProperties(); var orderedKeys = props .OrderBy(pair => pair.Key) .Select(pair => pair.Key); foreach (string propName in orderedKeys) { Property prop = props[propName]; bool isDefault = false; object a = DefaultProperty.Get(instance, prop); object b = prop.Value; if (a is double d0 && b is double d1) { isDefault = d0.FuzzyEquals(d1); }
public override object VisitPropertyDeclaration(AST.PropertyDeclaration propertyDeclaration, object data) { DomRegion region = GetRegion(propertyDeclaration.StartLocation, propertyDeclaration.EndLocation); DomRegion bodyRegion = GetRegion(propertyDeclaration.BodyStart, propertyDeclaration.BodyEnd); IReturnType type = CreateReturnType(propertyDeclaration.TypeReference); DefaultClass c = GetCurrentClass(); DefaultProperty property = new DefaultProperty(propertyDeclaration.Name, type, ConvertModifier(propertyDeclaration.Modifier), region, bodyRegion, GetCurrentClass()); if (propertyDeclaration.HasGetRegion) { property.GetterRegion = GetRegion(propertyDeclaration.GetRegion.StartLocation, propertyDeclaration.GetRegion.EndLocation); property.CanGet = true; property.GetterModifiers = ConvertModifier(propertyDeclaration.GetRegion.Modifier, ModifierEnum.None); } if (propertyDeclaration.HasSetRegion) { property.SetterRegion = GetRegion(propertyDeclaration.SetRegion.StartLocation, propertyDeclaration.SetRegion.EndLocation); property.CanSet = true; property.SetterModifiers = ConvertModifier(propertyDeclaration.SetRegion.Modifier, ModifierEnum.None); } property.Documentation = GetDocumentation(region.BeginLine, propertyDeclaration.Attributes); ConvertAttributes(propertyDeclaration, property); c.Properties.Add(property); return(null); }
public override IEnumerable <IProperty> GetProperties(ITypeResolveContext context, Predicate <IProperty> filter = null) { ITypeDefinition arrayDef = systemArray.Resolve(context) as ITypeDefinition; if (arrayDef != null) { foreach (IProperty p in arrayDef.GetProperties(context, filter)) { yield return(p); } DefaultProperty indexer = new DefaultProperty(arrayDef, "Items") { EntityType = EntityType.Indexer, ReturnType = elementType, Accessibility = Accessibility.Public, Getter = DefaultAccessor.GetFromAccessibility(Accessibility.Public), Setter = DefaultAccessor.GetFromAccessibility(Accessibility.Public), IsSynthetic = true }; for (int i = 0; i < dimensions; i++) { indexer.Parameters.Add(indexerParam); } indexer.Freeze(); if (filter == null || filter(indexer)) { yield return(indexer); } } }
public DefaultProperty AddProperty(string name) { DefaultProperty property = new DefaultProperty(this, name); Properties.Add(property); return(property); }
public void AutoAssignTest3() { BeethovenFactory factory = new BeethovenFactory(); var defaultValues1 = new { Name = "The evil company", Address = "2460 Sunshine road" }; DefaultProperty defaultProperty1 = new DefaultProperty() .AnonymousValueLookup(defaultValues1) .SetterGetter(); ICompanyInformation companyInformation = factory.Generate <ICompanyInformation>(defaultProperty1); Assert.AreEqual("The evil company", companyInformation.Name); Assert.AreEqual("2460 Sunshine road", companyInformation.Address); var defaultValues2 = new { Name = "", }; DefaultProperty defaultProperty2 = new DefaultProperty() .AnonymousValueLookup(defaultValues2) .SetterGetter(); companyInformation = factory.Generate <ICompanyInformation>(defaultProperty2); Assert.AreEqual("", companyInformation.Name); Assert.AreEqual(null, companyInformation.Address); }
public override object VisitIndexerDeclaration(AST.IndexerDeclaration indexerDeclaration, object data) { DomRegion region = GetRegion(indexerDeclaration.StartLocation, indexerDeclaration.EndLocation); DomRegion bodyRegion = GetRegion(indexerDeclaration.BodyStart, indexerDeclaration.BodyEnd); DefaultProperty i = new DefaultProperty("Indexer", CreateReturnType(indexerDeclaration.TypeReference), ConvertModifier(indexerDeclaration.Modifier), region, bodyRegion, GetCurrentClass()); i.IsIndexer = true; if (indexerDeclaration.HasGetRegion) { i.GetterRegion = GetRegion(indexerDeclaration.GetRegion.StartLocation, indexerDeclaration.GetRegion.EndLocation); i.CanGet = true; i.GetterModifiers = ConvertModifier(indexerDeclaration.GetRegion.Modifier, ModifierEnum.None); } if (indexerDeclaration.HasSetRegion) { i.SetterRegion = GetRegion(indexerDeclaration.SetRegion.StartLocation, indexerDeclaration.SetRegion.EndLocation); i.CanSet = true; i.SetterModifiers = ConvertModifier(indexerDeclaration.SetRegion.Modifier, ModifierEnum.None); } i.Documentation = GetDocumentation(region.BeginLine, indexerDeclaration.Attributes); ConvertAttributes(indexerDeclaration, i); if (indexerDeclaration.Parameters != null) { foreach (AST.ParameterDeclarationExpression par in indexerDeclaration.Parameters) { i.Parameters.Add(CreateParameter(par)); } } DefaultClass c = GetCurrentClass(); c.Properties.Add(i); return(null); }
/// <summary> /// Returns all the default properties that don't have any dependency from other default properties. /// The first time they are fetched from DB, the other ones from in-memory cache. /// </summary> /// <returns>an empty map if any error occurred; the default basic properties otherwise, /// where the keys are the properties names and the values are the actual possible values of that basic property</returns> public static IDictionary <string, List <string> > GetBasicProperties(this IPropertiesRepository repo) { if (s_basicProps == null) { //init default properties if needed: ICollection <DefaultProperty> defProperties = repo.GetDefaultProperties(); s_basicProps = DefaultProperty.FilterBasicProperties(defProperties); } return(s_basicProps); }
void ConvertParameters(AST.ParameterDeclarationCollection parameters, DefaultProperty p) { if (parameters == null || parameters.Count == 0) { p.Parameters = DefaultParameter.EmptyParameterList; } else { AddParameters(parameters, p.Parameters, p, p.DeclaringType); } }
private WrapperGenerator(object[] partDefinitions, Func <object, IEnumerable <object> > getWrappers) { object[] flatDefinitions = Flatten(partDefinitions).ToArray(); this.partDefinitions = flatDefinitions; this.getWrappers = getWrappers; defaultProperty = partDefinitions.OfType <DefaultProperty>().SingleOrDefault(); defaultMethod = partDefinitions.OfType <DefaultMethod>().SingleOrDefault(); this.partDefinitions = this.partDefinitions .Concat(GetDefaultProperties(flatDefinitions.OfType <PropertyDefinition>())) .Concat(GetDefaultMethods()) .ToArray(); }
public ActionSetProperties Clone() { TestActionSetProperties asp = new TestActionSetProperties { Properties = new DefaultProperties() }; for (int i = 1; i <= this.Properties.Count; ++i) { DefaultProperty defaultProperty = this.Properties[i]; asp.Properties.Add(-1, defaultProperty.Clone()); } return(asp); }
public override object VisitPropertyDeclaration(AST.PropertyDeclaration propertyDeclaration, object data) { DomRegion region = GetRegion(propertyDeclaration.StartLocation, propertyDeclaration.EndLocation); DomRegion bodyRegion = GetRegion(propertyDeclaration.BodyStart, propertyDeclaration.BodyEnd); IReturnType type = CreateReturnType(propertyDeclaration.TypeReference); DefaultClass c = GetCurrentClass(); DefaultProperty property = new DefaultProperty(propertyDeclaration.Name, type, ConvertModifier(propertyDeclaration.Modifier), region, bodyRegion, GetCurrentClass()); if (propertyDeclaration.HasGetRegion) { property.GetterRegion = GetRegion(propertyDeclaration.GetRegion.StartLocation, propertyDeclaration.GetRegion.EndLocation); property.CanGet = true; property.GetterModifiers = ConvertModifier(propertyDeclaration.GetRegion.Modifier, ModifierEnum.None); } if (propertyDeclaration.HasSetRegion) { property.SetterRegion = GetRegion(propertyDeclaration.SetRegion.StartLocation, propertyDeclaration.SetRegion.EndLocation); property.CanSet = true; property.SetterModifiers = ConvertModifier(propertyDeclaration.SetRegion.Modifier, ModifierEnum.None); } property.Documentation = GetDocumentation(region.BeginLine, propertyDeclaration.Attributes); ConvertAttributes(propertyDeclaration, property); property.IsIndexer = propertyDeclaration.IsIndexer; if (propertyDeclaration.Parameters != null) { foreach (AST.ParameterDeclarationExpression par in propertyDeclaration.Parameters) { property.Parameters.Add(CreateParameter(par)); } } // If an IndexerNameAttribute is specified, use the specified name // for the indexer instead of the default name. IAttribute indexerNameAttribute = property.Attributes.LastOrDefault(this.IsIndexerNameAttribute); if (indexerNameAttribute != null && indexerNameAttribute.PositionalArguments.Count > 0) { string name = indexerNameAttribute.PositionalArguments[0] as string; if (!String.IsNullOrEmpty(name)) { property.FullyQualifiedName = String.Concat(property.DeclaringType.FullyQualifiedName, ".", name); } } AddInterfaceImplementations(property, propertyDeclaration); c.Properties.Add(property); return(null); }
DefaultClass CreateAnonymousTypeClass(CollectionInitializerExpression initializer) { List <IReturnType> fieldTypes = new List <IReturnType>(); List <string> fieldNames = new List <string>(); foreach (Expression expr in initializer.CreateExpressions) { if (expr is NamedArgumentExpression) { // use right part only fieldTypes.Add(ResolveType(((NamedArgumentExpression)expr).Expression)); } else { fieldTypes.Add(ResolveType(expr)); } fieldNames.Add(GetAnonymousTypeFieldName(expr)); } StringBuilder nameBuilder = new StringBuilder(); nameBuilder.Append('{'); for (int i = 0; i < fieldTypes.Count; i++) { if (i > 0) { nameBuilder.Append(", "); } nameBuilder.Append(fieldNames[i]); nameBuilder.Append(" : "); if (fieldTypes[i] != null) { nameBuilder.Append(fieldTypes[i].DotNetName); } } nameBuilder.Append('}'); DefaultClass c = new DefaultClass(new DefaultCompilationUnit(resolver.ProjectContent), nameBuilder.ToString()); c.Modifiers = ModifierEnum.Internal | ModifierEnum.Synthetic | ModifierEnum.Sealed; for (int i = 0; i < fieldTypes.Count; i++) { DefaultProperty p = new DefaultProperty(fieldNames[i], fieldTypes[i], ModifierEnum.Public | ModifierEnum.Synthetic, DomRegion.Empty, DomRegion.Empty, c); p.CanGet = true; p.CanSet = false; c.Properties.Add(p); } return(c); }
/// <summary> /// Gets whether the value of the property is set /// </summary> public override bool IsSet(DotvvmBindableObject control, bool inherit = true) { if (control.properties != null && control.properties.ContainsKey(this)) { return(true); } if (IsValueInherited && inherit && control.Parent != null) { return(IsSet(control.Parent)); } return(DefaultProperty.IsSet(control, DefaultPropertyInherit)); }
///////////////////////////////////////////////////////////////////////////////////////////////////// #region Add Methods ///////////////////////////////////////////////////////////////////////////////////////////////////// public bool SuggestDefaultProperty(DefaultProperty defProp, int userID) { //send the request and parse the response: string contentToSend = "content=" + HttpUtility.UrlEncode(defProp.Serialize(m_serialFormat)); S2CResObj <object> resp = SendReqObj(SUGGEST_DEFAULTS_URL, contentToSend, true); //build the result: if (!CheckResp(resp)) { PrintRespError(resp); return(false); } return(ParseBoolResponse(resp)); }
public override object VisitIndexerDeclaration(NRefactoryAST.IndexerDeclaration indexerDeclaration, object data) { DomRegion region = GetRegion(indexerDeclaration.StartLocation, indexerDeclaration.EndLocation); DomRegion bodyRegion = GetRegion(indexerDeclaration.BodyStart, indexerDeclaration.BodyEnd); DefaultProperty i = new DefaultProperty("Item", CreateReturnType(indexerDeclaration.TypeReference), ConvertModifier(indexerDeclaration.Modifier), region, bodyRegion, GetCurrentClass()); i.IsIndexer = true; if (indexerDeclaration.HasGetRegion) { i.GetterRegion = GetRegion(indexerDeclaration.GetRegion.StartLocation, indexerDeclaration.GetRegion.EndLocation); i.CanGet = true; i.GetterModifiers = ConvertModifier(indexerDeclaration.GetRegion.Modifier, ModifierEnum.None); } if (indexerDeclaration.HasSetRegion) { i.SetterRegion = GetRegion(indexerDeclaration.SetRegion.StartLocation, indexerDeclaration.SetRegion.EndLocation); i.CanSet = true; i.SetterModifiers = ConvertModifier(indexerDeclaration.SetRegion.Modifier, ModifierEnum.None); } i.Documentation = GetDocumentation(region.BeginLine, indexerDeclaration.Attributes); ConvertAttributes(indexerDeclaration, i); if (indexerDeclaration.Parameters != null) { foreach (NRefactoryAST.ParameterDeclarationExpression par in indexerDeclaration.Parameters) { i.Parameters.Add(CreateParameter(par)); } } // If an IndexerNameAttribute is specified, use the specified name // for the indexer instead of the default name. IAttribute indexerNameAttribute = i.Attributes.LastOrDefault(this.IsIndexerNameAttribute); if (indexerNameAttribute != null && indexerNameAttribute.PositionalArguments.Count > 0) { string name = indexerNameAttribute.PositionalArguments[0] as string; if (!String.IsNullOrEmpty(name)) { i.FullyQualifiedName = String.Concat(i.DeclaringType.FullyQualifiedName, ".", name); } } DefaultClass c = GetCurrentClass(); c.Properties.Add(i); return(null); }
public override void OnProperty(AST.Property node) { DefaultProperty property = new DefaultProperty(node.Name, CreateReturnType(node), GetModifier(node), GetRegion(node), GetClientRegion(node), OuterClass); ConvertAttributes(node, property); ConvertParameters(node.Parameters, property); if (node.Getter != null && node.Getter.Body != null) { property.GetterRegion = GetClientRegion(node.Getter); } if (node.Setter != null && node.Setter.Body != null) { property.SetterRegion = GetClientRegion(node.Setter); } property.IsIndexer = (node.Name == "self"); OuterClass.Properties.Add(property); property.UserData = node; }
/// <summary> /// Gets the value of the property. /// </summary> public override object GetValue(DotvvmBindableObject control, bool inherit = true) { object value; if (control.properties != null) { if (control.properties.TryGetValue(this, out value)) { return(value); } } if (IsValueInherited && inherit && control.Parent != null) { return(GetValue(control.Parent)); } return(DefaultProperty.GetValue(control, DefaultPropertyInherit)); }
public override IEntity VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, object data) { DefaultProperty p = new DefaultProperty(currentTypeDefinition, propertyDeclaration.Name); p.Region = MakeRegion(propertyDeclaration); p.BodyRegion = MakeBraceRegion(propertyDeclaration); ApplyModifiers(p, propertyDeclaration.Modifiers); p.ReturnType = ConvertType(propertyDeclaration.ReturnType); ConvertAttributes(p.Attributes, propertyDeclaration.Attributes); if (!propertyDeclaration.PrivateImplementationType.IsNull) { p.Accessibility = Accessibility.None; p.InterfaceImplementations.Add(ConvertInterfaceImplementation(propertyDeclaration.PrivateImplementationType, p.Name)); } p.Getter = ConvertAccessor(propertyDeclaration.Getter, p.Accessibility); p.Setter = ConvertAccessor(propertyDeclaration.Setter, p.Accessibility); currentTypeDefinition.Properties.Add(p); return(p); }
/// <summary> /// Serves as a hash function for the objects of <see cref="DumpAttribute"/> and its derived types. /// </summary> /// <returns>A hash code for the current <see cref="DumpAttribute"/> instance.</returns> public override int GetHashCode() { var hashCode = Constants.HashInitializer; unchecked { hashCode = Constants.HashMultiplier * hashCode + Order.GetHashCode(); hashCode = Constants.HashMultiplier * hashCode + DumpNullValues.GetHashCode(); hashCode = Constants.HashMultiplier * hashCode + Skip.GetHashCode(); hashCode = Constants.HashMultiplier * hashCode + RecurseDump.GetHashCode(); hashCode = Constants.HashMultiplier * hashCode + (DefaultProperty?.GetHashCode() ?? 0); hashCode = Constants.HashMultiplier * hashCode + Mask.GetHashCode(); hashCode = Constants.HashMultiplier * hashCode + MaskValue.GetHashCode(); hashCode = Constants.HashMultiplier * hashCode + MaxLength.GetHashCode(); hashCode = Constants.HashMultiplier * hashCode + MaxDepth.GetHashCode(); hashCode = Constants.HashMultiplier * hashCode + LabelFormat.GetHashCode(); hashCode = Constants.HashMultiplier * hashCode + ValueFormat.GetHashCode(); } return(hashCode); }
public override IEntity VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, object data) { DefaultProperty p = new DefaultProperty(currentTypeDefinition, "Items"); p.EntityType = EntityType.Indexer; p.Region = MakeRegion(indexerDeclaration); p.BodyRegion = MakeBraceRegion(indexerDeclaration); ApplyModifiers(p, indexerDeclaration.Modifiers); p.ReturnType = ConvertType(indexerDeclaration.ReturnType); ConvertAttributes(p.Attributes, indexerDeclaration.Attributes); if (!indexerDeclaration.PrivateImplementationType.IsNull) { p.Accessibility = ICSharpCode.NRefactory.TypeSystem.Accessibility.None; p.InterfaceImplementations.Add(ConvertInterfaceImplementation(indexerDeclaration.PrivateImplementationType, p.Name)); } p.Getter = ConvertAccessor(indexerDeclaration.Getter, p.Accessibility); p.Setter = ConvertAccessor(indexerDeclaration.Setter, p.Accessibility); ConvertParameters(p.Parameters, indexerDeclaration.Parameters); currentTypeDefinition.Properties.Add(p); return(p); }
/// <summary> /// Makes a copy of <c>oldClass</c>. /// </summary> /// <param name="oldClass">Class to be copied.</param> /// <returns>Copy of the class.</returns> private IClass copyClass(IClass oldClass) { DefaultClass newClass = new DefaultClass(oldClass.CompilationUnit, oldClass.FullyQualifiedName); newClass.Modifiers = oldClass.Modifiers; foreach (ITypeParameter element in oldClass.TypeParameters) { newClass.TypeParameters.Add(element); } // Recursively copy inner classes. foreach (IClass element in oldClass.InnerClasses) { newClass.InnerClasses.Add(copyClass(element)); } // Copy events. foreach (IEvent element in oldClass.Events) { DefaultEvent newEvent = new DefaultEvent(element.Name, element.ReturnType, element.Modifiers, element.Region, element.BodyRegion, newClass); newClass.Events.Add(newEvent); } //Copy properties foreach (IProperty element in oldClass.Properties) { DefaultProperty newProperty = new DefaultProperty(element.Name, element.ReturnType, element.Modifiers, element.Region, element.BodyRegion, newClass); newClass.Properties.Add(newProperty); } //Copy methods. copyMethods(oldClass, newClass); copyFields(oldClass, newClass); return(newClass); }
public bool AddDefaultProperty(DefaultProperty defProp) { throw new NotImplementedException(); }
MemberResolveResult ResolvePropertyName(IReturnType resolvedType, string propertyName, bool allowAttached) { IMember member = resolvedType.GetProperties().Find(delegate(IProperty p) { return(p.Name == propertyName); }); if (member == null) { member = resolvedType.GetEvents().Find(delegate(IEvent p) { return(p.Name == propertyName); }); } if (member == null && allowAttached) { IMethod method = resolvedType.GetMethods().Find( delegate(IMethod p) { return(p.IsStatic && p.Parameters.Count == 1 && p.Name == "Get" + propertyName); }); member = method; if (member != null) { member = new DefaultProperty(resolvedType.GetUnderlyingClass(), propertyName) { ReturnType = method.ReturnType }; } else { IMethod m = resolvedType.GetMethods().Find( delegate(IMethod p) { return(p.IsPublic && p.IsStatic && p.Parameters.Count == 2 && (p.Name == "Add" + propertyName + "Handler" || p.Name == "Remove" + propertyName + "Handler")); }); member = m; if (member != null) { member = new DefaultEvent(resolvedType.GetUnderlyingClass(), propertyName) { ReturnType = m.Parameters[1].ReturnType } } ; } } if (member != null) { return(new MemberResolveResult(callingClass, null, member)); } return(null); } MemberResolveResult ResolveAttribute(string attributeName) { if (context.ActiveElement == null) { return(null); } string attributeXmlNamespace; if (attributeName.Contains(":")) { string prefix = attributeName.Substring(0, attributeName.IndexOf(':')); if (!context.XmlnsDefinitions.TryGetValue(prefix, out attributeXmlNamespace)) { attributeXmlNamespace = null; } attributeName = attributeName.Substring(attributeName.IndexOf(':') + 1); } else { if (!context.XmlnsDefinitions.TryGetValue("", out attributeXmlNamespace)) { attributeXmlNamespace = null; } } if (attributeName.Contains(".")) { string className = attributeName.Substring(0, attributeName.IndexOf('.')); attributeName = attributeName.Substring(attributeName.IndexOf('.') + 1); return(ResolveProperty(attributeXmlNamespace, className, attributeName, true)); } else { var lastElement = context.ActiveElement; return(ResolveProperty(lastElement.Namespace, lastElement.LocalName, attributeName, false)); } } ResolveResult ResolveAttributeValue(IMember propertyOrEvent, string expression) { if (propertyOrEvent == null) { return(null); } if (propertyOrEvent is IEvent && callingClass != null) { return(new MethodGroupResolveResult(callingClass, null, callingClass.DefaultReturnType, expression)); } else if (propertyOrEvent is IProperty && callingClass != null) { if (propertyOrEvent.Name == "Name") { foreach (IField f in callingClass.Fields) { if (f.Name == expression) { return(new MemberResolveResult(callingClass, null, f)); } } } return(ResolveElementName(expression)); } IReturnType type = propertyOrEvent.ReturnType; if (type == null) { return(null); } IClass c = type.GetUnderlyingClass(); if (c == null) { return(null); } if (c.ClassType == ClassType.Enum) { foreach (IField f in c.Fields) { if (f.Name == expression) { return(new MemberResolveResult(callingClass, null, f)); } } } return(null); }
public override object VisitPropertyDeclaration(AST.PropertyDeclaration propertyDeclaration, object data) { DomRegion region = GetRegion(propertyDeclaration.StartLocation, propertyDeclaration.EndLocation); DomRegion bodyRegion = GetRegion(propertyDeclaration.BodyStart, propertyDeclaration.BodyEnd); IReturnType type = CreateReturnType(propertyDeclaration.TypeReference); DefaultClass c = GetCurrentClass(); DefaultProperty property = new DefaultProperty(propertyDeclaration.Name, type, ConvertModifier(propertyDeclaration.Modifier), region, bodyRegion, GetCurrentClass()); if (propertyDeclaration.HasGetRegion) { property.GetterRegion = GetRegion(propertyDeclaration.GetRegion.StartLocation, propertyDeclaration.GetRegion.EndLocation); property.CanGet = true; property.GetterModifiers = ConvertModifier(propertyDeclaration.GetRegion.Modifier, ModifierEnum.None); } if (propertyDeclaration.HasSetRegion) { property.SetterRegion = GetRegion(propertyDeclaration.SetRegion.StartLocation, propertyDeclaration.SetRegion.EndLocation); property.CanSet = true; property.SetterModifiers = ConvertModifier(propertyDeclaration.SetRegion.Modifier, ModifierEnum.None); } property.Documentation = GetDocumentation(region.BeginLine, propertyDeclaration.Attributes); ConvertAttributes(propertyDeclaration, property); c.Properties.Add(property); return null; }
/// <summary> /// Validate the object. /// </summary> /// <exception cref="Microsoft.Rest.ValidationException"> /// Thrown if validation fails /// </exception> public virtual void Validate() { if (AdditionalItems != null) { AdditionalItems.Validate(); } if (AdditionalProperties != null) { AdditionalProperties.Validate(); } if (AllOf != null) { foreach (var element in AllOf) { if (element != null) { element.Validate(); } } } if (AnyOf != null) { foreach (var element1 in AnyOf) { if (element1 != null) { element1.Validate(); } } } if (DefaultProperty != null) { DefaultProperty.Validate(); } if (Definitions != null) { foreach (var valueElement in Definitions.Values) { if (valueElement != null) { valueElement.Validate(); } } } if (Dependencies != null) { foreach (var valueElement1 in Dependencies.Values) { if (valueElement1 != null) { valueElement1.Validate(); } } } if (EnumProperty != null) { foreach (var element2 in EnumProperty) { if (element2 != null) { element2.Validate(); } } } if (Example != null) { Example.Validate(); } if (Items != null) { Items.Validate(); } if (Not != null) { Not.Validate(); } if (OneOf != null) { foreach (var element3 in OneOf) { if (element3 != null) { element3.Validate(); } } } if (PatternProperties != null) { foreach (var valueElement2 in PatternProperties.Values) { if (valueElement2 != null) { valueElement2.Validate(); } } } if (Properties != null) { foreach (var valueElement3 in Properties.Values) { if (valueElement3 != null) { valueElement3.Validate(); } } } }
public void InsertPropertyAtStart(string name) { DefaultProperty property = new DefaultProperty(this, name); Properties.Insert(0, property); }
DefaultClass CreateAnonymousTypeClass(CollectionInitializerExpression initializer) { List<IReturnType> fieldTypes = new List<IReturnType>(); List<string> fieldNames = new List<string>(); foreach (Expression expr in initializer.CreateExpressions) { if (expr is NamedArgumentExpression) { // use right part only fieldTypes.Add( ResolveType(((NamedArgumentExpression)expr).Expression) ); } else { fieldTypes.Add( ResolveType(expr) ); } fieldNames.Add(GetAnonymousTypeFieldName(expr)); } StringBuilder nameBuilder = new StringBuilder(); nameBuilder.Append('{'); for (int i = 0; i < fieldTypes.Count; i++) { if (i > 0) nameBuilder.Append(", "); nameBuilder.Append(fieldNames[i]); nameBuilder.Append(" : "); if (fieldTypes[i] != null) { nameBuilder.Append(fieldTypes[i].DotNetName); } } nameBuilder.Append('}'); DefaultClass c = new DefaultClass(new DefaultCompilationUnit(resolver.ProjectContent), nameBuilder.ToString()); c.Modifiers = ModifierEnum.Internal | ModifierEnum.Synthetic | ModifierEnum.Sealed; for (int i = 0; i < fieldTypes.Count; i++) { DefaultProperty p = new DefaultProperty(fieldNames[i], fieldTypes[i], ModifierEnum.Public | ModifierEnum.Synthetic, DomRegion.Empty, DomRegion.Empty, c); p.CanGet = true; p.CanSet = false; c.Properties.Add(p); } return c; }
get => GetValue(DefaultProperty); set => SetValue(DefaultProperty, value);
public override object VisitPropertyDeclaration(AST.PropertyDeclaration propertyDeclaration, object data) { DomRegion region = GetRegion(propertyDeclaration.StartLocation, propertyDeclaration.EndLocation); DomRegion bodyRegion = GetRegion(propertyDeclaration.BodyStart, propertyDeclaration.BodyEnd); IReturnType type = CreateReturnType(propertyDeclaration.TypeReference); DefaultClass c = GetCurrentClass(); DefaultProperty property = new DefaultProperty(propertyDeclaration.Name, type, ConvertModifier(propertyDeclaration.Modifier), region, bodyRegion, GetCurrentClass()); if (propertyDeclaration.HasGetRegion) { property.GetterRegion = GetRegion(propertyDeclaration.GetRegion.StartLocation, propertyDeclaration.GetRegion.EndLocation); property.CanGet = true; property.GetterModifiers = ConvertModifier(propertyDeclaration.GetRegion.Modifier, ModifierEnum.None); } if (propertyDeclaration.HasSetRegion) { property.SetterRegion = GetRegion(propertyDeclaration.SetRegion.StartLocation, propertyDeclaration.SetRegion.EndLocation); property.CanSet = true; property.SetterModifiers = ConvertModifier(propertyDeclaration.SetRegion.Modifier, ModifierEnum.None); } property.Documentation = GetDocumentation(region.BeginLine, propertyDeclaration.Attributes); ConvertAttributes(propertyDeclaration, property); property.IsIndexer = propertyDeclaration.IsIndexer; if (propertyDeclaration.Parameters != null) { foreach (AST.ParameterDeclarationExpression par in propertyDeclaration.Parameters) { property.Parameters.Add(CreateParameter(par)); } } // If an IndexerNameAttribute is specified, use the specified name // for the indexer instead of the default name. IAttribute indexerNameAttribute = property.Attributes.LastOrDefault(this.IsIndexerNameAttribute); if (indexerNameAttribute != null && indexerNameAttribute.PositionalArguments.Count > 0) { string name = indexerNameAttribute.PositionalArguments[0] as string; if (!String.IsNullOrEmpty(name)) { property.FullyQualifiedName = String.Concat(property.DeclaringType.FullyQualifiedName, ".", name); } } AddInterfaceImplementations(property, propertyDeclaration); c.Properties.Add(property); return null; }
public override object VisitIndexerDeclaration(AST.IndexerDeclaration indexerDeclaration, object data) { DomRegion region = GetRegion(indexerDeclaration.StartLocation, indexerDeclaration.EndLocation); DomRegion bodyRegion = GetRegion(indexerDeclaration.BodyStart, indexerDeclaration.BodyEnd); DefaultProperty i = new DefaultProperty("Indexer", CreateReturnType(indexerDeclaration.TypeReference), ConvertModifier(indexerDeclaration.Modifier), region, bodyRegion, GetCurrentClass()); i.IsIndexer = true; i.Documentation = GetDocumentation(region.BeginLine, indexerDeclaration.Attributes); ConvertAttributes(indexerDeclaration, i); if (indexerDeclaration.Parameters != null) { foreach (AST.ParameterDeclarationExpression par in indexerDeclaration.Parameters) { i.Parameters.Add(CreateParameter(par)); } } DefaultClass c = GetCurrentClass(); c.Properties.Add(i); return null; }