/// <summary> /// Calculates the sum /// </summary> public FuncParameter Aggregate(IEnumerable <IComparable> myValues, IPropertyDefinition myPropertyDefinition) { var sumType = myPropertyDefinition.BaseType; IComparable sum = null; try { foreach (var value in myValues) { if (sum == null) { sum = ArithmeticOperations.Add(sumType, 0, value); } else { sum = ArithmeticOperations.Add(sumType, sum, value); } } } catch (ArithmeticException e) { throw new InvalidArithmeticAggregationException(sumType, this.PluginShortName, e); } return(new FuncParameter(sum, myPropertyDefinition)); }
private static void InitializePropertyItem(PropertyItem propertyItem, IPropertyDefinition pd) { propertyItem.ChildrenDefinitions = pd.ChildrenDefinitions; // Assign a shorter name, for code clarity only. PropertyGridUtilities.SetupDefinitionBinding(propertyItem, PropertyItem.DisplayNameProperty, pd, () => pd.DisplayName); PropertyGridUtilities.SetupDefinitionBinding(propertyItem, PropertyItem.DescriptionProperty, pd, () => pd.Description); PropertyGridUtilities.SetupDefinitionBinding(propertyItem, PropertyItem.CategoryProperty, pd, () => pd.Category); PropertyGridUtilities.SetupDefinitionBinding(propertyItem, PropertyItem.PropertyOrderProperty, pd, () => pd.DisplayOrder); PropertyGridUtilities.SetupDefinitionBinding(propertyItem, PropertyItem.AdvancedOptionsIconProperty, pd, () => pd.AdvancedOptionsIcon); PropertyGridUtilities.SetupDefinitionBinding(propertyItem, PropertyItem.AdvancedOptionsTooltipProperty, pd, () => pd.AdvancedOptionsTooltip); PropertyGridUtilities.SetupDefinitionBinding(propertyItem, PropertyItem.IsExpandableProperty, pd, () => pd.IsExpandable); Binding valueBinding = new Binding("Value") { Source = pd, Mode = BindingMode.TwoWay }; propertyItem.SetBinding(PropertyItem.ValueProperty, valueBinding); propertyItem.Editor = pd.GenerateEditorElement(propertyItem); if (pd.CommandBindings != null) { foreach (CommandBinding commandBinding in pd.CommandBindings) { propertyItem.CommandBindings.Add(commandBinding); } } }
private static bool DetermineIsVisible(IPropertyDefinition propertyDefinition, PropertyAccessorAccessModifiers accessModifiers) { if (propertyDefinition.IsVisible == false) { // The parent property is not visible so neither is the accessor return(false); } if (accessModifiers == PropertyAccessorAccessModifiers.None) { // There is no access modifiers defined to further restrict visibility so we inherit from the declaring property return(true); } if (accessModifiers == PropertyAccessorAccessModifiers.Protected) { return(true); } if (accessModifiers == PropertyAccessorAccessModifiers.ProtectedInternal) { return(true); } return(false); }
public override object ConvertToPropertyBagValue(IPropertyDefinition propertyDefinition, object value, bool keepRelationInfo) { var netvalue = value as List <object>; if (netvalue == null || netvalue.Count == 0) { return(null); } var itemsPropertyDefinition = (IPropertyDefinition)propertyDefinition.AdditionalProperties[PropertyItems]; var targetList = netvalue .Select(x => itemsPropertyDefinition.PropertyType.ConvertToPropertyBagValue(itemsPropertyDefinition, x, keepRelationInfo)) .Where(x => x != null) .ToArray(); if (!targetList.Any()) { return(null); } var targetListItemsTypes = targetList.First().GetType(); var result = Array.CreateInstance(targetListItemsTypes, targetList.Length); Array.Copy(targetList, result, targetList.Length); return(result); }
public string GetPropertyType(IPropertyDefinition propertyModel) { switch (propertyModel) { case ConfigurationPrimitivePropertyModel input: return(GetPropertyType(input)); case IMultipleOptionPropertyDefinition input: return(ConfigurationPropertyType.MultipleOption); case IOptionPropertyDefinition input: return(ConfigurationPropertyType.Option); case ConfigurationClassCollectionPropertyDefinition input: return(ConfigurationPropertyType.Collection); case ConfigurationPrimitiveCollectionPropertyDefinition input: return(GetPropertyType(input)); case ConfigurationClassPropertyDefinition input: return(ConfigurationPropertyType.Class); default: throw new InvalidOperationException($"Could not handle ConfigurationPropertyModelBase of type {propertyModel.GetType().Name}"); } }
public void Replace(Operation operation, object objectToApplyTo) { operation.NotNull(nameof(operation)); objectToApplyTo.NotNull(nameof(objectToApplyTo)).Is <IEntity>(nameof(objectToApplyTo)); var entity = (IEntity)objectToApplyTo; string remaining = null; var currentEntity = entity; var leading = operation.path.SplitFirst('/', out remaining); IPropertyDefinition propertyDefinition = currentEntity.Definition.Properties.SafeGet(leading); if (propertyDefinition == null) { throw new BadRequestException($"Unable to find property {leading} on {currentEntity}."); } while (remaining != null) { currentEntity = (IEntity)currentEntity[propertyDefinition.Name]; leading = remaining.SplitFirst('/', out remaining); propertyDefinition = currentEntity.Definition.Properties.SafeGet(leading); if (propertyDefinition == null) { throw new BadRequestException($"Unable to find property {leading} on {currentEntity}."); } } currentEntity[propertyDefinition.Name] = propertyDefinition.PropertyType.ConvertFromPropertyBagValue(propertyDefinition, operation.value); }
public override List <IPropertyDefinition> Rewrite(List <IPropertyDefinition> propertyDefinitions) { TrimType currentType = CurrentTrimElement as TrimType; List <IPropertyDefinition> newList = new List <IPropertyDefinition>(); if (propertyDefinitions == null) { return(newList); } foreach (IPropertyDefinition property in propertyDefinitions) { MemberElement currentElement = currentType.GetMemberElementFromMember(property); if (currentElement != null) { _trimElements.Push(currentElement); IPropertyDefinition newProperty = Rewrite(property); newList.Add(newProperty); _trimElements.Pop(); } } return(newList); }
// ---- asserts ---- public void AssertAreEqual(IObjectType expected, IObjectType actual) { if (expected == null && actual == null) { return; } Assert.NotNull(expected); Assert.NotNull(actual); Assert.NotNull(actual.Id); Assert.AreEqual(expected.Id, actual.Id); Assert.AreEqual(expected.IsBaseType, actual.IsBaseType); Assert.AreEqual(expected.BaseTypeId, actual.BaseTypeId); Assert.AreEqual(expected.DisplayName, actual.DisplayName); Assert.AreEqual(expected.Description, actual.Description); Assert.AreEqual(expected.LocalName, actual.LocalName); Assert.AreEqual(expected.LocalNamespace, actual.LocalNamespace); Assert.AreEqual(expected.QueryName, actual.QueryName); Assert.AreEqual(expected.PropertyDefinitions.Count, actual.PropertyDefinitions.Count); foreach (IPropertyDefinition propDef in expected.PropertyDefinitions) { Assert.NotNull(propDef); Assert.NotNull(propDef.Id); IPropertyDefinition propDef2 = actual[propDef.Id]; AssertAreEqual(propDef, propDef2); } }
public override Task SetDefaultValue(IPropertyDefinition propertyDefinition, IEntity entity, CancellationToken ct) { var defaultValue = propertyDefinition.DefaultValue as string; if (defaultValue.IsNullOrEmpty()) { return(Task.CompletedTask); } if (defaultValue.SafeOrdinalEquals(TodayDefaultValue)) { entity[propertyDefinition.Name] = SystemClock.Instance.GetCurrentInstant().InZone(DateTimeZoneProviders.Tzdb.GetSystemDefault()).Date; } else { var parseResult = LocalDatePattern.IsoPattern.Parse(defaultValue); if (parseResult.Success) { entity[propertyDefinition.Name] = parseResult.Value; } else { throw new ValueTypeException(this, $"Error while parsing value {defaultValue} as a date using pattern {LocalDatePattern.IsoPattern.PatternText}.", parseResult.Exception); } } return(Task.CompletedTask); }
internal PropertyReference GetProperty(IPropertyDefinition propDefn) { var defn = propDefn; var prop = new PropertyReference(defn.NameProp().Value ?? defn.KeyedName().Value ?? defn.IdProp().KeyedName().Value, this); while (defn.DataType().Value == "foreign" && defn.Property("foreign_property").HasValue() && defn.DataSource().KeyedName().HasValue()) { var linkProp = new PropertyReference(defn.DataSource().KeyedName().Value, prop.Table); var table = linkProp.GetOrAddTable(Context); defn = (IPropertyDefinition)defn.Property("foreign_property").AsItem(); if (string.IsNullOrEmpty(table.Type)) { table.Type = defn.SourceId().Attribute("name").Value ?? defn.SourceId().KeyedName().Value; } prop = new PropertyReference(defn.NameProp().Value ?? defn.KeyedName().Value ?? defn.IdProp().KeyedName().Value, table); } return(prop); }
public void WriteMemberDeclaration(ITypeDefinitionMember member) { IMethodDefinition method = member as IMethodDefinition; if (method != null) { WriteMethodDefinition(method); return; } IPropertyDefinition property = member as IPropertyDefinition; if (property != null) { WritePropertyDefinition(property); return; } IEventDefinition evnt = member as IEventDefinition; if (evnt != null) { WriteEventDefinition(evnt); return; } IFieldDefinition field = member as IFieldDefinition; if (field != null) { WriteFieldDefinition(field); return; } _writer.Write("Unknown member definitions type {0}", member.ToString()); }
/// <summary> /// Create a new query plan property /// </summary> /// <param name="myVertexType">The interesting vertex type</param> /// <param name="myProperty">The interesting property</param> public QueryPlanProperty(IVertexType myVertexType, IPropertyDefinition myProperty, String myInterestingEdition, TimeSpanDefinition myInterestingTimeSpan) { VertexType = myVertexType; Property = myProperty; Edition = myInterestingEdition; Timespan = myInterestingTimeSpan; }
public override object ConvertFromPropertyBagValue(IPropertyDefinition propertyDefinition, object value) { if (value == null) { return(null); } if (value is Guid) { return(value); } if (value is string && string.IsNullOrEmpty((string)value)) { return(null); } Guid result; if (Guid.TryParse(value.ToString(), out result)) { return(result); } throw new ValueTypeException(this, $"Unable to parse value {value} as a valid UUID."); }
public static bool IsOverride(this ITypeDefinitionMember member) { IMethodDefinition method = member as IMethodDefinition; if (method != null) { return(method.IsOverride()); } IPropertyDefinition property = member as IPropertyDefinition; if (property != null) { return(property.Accessors.Any(m => m.ResolvedMethod.IsOverride())); } IEventDefinition evnt = member as IEventDefinition; if (evnt != null) { return(evnt.Accessors.Any(m => m.ResolvedMethod.IsOverride())); } return(false); }
public static bool IsVisibleToFriendAssemblies(this ITypeDefinitionMember member) { // MemberHelper in CCI doesn't have a method like IsVisibleOutsideAssembly(...) to use here. This method // has similar behavior except that it returns true for all internal and internal protected members as well // as non-sealed private protected members. switch (member.Visibility) { case TypeMemberVisibility.Assembly: case TypeMemberVisibility.FamilyOrAssembly: case TypeMemberVisibility.Public: return(true); case TypeMemberVisibility.Family: case TypeMemberVisibility.FamilyAndAssembly: return(!member.ContainingTypeDefinition.IsSealed); } var containingType = member.ContainingTypeDefinition; return(member switch { IMethodDefinition methodDefinition => IsExplicitImplementationVisible(methodDefinition, containingType), IPropertyDefinition propertyDefinition => IsExplicitImplementationVisible(propertyDefinition.Getter, containingType) || IsExplicitImplementationVisible(propertyDefinition.Setter, containingType), IEventDefinition eventDefinition => IsExplicitImplementationVisible(eventDefinition.Adder, containingType) || IsExplicitImplementationVisible(eventDefinition.Remover, containingType), _ => false, });
/// <summary> /// Returns a C#-like string that corresponds to the given type member definition and that conforms to the specified formatting options. /// </summary> //^ [Pure] public virtual string GetMemberSignature(ITypeMemberReference member, NameFormattingOptions formattingOptions) { IMethodReference /*?*/ method = member as IMethodReference; if (method != null) { return(this.GetMethodSignature(method, formattingOptions)); } ITypeReference /*?*/ type = member as ITypeReference; if (type != null) { return(_typeNameFormatter.GetTypeName(type, formattingOptions)); } IEventDefinition /*?*/ eventDef = member as IEventDefinition; if (eventDef != null) { return(this.GetEventSignature(eventDef, formattingOptions)); } IFieldReference /*?*/ field = member as IFieldReference; if (field != null) { return(this.GetFieldSignature(field, formattingOptions)); } IPropertyDefinition /*?*/ property = member as IPropertyDefinition; if (property != null) { return(this.GetPropertySignature(property, formattingOptions)); } return(member.Name.Value); }
public static ITypeReference GetReturnType(this ITypeDefinitionMember member) { IMethodDefinition method = member as IMethodDefinition; if (method != null) { return(method.Type); } IPropertyDefinition property = member as IPropertyDefinition; if (property != null) { return(property.Type); } IEventDefinition evnt = member as IEventDefinition; if (evnt != null) { return(evnt.Type); } IFieldDefinition field = member as IFieldDefinition; if (field != null) { return(field.Type); } return(null); }
public override object ConvertFromPropertyBagValue(IPropertyDefinition propertyDefinition, object value) { var bag = value as PropertyBag; if (bag == null) { return(null); } if (propertyDefinition.AdditionalProperties.SafeGet(PropertyInverseOf) != null) { return(null); } var entityId = bag[MetaConstants.IdProperty]; if (entityId == null) { return(null); } var entityDefinition = (IEntityDefinition)propertyDefinition.AdditionalProperties[PropertyTarget]; var entity = propertyDefinition.EntityDefinition.Model.Factories.Entity.Hydrate(entityDefinition, bag); return(entity); }
/// <summary> /// Calculates the sum /// </summary> public FuncParameter Aggregate(IEnumerable<IComparable> myValues, IPropertyDefinition myPropertyDefinition) { var sumType = myPropertyDefinition.BaseType; IComparable sum = null; try { foreach (var value in myValues) { if (sum == null) { sum = ArithmeticOperations.Add(sumType, 0, value); } else { sum = ArithmeticOperations.Add(sumType, sum, value); } } } catch (ArithmeticException) { throw new InvalidArithmeticAggregationException(sumType, this.AggregateName); } return new FuncParameter(sum, myPropertyDefinition); }
public void RemoveProperty(IPropertyDefinition property) { EnsureNotSealed(); if (_properties.Contains(property)) { _properties.Remove(property); } }
public virtual void PrintPropertyDefinitionModifiers(IPropertyDefinition propertyDefinition) { Contract.Requires(propertyDefinition != null); PrintMethodDefinitionModifiers(propertyDefinition.Getter == null ? propertyDefinition.Setter.ResolvedMethod : propertyDefinition.Getter.ResolvedMethod); }
public PropertyDefinition GetPropertyDefinition(IPropertyDefinition item) { return(TryGetOrAdd(_propertycache, item, pdef => { var tdef = GetTypeDefinition(item.DeclaringType); return tdef == null ? null : JustDecompileHelper.FindMatchingProperty(tdef, pdef); })); }
public static readonly Guid MY_ID = new Guid("{4A0F816D-FB62-4E62-B22A-332D38B461C6}"); //Feb2020/dth /// <summary> /// Method called that defines the schema (property, display name, description, ...) for the element. /// This will show on the Simio UI /// </summary> public void DefineSchema(IElementSchema schema) { IPropertyDefinition pd = schema.PropertyDefinitions.AddStringProperty("ExcelWorkbook", String.Empty); pd.DisplayName = "Excel Workbook"; pd.Description = "Path and name to Excel workbook."; pd.Required = true; }
public override void TraverseChildren(IPropertyDefinition propertyDefinition) { if (!_filter.Include(propertyDefinition)) { return; } base.TraverseChildren(propertyDefinition); }
/// <summary> /// Creates a <see cref="PropertyMapping"/> from this descriptor. /// </summary> /// <param name="context">The <see cref="IMansionContext"/>.</param> /// <param name="property">The <see cref="IPropertyDefinition"/>.</param> /// <returns>The created <see cref="PropertyMapping"/>.</returns> protected override SinglePropertyMapping DoCreateSingleMapping(IMansionContext context, IPropertyDefinition property) { // create the mapping return new SingleValuedPropertyMapping(property.Name) { // map the type Type = Properties.Get<string>(context, "type") }; }
/// <summary> /// Returns a C#-like string that corresponds to the signature of the given property definition and that conforms to the specified formatting options. /// </summary> //^ [Pure] public virtual string GetPropertySignature(IPropertyDefinition property, NameFormattingOptions formattingOptions) { StringBuilder sb = new StringBuilder(); this.AppendPropertyName(property, formattingOptions, sb); this.AppendPropertyParameters(property.Parameters, formattingOptions, sb); return(sb.ToString()); }
/// <summary> /// Creates the a <see cref="Column"/>. /// </summary> /// <param name="context">The <see cref="IMansionContext"/>.</param> /// <param name="table">The <see cref="Table"/> to which the column will be added.</param> /// <param name="property">The <see cref="IPropertyDefinition"/>.</param> /// <returns>Returns the created <see cref="Column"/>.</returns> protected virtual Column DoCreate(IMansionContext context, Table table, IPropertyDefinition property) { // get the column name var columnName = Properties.Get<string>(context, "columnName", null) ?? property.Name; // create the column return PropertyColumn.CreatePropertyColumn(context, property.Name, columnName, Properties); }
public override void Visit(IPropertyDefinition propertyDefinition) { if (Process(propertyDefinition)) { visitor.Visit(propertyDefinition); } base.Visit(propertyDefinition); }
public override void TraverseChildren(ITargetExpression targetExpression) { base.TraverseChildren(targetExpression); ITypeReference type = Dummy.TypeReference; ILocalDefinition /*?*/ local = targetExpression.Definition as ILocalDefinition; if (local != null) { if (local.IsReference) { if (local.IsPinned) { type = Immutable.PointerType.GetPointerType(local.Type, this.host.InternFactory); } else { type = Immutable.ManagedPointerType.GetManagedPointerType(local.Type, this.host.InternFactory); } } else { type = local.Type; } } else { IParameterDefinition /*?*/ parameter = targetExpression.Definition as IParameterDefinition; if (parameter != null) { type = parameter.Type; } else { IFieldReference /*?*/ field = targetExpression.Definition as IFieldReference; if (field != null) { type = field.Type; } else { IPropertyDefinition /*?*/ property = targetExpression.Definition as IPropertyDefinition; if (property != null) { type = property.Type; } else { IExpression /*?*/ expression = targetExpression.Definition as IExpression; if (expression != null) { type = expression.Type; } } } } } ((TargetExpression)targetExpression).Type = type; }
/// <summary> /// Method called that defines the property, state, and event schema for the element. /// </summary> public void DefineSchema(IElementSchema schema) { IPropertyDefinition pd = schema.PropertyDefinitions.AddStringProperty("FilePath", String.Empty); pd.Description = "The name of the file path for output."; pd = schema.PropertyDefinitions.AddBooleanProperty("OutputToFile"); pd.Description = "If true, append table information to file each time step is executed"; }
public override void TraverseChildren(IPropertyDefinition property) { if (!MemberHelper.IsVisibleOutsideAssembly(property)) { return; } _assembly.EnrollApi(property); }
public IPropertyDefinition this[string propertyId] { get { IPropertyDefinition propertyDefinition = null; propertyDefintionDict.TryGetValue(propertyId, out propertyDefinition); return(propertyDefinition); } }
public override void Visit(IPropertyDefinition property) { if (IsMemberExternallyVisible2(property)) { // Recursion Visit(property.Parameters); Visit(property.Type); } }
public CciPropertyDetails(IPropertyDefinition property) : base(property) { if (property == null) { throw new ArgumentNullException("property"); } _property = property; }
public ServicePropertyDefinition(IPropertyDefinition myPropertyDefinition) : base(myPropertyDefinition) { this.IsMandatory = myPropertyDefinition.IsMandatory; this.InIndices = myPropertyDefinition.InIndices.Select(x => x.Name).ToList(); this.Multiplicity = ConvertHelper.ToServicePropertyMultiplicity(myPropertyDefinition.Multiplicity); this.IsUserDefinedType = myPropertyDefinition.IsUserDefinedType; this.BaseType = myPropertyDefinition.BaseType.AssemblyQualifiedName; this.DefaultValue = myPropertyDefinition.DefaultValue; }
public override void Visit(IPropertyDefinition property) { IMethodReference getter = property.Getter; IMethodReference setter = property.Setter; if (getter != null) AddMemberReference(getter.ResolvedMethod); if (setter != null) AddMemberReference(setter.ResolvedMethod); base.Visit(property); }
/// <summary> /// Creates the <see cref="Table"/> from the descriptor. /// </summary> /// <param name="context">The <see cref="IMansionContext"/>.</param> /// <param name="schema">The <see cref="Schema"/>in which to create the table.</param> /// <param name="property">The <see cref="IPropertyDefinition"/>.</param> /// <exception cref="ArgumentNullException">Thrown if one of the parameters is null.</exception> public void Create(IMansionContext context, Schema schema, IPropertyDefinition property) { // validate arguments if (context == null) throw new ArgumentNullException("context"); if (schema == null) throw new ArgumentNullException("schema"); if (property == null) throw new ArgumentNullException("property"); // invoke template method DoCreate(context, schema, property); }
/// <summary> /// Creates the a <see cref="Column"/>. /// </summary> /// <param name="context">The <see cref="IMansionContext"/>.</param> /// <param name="table">The <see cref="Table"/> to which the column will be added.</param> /// <param name="property">The <see cref="IPropertyDefinition"/>.</param> /// <returns>Returns the created <see cref="Column"/>.</returns> /// <exception cref="ArgumentNullException">Thrown if one of the parameters is null.</exception> public Column Create(IMansionContext context, Table table, IPropertyDefinition property) { // validate arguments if (context == null) throw new ArgumentNullException("context"); if (property == null) throw new ArgumentNullException("property"); if (table == null) throw new ArgumentNullException("table"); // invoke template method return DoCreate(context, table, property); }
private void WriteAccessorDefinition(IPropertyDefinition property, IMethodDefinition accessor, string accessorType) { WriteSpace(); WriteAttributes(accessor.Attributes, writeInline: true); // If the accessor is an internal call (or a PInvoke) we should put those attributes here as well WriteMethodPseudoCustomAttributes(accessor); if (accessor.Visibility != property.Visibility) WriteVisibility(accessor.Visibility); WriteKeyword(accessorType, noSpace: true); WriteMethodBody(accessor); }
public sxPropertyDefinition(IPropertyTemplate pt) { m_def = null; m_desc = null; m_temp = pt; m_id = m_temp.Id.ToString(); m_displayName = m_temp.DisplayName; m_name = m_temp.SymbolicName; m_cardinality = m_temp.Cardinality; m_choiceList = m_temp.ChoiceList; m_typeID = m_temp.DataType; m_hidden = m_temp.IsHidden; m_required = m_temp.IsValueRequired; }
/// <summary> /// Calculates the maximum /// </summary> public FuncParameter Aggregate(IEnumerable<IComparable> myValues, IPropertyDefinition myPropertyDefinition) { IComparable max = null; foreach (var value in myValues) { if (max == null) { max = value; } else if (max.CompareTo(value) < 0) { max = value; } } return new FuncParameter(max, myPropertyDefinition); }
/// <summary> /// Adds <see cref="PropertyMapping"/>s of <paramref name="property"/> to the given <paramref name="typeMapping"/>. /// </summary> /// <param name="context">The <see cref="IMansionContext"/>.</param> /// <param name="property">The <see cref="IPropertyDefinition"/> of the property for which to add the <see cref="PropertyMapping"/>s.</param> /// <param name="typeMapping">The <see cref="TypeMapping"/> to which to add the new <see cref="PropertyMapping"/>s.</param> protected override void DoAddMappingTo(IMansionContext context, IPropertyDefinition property, TypeMapping typeMapping) { typeMapping.Add(new SingleValuedPropertyMapping("approved") { Type = "boolean" }); typeMapping.Add(new SingleValuedPropertyMapping("archived") { Type = "boolean" }); typeMapping.Add(new SingleValuedPropertyMapping("publicationDate") { Type = "date" }); typeMapping.Add(new SingleValuedPropertyMapping("expirationDate") { Type = "date" }); }
/// <summary> /// Calculates the average /// </summary> public FuncParameter Aggregate(IEnumerable<IComparable> myValues, IPropertyDefinition myPropertyDefinition) { var divType = myPropertyDefinition.BaseType; IComparable sum = null; uint total = 0; foreach (var value in myValues) { if (sum == null) { sum = ArithmeticOperations.Add(divType, 0, value); } else { sum = ArithmeticOperations.Add(divType, sum, value); } total++; } var aggregateResult = ArithmeticOperations.Div(typeof(Double), sum, total); return new FuncParameter(aggregateResult, myPropertyDefinition); }
public virtual void PrintPropertyDefinitionReturnType(IPropertyDefinition propertyDefinition) { PrintTypeReference(propertyDefinition.Type); }
public virtual void PrintPropertyDefinitionVisibility(IPropertyDefinition propertyDefinition) { PrintTypeMemberVisibility(propertyDefinition.Visibility); }
/// <summary> /// Performs some computation with the given property definition. /// </summary> public virtual void Visit(IPropertyDefinition propertyDefinition) { this.Visit((ITypeDefinitionMember)propertyDefinition); }
public IEnumerable<ISonesIndex> GetIndices(IVertexType myVertexType, IPropertyDefinition myPropertyDefinition, SecurityToken mySecurityToken, Int64 myTransactionToken) { myVertexType.CheckNull("myVertexType"); return myVertexType.GetIndexDefinitions(false).Where(_=>_.IndexedProperties.Count == 1 && _.IndexedProperties.Contains(myPropertyDefinition)).Select(_ => _indices[_.ID]); //return myPropertyDefinition.InIndices.Where(_ => myVertexType.Equals(_.VertexType)).Select(_ => _indices[_.ID]); }
/// <summary> /// Performs some computation with the given property definition. /// </summary> public void Visit(IPropertyDefinition propertyDefinition) { this.Visit((ITypeDefinitionMember)propertyDefinition); if (propertyDefinition.IsRuntimeSpecial && !propertyDefinition.IsSpecialName) this.ReportError(MetadataError.RuntimeSpecialMustAlsoBeSpecialName, propertyDefinition); if (propertyDefinition.HasDefaultValue) { var propertyType = propertyDefinition.Type; if (propertyType.IsEnum && propertyType.ResolvedType != Dummy.Type) propertyType = propertyType.ResolvedType.UnderlyingType; if (!TypeHelper.TypesAreEquivalent(propertyDefinition.DefaultValue.Type, propertyDefinition.Type)) this.ReportError(MetadataError.MetadataConstantTypeMismatch, propertyDefinition.DefaultValue, propertyDefinition); } }
/// <summary> /// Extracts method contracts for the accessors and packages them under the property itself. /// </summary> public override void Visit(IPropertyDefinition propertyDefinition) { Contract.Assert(propertyDefinition != null); string propertyId = MemberHelper.GetMemberSignature(propertyDefinition, NameFormattingOptions.DocumentationId); docTracker.WriteLine(propertyId); int contractsCounter = 0; XAccessorContract getterContracts = null; if (propertyDefinition.Getter != null) { var getterMethod = propertyDefinition.Getter.ResolvedMethod; Contract.Assume(getterMethod != null); bool isPure = IsPure(getterMethod); //TODO: Remove, this should be handled on the packager side. ContractPackager packager = new ContractPackager(host, docTracker); packager.PackageMethodContracts(getterMethod, isPure); XContract[] getterContractArray; if (packager.TryGetContracts(out getterContractArray)) { contractsCounter += getterContractArray.Length; docTracker.AddMemberInfo(getterContractArray.Length, MemberKind.Getter); getterContracts = new XAccessorContract(this.host, XAccessorKind.Getter, getterContractArray, docTracker); } } XAccessorContract setterContracts = null; if (propertyDefinition.Setter != null) { var setterMethod = propertyDefinition.Setter.ResolvedMethod; Contract.Assume(setterMethod != null); bool isPure = IsPure(setterMethod); //TODO: Remove, this should be handled on the packager side. ContractPackager packager = new ContractPackager(host, docTracker); packager.PackageMethodContracts(setterMethod, isPure); XContract[] setterContractArray; if (packager.TryGetContracts(out setterContractArray)) { contractsCounter += setterContractArray.Length; docTracker.AddMemberInfo(setterContractArray.Length, MemberKind.Setter); setterContracts = new XAccessorContract(this.host, XAccessorKind.Setter, setterContractArray, docTracker); } } XContract[] accessorContracts = null; if (getterContracts != null && setterContracts != null) accessorContracts = new XContract[2] { getterContracts, setterContracts }; else if (getterContracts != null) accessorContracts = new XContract[1] { getterContracts }; else if (setterContracts != null) accessorContracts = new XContract[1] { setterContracts }; if (accessorContracts != null) { contracts.Add(new KeyValuePair<string, XContract[]>(propertyId, accessorContracts)); } docTracker.AddMemberInfo(contractsCounter, MemberKind.Property); //base.TraverseChildren(propertyDefinition); }
/// <summary> /// Creates the a <see cref="Column"/>. /// </summary> /// <param name="context">The <see cref="IMansionContext"/>.</param> /// <param name="table">The <see cref="Table"/> to which the column will be added.</param> /// <param name="property">The <see cref="IPropertyDefinition"/>.</param> /// <returns>Returns the created <see cref="Column"/>.</returns> protected override Column DoCreate(IMansionContext context, Table table, IPropertyDefinition property) { // create the column return new PermanentIdentityColumn(); }
private void WritePropertyDefinition(IPropertyDefinition property) { bool isInterfaceProp = property.ContainingTypeDefinition.IsInterface; IMethodDefinition accessor = null; IMethodDefinition getter = null; IMethodDefinition setter = null; if (property.Getter != null) { getter = property.Getter.ResolvedMethod; if (!_filter.Include(getter)) getter = null; accessor = getter; } if (property.Setter != null) { setter = property.Setter.ResolvedMethod; if (!_filter.Include(setter)) setter = null; if (accessor == null) accessor = setter; } if (accessor == null) return; bool isIndexer = accessor.ParameterCount > (accessor == setter ? 1 : 0); if (isIndexer) { string id = property.Name.Value; int index = id.LastIndexOf("."); if (index >= 0) id = id.Substring(index + 1); if (id != "Item") { WriteFakeAttribute("System.Runtime.CompilerServices.IndexerName", "\"" + id + "\""); } } WriteAttributes(property.Attributes); if (!isInterfaceProp) { if (!accessor.IsExplicitInterfaceMethod()) WriteVisibility(property.Visibility); // Getter and Setter modifiers should be the same WriteMethodModifiers(accessor); } if (property.GetHiddenBaseProperty(_filter) != Dummy.Property) WriteKeyword("new"); WriteTypeName(property.Type); if (isIndexer) { int index = property.Name.Value.LastIndexOf("."); if (index >= 0) WriteIdentifier(property.Name.Value.Substring(0, index + 1) + "this", false); // +1 to include the '.' else WriteIdentifier("this", false); var parameters = new List<IParameterDefinition>(accessor.Parameters); if (accessor == setter) // If setter remove value parameter. parameters.RemoveAt(parameters.Count - 1); WriteParameters(parameters, true); } else { WriteIdentifier(property.Name); } WriteSpace(); WriteSymbol("{"); //get if (getter != null) { WriteAccessorDefinition(property, getter, "get"); } //set if (setter != null) { WriteAccessorDefinition(property, setter, "set"); } WriteSpace(); WriteSymbol("}"); }
public virtual void onMetadataElement(IPropertyDefinition propertyDefinition) { }
public Property(IPropertyDefinition propertyDefinition, IList<object> values) { PropertyDefinition = propertyDefinition; Values = values; }
public override void TraverseChildren(IPropertyDefinition propertyDefinition) { PrintAttributes(propertyDefinition); bool isIndexer = false; if (IteratorHelper.EnumerableIsNotEmpty(propertyDefinition.Parameters)) { // We have an indexer. Note that this could still be an explicit interface implementation. // If it's got a name other than 'Item', we need an attribute to rename it. // Note that there will usually be a DefaultMemberAttribute on the class with the name // but the attribute doesn't always exist (eg. if it's an explicit interaface impl) isIndexer = true; string id = propertyDefinition.Name.Value; string simpleId = id.Substring(id.LastIndexOf('.') + 1); // excludes any interface type if (simpleId != "Item") { PrintPseudoCustomAttribute(propertyDefinition, "System.Runtime.CompilerServices.IndexerName", QuoteString(simpleId), true, null); } } PrintToken(VBToken.Indent); IMethodDefinition propMeth = propertyDefinition.Getter == null ? propertyDefinition.Setter.ResolvedMethod : propertyDefinition.Getter.ResolvedMethod; if (!propertyDefinition.ContainingTypeDefinition.IsInterface && IteratorHelper.EnumerableIsEmpty(MemberHelper.GetExplicitlyOverriddenMethods(propMeth))) PrintPropertyDefinitionVisibility(propertyDefinition); PrintPropertyDefinitionModifiers(propertyDefinition); PrintPropertyDefinitionReturnType(propertyDefinition); PrintToken(VBToken.Space); if (isIndexer) { // Indexers are always identified with a 'this' keyword, but might have an interface prefix string id = propertyDefinition.Name.Value; int lastDot = id.LastIndexOf('.'); if (lastDot != -1) sourceEmitterOutput.Write(id.Substring(0, lastDot +1)); PrintToken(VBToken.This); PrintToken(VBToken.LeftSquareBracket); bool fFirstParameter = true; var parms = propertyDefinition.Parameters; if (propertyDefinition.Getter != null) parms = propertyDefinition.Getter.ResolvedMethod.Parameters; // more likely to have names else if (propertyDefinition.Setter != null) { // Use the setter's names except for the final 'value' parameter var l = new List<IParameterDefinition>(propertyDefinition.Setter.ResolvedMethod.Parameters); l.RemoveAt(l.Count - 1); parms = l; } foreach (IParameterDefinition parameterDefinition in parms) { if (!fFirstParameter) PrintParameterListDelimiter(); this.Traverse(parameterDefinition); fFirstParameter = false; } PrintToken(VBToken.RightSquareBracket); } else { PrintPropertyDefinitionName(propertyDefinition); } //PrintToken(CSharpToken.LeftCurly); if (propertyDefinition.Getter != null) { PrintToken(VBToken.Indent); var getMeth = propertyDefinition.Getter.ResolvedMethod; if (getMeth.Visibility != propertyDefinition.Visibility) PrintTypeMemberVisibility(getMeth.Visibility); PrintToken(VBToken.Get); if (getMeth.IsAbstract || getMeth.IsExternal) PrintToken(VBToken.Semicolon); else Traverse(getMeth.Body); } if (propertyDefinition.Setter != null) { PrintToken(VBToken.Indent); var setMeth = propertyDefinition.Setter.ResolvedMethod; if (setMeth.Visibility != propertyDefinition.Visibility) PrintTypeMemberVisibility(setMeth.Visibility); PrintToken(VBToken.Set); if (setMeth.IsAbstract || setMeth.IsExternal) PrintToken(VBToken.Semicolon); else Traverse(setMeth.Body); } //PrintToken(CSharpToken.RightCurly); }
public IEnumerable<ISonesIndex> GetIndices(IPropertyDefinition myPropertyDefinition, SecurityToken mySecurityToken, Int64 myTransactionToken) { return myPropertyDefinition.InIndices.Select(_ => _indices[_.ID]); }
public virtual void PrintPropertyDefinitionName(IPropertyDefinition propertyDefinition) { PrintIdentifier(propertyDefinition.Name); }
public bool HasIndex(IPropertyDefinition myPropertyDefinition, SecurityToken mySecurityToken, Int64 myTransactionToken) { return myPropertyDefinition.InIndices.CountIsGreater(0); }
public virtual void PrintPropertyDefinitionModifiers(IPropertyDefinition propertyDefinition) { PrintMethodDefinitionModifiers(propertyDefinition.Getter == null ? propertyDefinition.Setter.ResolvedMethod : propertyDefinition.Getter.ResolvedMethod); }