private static IEnumerable<string> GetPropertyTags(ContentData content, PropertyDefinition propertyDefinition) { var tagNames = content[propertyDefinition.Name] as string; return tagNames == null ? Enumerable.Empty<string>() : tagNames.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries); }
private void DoPropertyBind(PropertyTreeBinderImpl parent, PropertyTreeMetaObject target, PropertyTreeNavigator navigator, PropertyDefinition property) { object ancestor = null; PropertyTreeMetaObject ancestorMeta = null; if (property.IsExtender) { var ancestorType = property.DeclaringTreeDefinition.SourceClrType; ancestorMeta = target.GetAncestors().Cast<PropertyTreeMetaObject>().FirstOrDefault( t => ancestorType.IsAssignableFrom(t.ComponentType)); if (ancestorMeta != null) ancestor = ancestorMeta.Component; } var component = target.Component; PropertyTreeMetaObject propertyTarget = target.CreateChild(property, navigator.QualifiedName, ancestorMeta); var services = new PropertyBindContext( component, property, ServiceProvider.Compose(ServiceProvider.FromValue(navigator), parent)) { LineNumber = navigator.LineNumber, LinePosition = navigator.LinePosition, }; propertyTarget = parent.Bind(propertyTarget, navigator, services); target.BindSetMember(property, navigator.QualifiedName, propertyTarget, ancestorMeta, services); }
public void Read(ClrModuleReader reader) { this.PropertyDefinition = new PropertyDefinition(); this.PropertyDefinition.Attributes = (PropertyAttributes)reader.Binary.ReadUInt16(); this.PropertyDefinition.Name = reader.ReadString(); this.Type = reader.ReadPropertySignature(); }
public override void AssignToProperty(object obj, PropertyDefinition property) { if (property.CanSet) property.SetOn(obj, GetTypedValue(collectionDef)); else if (property.CanGet) PopulateCollection(collectionDef, property.GetFrom(obj)); }
public PropertyMapDefinition() { this.Source = new ObjectDefinition(); this.Target = new ObjectDefinition(); this.SourceProp = new PropertyDefinition(); this.TargetProp = new PropertyDefinition(); }
static PropertyDefinition CreateProperty() { var prop = new PropertyDefinition(Generate.Name.ForMethod(), PropertyAttributes.None, TestModule.TypeSystem.Boolean); TestType.Properties.Add(prop); prop.DeclaringType = TestType; return prop; }
public RequiredRule(PropertyDefinition propertyDefinition) : base(propertyDefinition) { base.Assertion = oi => !String.IsNullOrWhiteSpace(oi.GetUntypedValue(propertyDefinition).StringValue); base.ErrorMessageStaticGenerator = () => $"'{propertyDefinition.CurrentName}' is required."; }
private IObservable<object> GetObservableFromProperty(PropertyDefinition subscription) { return Observable.FromEventPattern<PropertyChangedEventHandler, PropertyChangedEventArgs>( parentOnPropertyChanged => subscription.Parent.PropertyChanged += parentOnPropertyChanged, parentOnPropertyChanged => subscription.Parent.PropertyChanged -= parentOnPropertyChanged) .Where(pattern => pattern.EventArgs.PropertyName == subscription.PropertyName) .Select(pattern => _mountPoint.Value); }
/// <summary> /// Initializes a new instance of the <see cref="PropertyBasedScheduleConditionDefinition"/> class. /// </summary> /// <param name="contractName">The contract name that is used to identify the current condition.</param> /// <param name="property">The property that will provide the condition result.</param> private PropertyBasedScheduleConditionDefinition(string contractName, PropertyDefinition property) : base(contractName) { { Debug.Assert(property != null, "The property object should not be null."); } m_Property = property; }
public override void AssignToProperty(object obj, PropertyDefinition property) { if (property.CanSet) { property.SetOn(obj, GetTypedValue()); } else if (property.CanGet) { typedDictionary = property.GetFrom(obj) as IDictionary; PopulateDictionary(); } }
/// <summary> /// Initializes a new instance of the <see cref="PropertyBasedExportDefinition"/> class. /// </summary> /// <param name="contractName">The contract name that is used to identify the current export.</param> /// <param name="declaringType">The type that declares the property on which the import is placed.</param> /// <param name="property">The property for which the current object stores the serialized data.</param> private PropertyBasedExportDefinition( string contractName, TypeIdentity declaringType, PropertyDefinition property) : base(contractName, declaringType) { { Debug.Assert(property != null, "The property object shouldn't be null."); } m_Property = property; }
/// <summary> /// Creates the text block control. /// </summary> /// <param name="property">The property.</param> /// <returns> /// /// </returns> protected virtual FrameworkElement CreateTextBlockControl(PropertyDefinition property) { var tb = new TextBlock { HorizontalAlignment = property.HorizontalAlignment, VerticalAlignment = VerticalAlignment.Center, Padding = new Thickness(4, 0, 4, 0) }; tb.SetBinding(TextBlock.TextProperty, property.CreateOneWayBinding()); return tb; }
public override FrameworkElement CreateEditControl(PropertyDefinition propertyDefinition, string bindingPath) { var control = propertyDefinition.CreateEditControl(bindingPath); if (control != null) return control; var ctl = CreateExtendedToolkitControl(propertyDefinition, bindingPath); if (ctl != null) return ctl; return base.CreateEditControl(propertyDefinition, bindingPath); }
static PropertyDefinition CreateProperty() { var prop = new PropertyDefinition(Generate.Name.ForMethod(), PropertyAttributes.None, TestModule.TypeSystem.Boolean); TestType.Properties.Add(prop); prop.DeclaringType = TestType; prop.GetMethod = TestType.CreateMethod("get_" + prop.Name) .Returns<bool>() .AppendIL() .Ldc(true) .Ret() .MethodDefinition; return prop; }
public TypeConvertableRule(PropertyDefinition propertyDefinition) : base(propertyDefinition) { base.Assertion = oi => { var propertyValue = oi.GetUntypedValue(propertyDefinition); //a type is converted at the time it's string value is set, so all we need to do is check to see if that was successful. return propertyValue.TypedValueIsAvailable; }; base.ErrorMessageStaticGenerator = () => $"{propertyDefinition.CurrentName} must be a valid {(App.CurrentContext.IsHumanInterface ? GetHumanNameForType(propertyDefinition.ValueType) : propertyDefinition.ValueType.ToString())}."; }
/// <summary> /// Creates the edit control. /// </summary> /// <param name="property">The property.</param> /// <param name="instance">The instance.</param> /// <returns> /// The control. /// </returns> public virtual FrameworkElement CreateEditControl(PropertyDefinition property, object instance) { var propertyType = property.Descriptor.PropertyType; if (property.ItemsSourceProperty != null || property.ItemsSource != null) return CreateComboBox(property); if (propertyType.Is(typeof(Color))) { return this.CreateColorPickerControl(property); } return CreateTextBox(property); }
internal static CilProperty Create(PropertyDefinition propertyDef, int token, ref CilReaders readers, CilTypeDefinition typeDefinition) { CilProperty property = new CilProperty(); property._typeDefinition = typeDefinition; property._propertyDef = propertyDef; property._readers = readers; property._isSignatureInitialized = false; property._isDefaultValueInitialized = false; property._isGetterInitialized = false; property._isSetterInitialized = false; property._token = token; property._accessors = propertyDef.GetAccessors(); return property; }
/// <summary> /// Creates the display control. /// </summary> /// <param name="property">The property.</param> /// <param name="instance">The instance.</param> /// <returns> /// The control. /// </returns> public virtual FrameworkElement CreateDisplayControl(PropertyDefinition property, object instance) { var propertyType = property.Descriptor.PropertyType; if (propertyType.Is(typeof(bool))) { return this.CreateCheckBoxControl(property); } if (propertyType.Is(typeof(Color))) { return this.CreateColorPreviewControl(property); } return this.CreateTextBlockControl(property); }
public InvalidStringRule(PropertyDefinition propertyDefinition, params string[] invalidStrings) : base(propertyDefinition) { InvalidStrings = invalidStrings; base.Assertion = oi => { var stringValue = oi.GetUntypedValue(propertyDefinition).StringValue; if (stringValue == null) { return true; } return !InvalidStrings.Any(ic => stringValue.Contains(ic)); }; base.ErrorMessageStaticGenerator = () => $"'{propertyDefinition.CurrentName}' cannot contain any of the following values {string.Join(",", InvalidStrings)}."; }
public RangeRule(PropertyDefinition propertyDefinition, object minValue, object maxValue) : base(propertyDefinition) { MinimumValue = minValue; MaximumValue = maxValue; base.Assertion = oi => { var stringValue = oi.GetUntypedValue(propertyDefinition).StringValue; if (stringValue == null) { return true; } Type propertyType = propertyDefinition.ValueType; object min; object max; try { min = Convert.ChangeType(MinimumValue, propertyType); max = Convert.ChangeType(MaximumValue, propertyType); } catch (InvalidCastException cx) { return false; } var objValue = oi.GetUntypedValue(propertyDefinition).Value; if (propertyType == typeof(int)) { return (int)objValue >= (int)minValue && (int)objValue <= (int)maxValue; } if (propertyType == typeof(double) || propertyType == typeof(float)) { return (double)objValue >= (double)minValue && (double)objValue <= (double)maxValue; } if (propertyType == typeof(DateTime) || propertyType == typeof(DateTime)) { return (DateTime)objValue >= (DateTime)minValue && (DateTime)objValue <= (DateTime)maxValue; } throw new InvalidOperationException("Range type must be one of the following types: int, float, double, DateTime"); }; base.ErrorMessageStaticGenerator = () => $"'{propertyDefinition.CurrentName}' must be between {MinimumValue} and {MaximumValue}."; }
public RegexRule(PropertyDefinition propertyDefinition, string pattern) : base(propertyDefinition) { Pattern = pattern; base.Assertion = oi => { var stringValue = oi.GetUntypedValue(propertyDefinition).StringValue; if (stringValue == null) { return true; } return new Regex(pattern, RegexOptions.IgnoreCase).IsMatch(stringValue); }; base.ErrorMessageStaticGenerator = () => $"'{propertyDefinition.CurrentName}' must match the pattern {Pattern}."; }
public StringLengthRule(PropertyDefinition propertyDefinition, int minLength, int maxLength) : base(propertyDefinition) { MinimumLength = minLength; MaximumLength = maxLength; base.Assertion = oi => { var stringValue = oi.GetUntypedValue(propertyDefinition).StringValue; if (stringValue == null) { return true; } return stringValue.Length >= MinimumLength && stringValue.Length <= MaximumLength; }; base.ErrorMessageStaticGenerator = () => $"'{propertyDefinition.CurrentName}' must be between {MinimumLength} and {MaximumLength}."; }
/// <summary> /// Initializes a new instance of the <see cref="PropertyBasedImportDefinition"/> class. /// </summary> /// <param name="contractName">The contract name that is used to identify the current import.</param> /// <param name="requiredTypeIdentity">The type identity of the export type expected.</param> /// <param name="cardinality"> /// One of the enumeration values that indicates the cardinality of the export object required by the import definition. /// </param> /// <param name="isRecomposable"> /// <see langword="true" /> to specify that the import definition can be satisfied multiple times throughout the lifetime of a parts; /// otherwise, <see langword="false" />. /// </param> /// <param name="creationPolicy"> /// A value that indicates that the importer requires a specific creation policy for the exports used to satisfy this import. /// </param> /// <param name="declaringType">The type that defines the property.</param> /// <param name="property">The property for which the current object stores the serialized data.</param> private PropertyBasedImportDefinition( string contractName, TypeIdentity requiredTypeIdentity, ImportCardinality cardinality, bool isRecomposable, CreationPolicy creationPolicy, TypeIdentity declaringType, PropertyDefinition property) : base(contractName, requiredTypeIdentity, cardinality, isRecomposable, false, creationPolicy, declaringType) { { Lokad.Enforce.Argument(() => property); } m_Property = property; }
protected void Add(PropertyDefinition source, SchemaConverter.Getter getter, SchemaConverter.Setter setter) { this.mapping.Add(source, new KeyValuePair <SchemaConverter.Getter, SchemaConverter.Setter>(getter, setter)); }
internal static bool IsCollection(this PropertyDefinition property, System.Type elementType) { return(property.IsCollection(out _) && ((GenericInstanceType)property.PropertyType).GenericArguments.Last().FullName == elementType.FullName); }
internal static bool IsString(this PropertyDefinition property) { return(property.PropertyType.FullName == StringTypeName); }
internal static bool IsObjectId(this PropertyDefinition property) { return(property.PropertyType.FullName == ObjectIdTypeName); }
internal static bool IsRequired(this PropertyDefinition property, ImportedReferences references) { Debug.Assert(property.DeclaringType.IsValidRealmObjectBaseInheritor(references), "Required properties only make sense on RealmObject/EmbeddedObject classes"); return(property.CustomAttributes.Any(a => a.AttributeType.Name == "RequiredAttribute")); }
internal static bool IsDescendantOf(this PropertyDefinition property, TypeReference other) { return(property.PropertyType.Resolve().BaseType.IsSameAs(other)); }
internal static bool IsISet(this PropertyDefinition property) { return(property.IsType("ISet`1", "System.Collections.Generic")); }
public GetAccessorDiffItem(PropertyDefinition oldProperty, PropertyDefinition newProperty, IEnumerable <IDiffItem> declarationDiffs) : base(oldProperty.GetMethod, newProperty.GetMethod, declarationDiffs, null) { }
public static IEditable DefaultEditableFactory(PropertyDefinition pd) { if (pd.Editable != null) return null; if (pd.Info != null && pd.Info.DeclaringType == typeof(ContentItem)) { if (pd.Name == "Title") return new WithEditableTitleAttribute(); if (pd.Name == "Name") return new WithEditableNameAttribute(); return null; } if (pd.PropertyType == typeof(string)) { if (pd.Name.Contains("Image")) return new EditableImageUploadAttribute(); if (pd.Name.Contains("Url")) return new EditableUrlAttribute(); if (pd.Name.Contains("Text") || pd.Name.Contains("Body") || pd.Name.Contains("Main")) return new EditableFreeTextAreaAttribute(); if (pd.Name.Contains("Theme")) return new EditableThemeSelectionAttribute(); if (pd.Name.Contains("Language")) return new EditableLanguagesDropDownAttribute(); if (pd.Name.Contains("Media")) return new EditableMediaUploadAttribute(); if (pd.Name.Contains("Meta")) return new EditableMetaTagAttribute(); if (pd.Name.Contains("Folder")) return new EditableFolderSelectionAttribute(); if (pd.Name.Contains("File")) return new EditableFileUploadAttribute(); return new EditableTextAttribute(); } if (pd.PropertyType == typeof(DateTime) || pd.PropertyType == typeof(DateTime?)) return new EditableDateAttribute(); if (pd.PropertyType == typeof(int)) return new EditableNumberAttribute(); if (pd.PropertyType.IsEnum) return new EditableEnumAttribute(pd.PropertyType); if (pd.PropertyType == typeof(ContentItem)) return new EditableLinkAttribute(); if (typeof(ContentItem).IsAssignableFrom(pd.PropertyType)) return new EditableItemSelectionAttribute(pd.PropertyType); if (pd.PropertyType.IsGenericType) { if (typeof(IEnumerable<>).IsAssignableFrom(pd.PropertyType.GetGenericTypeDefinition())) { var genericArgument = pd.PropertyType.GetGenericArguments()[0]; if (typeof(ContentItem).IsAssignableFrom(genericArgument)) { if (pd.Name.Contains("Children")) return new EditableChildrenAttribute() { ZoneName = pd.Name }; return new EditableMultipleItemSelectionAttribute(genericArgument); } if (genericArgument == typeof(string)) { if (pd.Name.Contains("Tag")) return new EditableTagsAttribute(); } } return null; } return null; }
/// <summary> /// Creates a edit control and bind it to the current cell element. /// </summary> /// <param name="cell">The cell reference.</param> /// <param name="pd">The <see cref="PropertyDefinition" />.</param> /// <returns> /// The <see cref="FrameworkElement" />. /// </returns> private FrameworkElement CreateEditControl(CellRef cell, PropertyDefinition pd) { return this.Operator.CreateEditControl(cell, pd); }
public virtual void ReadSemantic (PropertyDefinition prop) { }
public static TypeDefinition DeserializeTypeDefinition(BinaryReader reader) { string @namespace = reader.ReadString(); string typeName = reader.ReadString(); TypeAttributes attributes = (TypeAttributes)reader.ReadUInt32(); TypeDefinition type = new TypeDefinition( @namespace, typeName, attributes ); if (reader.ReadBoolean()) { int nestedTypeCount = reader.ReadInt32(); for (int i = 0; i < nestedTypeCount; i++) { type.NestedTypes.Add(DeserializeTypeDefinition(reader)); } } if (reader.ReadBoolean()) { type.BaseType = DeserializeTypeReference(reader); } else if (type.IsInterface) { type.BaseType = null; } else { type.BaseType = ModuleUtils.TerrariaModule.ImportReference(typeof(object)); } if (reader.ReadBoolean()) { int genericParameterCount = reader.ReadInt32(); for (int i = 0; i < genericParameterCount; i++) { type.GenericParameters.Add(DeserializeGenericParameter(reader)); } } int fieldCount = reader.ReadInt32(); for (int i = 0; i < fieldCount; i++) { type.Fields.Add(DeserializeFieldDefinition(reader)); } int methodCount = reader.ReadInt32(); for (int i = 0; i < methodCount; i++) { type.Methods.Add(DeserializeMethodDefinition(reader)); } int propertyCount = reader.ReadInt32(); for (int i = 0; i < propertyCount; i++) { PropertyDefinition property = DeserializePropertyDefinition(reader); string genericTypeName = type.Name.Contains('<') && !type.Name.Contains("AnonymousType") ? type.FullName + "." : ""; property.GetMethod = type.Methods.Where(m => m.Name.EndsWith("get_" + property.Name)).First(); MethodDefinition setter = type.Methods.Where(m => m.Name == "set_" + property.Name).FirstOrDefault(); if (setter != null) { property.SetMethod = setter; } type.Properties.Add(property); } return(type); }
public void RaisePropertyValueReadEvent(DomainObject domainObject, PropertyDefinition propertyDefinition, object value, ValueAccess valueAccess) { }
internal static bool IsCollection(this PropertyDefinition property, TypeReference elementType) { return((IsIList(property) || IsISet(property)) && ((GenericInstanceType)property.PropertyType).GenericArguments.Last().IsSameAs(elementType)); }
private static bool IsType(this PropertyDefinition property, string name, string @namespace) { return(property.PropertyType.Name == name && property.PropertyType.Namespace == @namespace); }
internal static bool IsIDictionary(this PropertyDefinition property) { return(property.IsType("IDictionary`2", "System.Collections.Generic")); }
public static bool CanShow(PropertyDefinition property) { var accessor = property.GetMethod ?? property.SetMethod; return(accessor.IsVirtual && !accessor.IsFinal && !accessor.DeclaringType.IsInterface); }
internal static bool IsAutomatic(this PropertyDefinition property) { return(property.GetMethod.CustomAttributes.Any(attr => attr.AttributeType.FullName == typeof(CompilerGeneratedAttribute).FullName)); }
public GtkFactoryInvocationArgs(PropertyDefinition aState, System.Type aDataSourceType, string aPropertyName) : this(aState, aDataSourceType, aPropertyName, null) { }
public static bool ContainsEmbeddedObject(this PropertyDefinition property, ImportedReferences references) => property.PropertyType.Resolve().IsEmbeddedObjectInheritor(references);
public GtkFactoryInvocationArgs(PropertyDefinition aState, System.Type aDataSourceType, string aPropertyName, object aDataSource) : base(aState, aDataSourceType, aPropertyName, aDataSource) { AddFilter("Gtk"); }
public static void SerializePropertyDefinition(PropertyDefinition property, BinaryWriter writer) { writer.Write(property.Name.Contains('.') ? property.Name.Split('.').Last() : property.Name); writer.Write((ushort)property.Attributes); SerializeTypeReference(property.PropertyType, writer); }
/// <summary> /// Weaves a property that is decorated with a ComputedAttribute. /// </summary> /// <param name="propertyDefinition">The definition of the property.</param> private void WeaveProperty(PropertyDefinition propertyDefinition) { // property name var computedName = propertyDefinition.Name; var propertyType = propertyDefinition.PropertyType; var moduleDefinition = propertyDefinition.Module; var declaringType = propertyDefinition.DeclaringType; var computedAttribute = propertyDefinition.CustomAttributes.SingleOrDefault(x => x.AttributeType.FullName == this.computedAttributeReference.FullName); // default enhancer var defaultEhancerType = this.deepEnhancerReference; TypeReference equalityComparerType = null; var keepAlive = false; var requiresReaction = false; int boolIndex = 0; foreach (var ca in computedAttribute.ConstructorArguments) { if (ca.Type == moduleDefinition.TypeSystem.String) { computedName = ca.Value as string; } if (ca.Type.FullName == typeof(Type).FullName) { if (ca.Value != null && ca.Value is TypeReference) { equalityComparerType = moduleDefinition.ImportReference(ca.Value as TypeReference); } } if (ca.Type == moduleDefinition.TypeSystem.Boolean) { if (boolIndex++ == 0) { requiresReaction = (bool)ca.Value; } else { keepAlive = (bool)ca.Value; } } } FieldDefinition observableObjectField = this.CreateObservableObjectField(declaringType, defaultEhancerType); if (propertyDefinition.GetMethod != null) { var methodDefinition = propertyDefinition.GetMethod; // push IL code for initialization of a computed member to the queue to emit in the ISharedState setter. this.ProcessorQueue.SharedStateAssignmentQueue.Enqueue( (declaringType, false, (processor, sharedStateBackingField) => this.EmitComputedMemberAdd( processor, computedName, methodDefinition, propertyDefinition.SetMethod, equalityComparerType, requiresReaction, keepAlive, observableObjectField))); var fieldAttributes = FieldAttributes.Private; if (methodDefinition.IsStatic) { fieldAttributes |= FieldAttributes.Static; } // add entrance counter field. var entranceCounterDefinition = declaringType.CreateField(moduleDefinition.TypeSystem.Int32, $"{InnerCounterFieldPrefix}{methodDefinition.Name}_EntranceCount", fieldAttributes); // extend the method body. this.ExtendGetMethodBody(methodDefinition, computedName, entranceCounterDefinition, observableObjectField); } if (propertyDefinition.SetMethod != null) { var methodDefinition = propertyDefinition.SetMethod; var fieldAttributes = FieldAttributes.Private; if (methodDefinition.IsStatic) { fieldAttributes |= FieldAttributes.Static; } // add entrance counter field. var entranceCounterDefinition = declaringType.CreateField(moduleDefinition.TypeSystem.Int32, $"{InnerCounterFieldPrefix}{methodDefinition.Name}_EntranceCount", fieldAttributes); // extend the method body. this.ExtendSetMethodBody(methodDefinition, computedName, entranceCounterDefinition, observableObjectField); } }
internal static bool IsRealmValue(this PropertyDefinition property) { return(property.PropertyType.FullName == RealmValueTypeName); }
public void VisitProperty(PropertyDefinition property, StringBuilder builder) { builder.Append("P:"); PartVisitor.Instance.VisitProperty(property, builder); }
internal static bool IsGuid(this PropertyDefinition property) { return(property.PropertyType.FullName == GuidTypeName); }
/// <summary> /// Gets the C# code defining the specified property. /// </summary> public static string GetDefinition(PropertyDefinition property) { var definitionBuilder = new StringBuilder(); AppendCustomAttributes(definitionBuilder, property.GetCustomAttributes()); // "public" definitionBuilder.Append("public "); // "static" if (property.GetMethod?.IsStatic == true || property.SetMethod?.IsStatic == true) { definitionBuilder.Append("static "); } // type definitionBuilder.Append(GetDisplayName(property.PropertyType)); definitionBuilder.Append(" "); // property name or "this" if the property is an indexer if (property.HasParameters) { definitionBuilder.Append("this"); // parameters (for indexers) definitionBuilder.Append("["); definitionBuilder.AppendJoin( ", ", property.Parameters.Select(GetDefinition) ); definitionBuilder.Append("]"); } else { definitionBuilder.Append(property.Name); } definitionBuilder.Append(" "); // getter and setter var hasGetter = property.GetMethod?.IsPublic == true; var hasSetter = property.SetMethod?.IsPublic == true; definitionBuilder.Append("{ "); if (hasGetter) { definitionBuilder.Append("get;"); } if (hasSetter) { if (hasGetter) { definitionBuilder.Append(" "); } definitionBuilder.Append("set;"); } definitionBuilder.Append(" }"); return(definitionBuilder.ToString()); }
public void RaisePropertyValueChangedEvent(DomainObject domainObject, PropertyDefinition propertyDefinition, object oldValue, object newValue) { }
private void GenerateProxy(TypeDefinition from, TypeDefinition to, TypeReference fromRef, MethodReference wrapperCtor, FieldReference wrapperField) { ILProcessor il; foreach (MethodDefinition method in from.Methods) { if (method.IsRuntimeSpecialName || !method.IsPublic) { continue; } MethodDefinition proxy = new MethodDefinition(method.Name, method.Attributes, method.ReturnType); to.Methods.Add(proxy); foreach (GenericParameter genParam in method.GenericParameters) { proxy.GenericParameters.Add(genParam.Relink(WrappedRelinker, proxy)); } foreach (ParameterDefinition param in method.Parameters) { proxy.Parameters.Add(param.Relink(WrappedRelinker, proxy)); } foreach (CustomAttribute attrib in method.CustomAttributes) { proxy.CustomAttributes.Add(attrib.Relink(WrappedRelinker, proxy)); } proxy.ReturnType = proxy.ReturnType?.Relink(WrappedRelinker, proxy); proxy.Body = new MethodBody(proxy); il = proxy.Body.GetILProcessor(); if (method.ReturnType.GetElementType().FullName == from.FullName) { il.Emit(OpCodes.Newobj, wrapperCtor); il.Emit(OpCodes.Dup); } MethodReference methodRef = method.Relink(Relinker, proxy); methodRef.DeclaringType = fromRef ?? methodRef.DeclaringType; if (proxy.GenericParameters.Count != 0) { GenericInstanceMethod methodRefGen = new GenericInstanceMethod(methodRef); foreach (GenericParameter genParam in proxy.GenericParameters) { methodRefGen.GenericArguments.Add(genParam); } methodRef = methodRefGen; } if (!method.IsStatic) { il.Emit(OpCodes.Ldarg_0); il.Emit(OpCodes.Ldfld, wrapperField); for (int i = 0; i < method.Parameters.Count; i++) { il.Emit(OpCodes.Ldarg, i + 1); if (method.Parameters[i].ParameterType.GetElementType().FullName == from.FullName) { il.Emit(OpCodes.Ldfld, wrapperField); } } il.Emit(OpCodes.Callvirt, methodRef); } else { for (int i = 0; i < method.Parameters.Count; i++) { il.Emit(OpCodes.Ldarg, i); if (method.Parameters[i].ParameterType.GetElementType().FullName == from.FullName) { il.Emit(OpCodes.Ldfld, wrapperField); } } il.Emit(OpCodes.Call, methodRef); } if (method.ReturnType.GetElementType().FullName == from.FullName) { il.Emit(OpCodes.Stfld, wrapperField); } il.Emit(OpCodes.Ret); } foreach (PropertyDefinition prop in from.Properties) { PropertyDefinition proxy = new PropertyDefinition(prop.Name, prop.Attributes, prop.PropertyType.Relink(WrappedRelinker, to)); to.Properties.Add(proxy); MethodDefinition proxyMethod; if (prop.GetMethod != null) { if ((proxyMethod = to.FindMethod(prop.GetMethod.GetFindableID(withType: false))) == null) { goto Next; } proxy.GetMethod = proxyMethod; } if (prop.SetMethod != null) { if ((proxyMethod = to.FindMethod(prop.SetMethod.GetFindableID(withType: false))) == null) { goto Next; } proxy.SetMethod = proxyMethod; } foreach (MethodDefinition method in prop.OtherMethods) { if ((proxyMethod = to.FindMethod(method.GetFindableID(withType: false))) == null) { goto Next; } proxy.OtherMethods.Add(proxyMethod); } Next : continue; } foreach (EventDefinition evt in from.Events) { EventDefinition proxy = new EventDefinition(evt.Name, evt.Attributes, evt.EventType.Relink(WrappedRelinker, to)); to.Events.Add(proxy); MethodDefinition proxyMethod; if (evt.AddMethod != null) { if ((proxyMethod = to.FindMethod(evt.AddMethod.GetFindableID(withType: false))) == null) { goto Next; } proxy.AddMethod = proxyMethod; } if (evt.RemoveMethod != null) { if ((proxyMethod = to.FindMethod(evt.RemoveMethod.GetFindableID(withType: false))) == null) { goto Next; } proxy.RemoveMethod = proxyMethod; } if (evt.InvokeMethod != null) { if ((proxyMethod = to.FindMethod(evt.InvokeMethod.GetFindableID(withType: false))) == null) { goto Next; } proxy.InvokeMethod = proxyMethod; } foreach (MethodDefinition method in evt.OtherMethods) { if ((proxyMethod = to.FindMethod(method.GetFindableID(withType: false))) == null) { goto Next; } proxy.OtherMethods.Add(proxyMethod); } Next : continue; } }
/// <summary> /// Creates the check box control. /// </summary> /// <param name="property">The property.</param> /// <returns></returns> protected virtual FrameworkElement CreateCheckBoxControl(PropertyDefinition property) { var c = new CheckBox { VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = property.HorizontalAlignment }; c.SetBinding(ToggleButton.IsCheckedProperty, property.CreateBinding()); return c; }
bool IVersionable.IsPropertyAccessible(PropertyDefinition propertyDefinition) { return(this.AdDlpPolicy.IsPropertyAccessible(propertyDefinition)); }
public virtual void ReadConstant (PropertyDefinition prop) { }
public virtual bool IsSupportedProperty(PropertyDefinition pdef) { return(IsSupported(pdef.PropertyType)); }
/// <summary> /// Creates the display control for the specified cell. /// </summary> /// <param name="cell">The cell.</param> /// <param name="pd">The property definition.</param> /// <param name="item">The item.</param> /// <returns> /// The display control. /// </returns> protected virtual UIElement CreateDisplayControl(CellRef cell, PropertyDefinition pd, object item) { FrameworkElement element = null; if (item == null) { item = this.GetItem(cell); } if (pd == null) { pd = this.GetPropertyDefinition(cell); } if (pd != null && item != null) { element = this.CreateDisplayControl(cell, pd); this.SetElementDataContext(element, pd, item); element.SourceUpdated += (s, e) => this.CurrentCellSourceUpdated(s, e, cell); element.VerticalAlignment = VerticalAlignment.Center; element.HorizontalAlignment = pd.HorizontalAlignment; } return element; }
protected override string GetPropertyDeclaration(PropertyDefinition property) { var propVisib = GetPropertyVisibility(property, out var getVisible, out var setVisible); var buf = new StringBuilder(); buf.Append(propVisib); // Pick an accessor to use for static/virtual/override/etc. checks. var method = property.SetMethod ?? property.GetMethod; string modifiers = String.Empty; if (method.IsStatic) { modifiers += " static"; } if (method.IsVirtual && !method.IsAbstract) { if (((method.Attributes & MethodAttributes.SpecialName) != 0)) { modifiers += " virtual"; } else { modifiers += " override"; } } TypeDefinition declDef = (TypeDefinition)method.DeclaringType; if (method.IsAbstract && !declDef.IsInterface) { modifiers += " abstract"; } if (method.IsFinal) { modifiers += " sealed"; } if (modifiers == " virtual sealed") { modifiers = ""; } buf.Append(modifiers).Append(' ').Append("property "); var typeName = GetTypeNameWithOptions(property.PropertyType, AppendHatOnReturn); buf.Append(typeName).Append(' '); IEnumerable <MemberReference> defs = property.DeclaringType.GetDefaultMembers(); string propertyName = property.Name; foreach (MemberReference mi in defs) { if (mi == property) { propertyName = "default"; break; } } buf.Append(propertyName == "default" ? propertyName : DocUtils.GetPropertyName(property, NestedTypeSeparator)); bool hasParams = false; if (property.Parameters.Count != 0) { hasParams = true; buf.Append('['); buf.Append(GetTypeNameWithOptions(property.Parameters[0].ParameterType, AppendHatOnReturn)); for (int i = 1; i < property.Parameters.Count; ++i) { buf.Append(", "); buf.Append(GetTypeNameWithOptions(property.Parameters[i].ParameterType, AppendHatOnReturn)); } buf.Append(']'); } buf.Append(" { "); if (getVisible != null) { if (getVisible != propVisib) { buf.Append(' ').Append(getVisible); } buf.AppendFormat("{0} get", typeName); if (hasParams) { AppendParameters(buf, property.Parameters, '(', ')'); } else { buf.Append("()"); } buf.Append(";"); } if (setVisible != null) { if (setVisible != propVisib) { buf.Append(' ').Append(setVisible); } buf.Append(' ').AppendFormat("void set("); if (hasParams) {//no need for braces since they are added in other place AppendParameters(buf, property.Parameters, null, null); buf.Append(", "); } buf.AppendFormat("{0} value)", typeName); buf.Append(";"); } buf.Append(" };"); return(buf[0] != ' ' ? buf.ToString() : buf.ToString(1, buf.Length - 1)); }
/// <summary> /// Sets the data context for the specified element. /// </summary> /// <param name="element">The element.</param> /// <param name="pd">The property definition.</param> /// <param name="item">The item.</param> private void SetElementDataContext(FrameworkElement element, PropertyDefinition pd, object item) { element.DataContext = pd.Descriptor != null ? item : this.ItemsSource; }
public static bool HasFlag(this PropertyDefinition propertyDefinition, PropertyAttributes attribute) => (propertyDefinition.Attributes & attribute) == attribute;