本文整理汇总了C#中INotifyPropertyChanged.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# INotifyPropertyChanged.GetType方法的具体用法?C# INotifyPropertyChanged.GetType怎么用?C# INotifyPropertyChanged.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类INotifyPropertyChanged
的用法示例。
在下文中一共展示了INotifyPropertyChanged.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ObjectObserver
/// <summary>
/// Initializes a new instance of the <see cref="ObjectObserver"/> class.
/// </summary>
/// <param name="propertyChanged">The property changed.</param>
/// <param name="tag">The tag.</param>
/// <param name="mementoService">The memento service. If <c>null</c>, the service will be retrieved from the <see cref="IServiceLocator"/>.</param>
/// <exception cref="ArgumentNullException">The <paramref name="propertyChanged"/> is <c>null</c>.</exception>
public ObjectObserver(INotifyPropertyChanged propertyChanged, object tag = null, IMementoService mementoService = null)
: base(tag, mementoService)
{
Argument.IsNotNull("propertyChanged", propertyChanged);
Log.Debug("Initializing ObjectObserver for type '{0}'", propertyChanged.GetType().Name);
_weakEventListener = this.SubscribeToWeakPropertyChangedEvent(propertyChanged, OnPropertyChanged);
InitializeDefaultValues(propertyChanged);
Log.Debug("Initialized ObjectObserver for type '{0}'", propertyChanged.GetType().Name);
}
示例2: BindViewModel
public void BindViewModel(INotifyPropertyChanged viewModel, BrowserBridge browser)
{
ViewModelDefinition definition = GetViewModelDefinition(viewModel.GetType());
if (definition == null)
{
definition = new ViewModelDefinition(viewModel.GetType(), viewModel.GetType().Name);
StringBuilder sb = new StringBuilder();
List<ViewModelDefinition> allDefs = new List<ViewModelDefinition>();
definition.CollectViewModelDefinitions(allDefs);
foreach (ViewModelDefinition child in allDefs)
child.DefineInBrowser(sb);
InjectFramework(sb);
browser.InsertScript(sb.ToString());
}
}
示例3: NotifyPropertyChangedRecordedElement
internal NotifyPropertyChangedRecordedElement(IUndoRedoService undoRedoService, INotifyPropertyChanged objAsNotifyPropertyChanged)
: base(objAsNotifyPropertyChanged)
{
if (undoRedoService == null) { throw new ArgumentNullException("undoRedoService"); }
if (objAsNotifyPropertyChanged == null) { throw new ArgumentNullException("objAsNotifyPropertyChanged"); }
_objAsNotifyPropertyChanged = objAsNotifyPropertyChanged;
_objAsNotifyPropertyChanged.PropertyChanged += OnPropertyChanged;
foreach (var propertyInfo in objAsNotifyPropertyChanged.GetType().GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))
{
var getMethod = propertyInfo.GetGetMethod();
if (getMethod != null && getMethod.GetParameters().Any())
{
continue;
}
var attributes = propertyInfo.GetCustomAttributes(typeof(IsRecordableAttribute), true);
if (attributes.Length <= 0)
{
continue;
}
var property = PropertyFactory.Create(undoRedoService, objAsNotifyPropertyChanged, (IsRecordableAttribute)attributes[0], propertyInfo);
_properties.Add(property.Name, property);
}
}
示例4: NotifyPropertyChangedSnapshot
public NotifyPropertyChangedSnapshot(DirtyModelDetector modelDetector, INotifyPropertyChanged snapshotValue)
: base(modelDetector, snapshotValue)
{
if (snapshotValue == null)
{
throw new ArgumentNullException("snapshotValue");
}
foreach (var propertyInfo in snapshotValue.GetType().GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))
{
var getMethod = propertyInfo.GetGetMethod();
if (getMethod != null && getMethod.GetParameters().Any())
{
continue;
}
var attributes = propertyInfo.GetCustomAttributes(typeof(IsSerialized), true);
if (attributes.Length <= 0)
{
continue;
}
var snapshot = SnaphotFactory.Create(modelDetector, propertyInfo.GetValue(snapshotValue, null));
var keyValuePair = new KeyValuePair<PropertyInfo, SnapshotElement>(propertyInfo, snapshot);
_propertiesSnapshots.Add(propertyInfo.Name, keyValuePair);
}
_listenedNotifyPropertyChanged = snapshotValue;
_listenedNotifyPropertyChanged.PropertyChanged += OnPropertyChanged;
}
示例5: ValidationTemplate
public ValidationTemplate(INotifyPropertyChanged target)
{
this.target = target;
validator = GetValidator(target.GetType());
validationResult = validator.Validate(target);
target.PropertyChanged += Validate;
}
示例6: MenuItemViewModel
public MenuItemViewModel(string nameKey, INotifyPropertyChanged nameSource, ICommand command, INotifyPropertyChanged commandParameterSource, string commandParameterName)
: this("name", new ObservableCollection<IMenuItemViewModel>())
{
m_nameKey = nameKey;
m_nameSource = nameSource;
m_command = command;
m_commandParameterSource = commandParameterSource;
m_commandParameterName = commandParameterName;
if (m_commandParameterSource != null && m_commandParameterName != null)
{
m_commandPropertyInfo = m_commandParameterSource.GetType().GetProperty(m_commandParameterName);
if (m_commandPropertyInfo != null)
{
m_commandParameter = m_commandPropertyInfo.GetValue(m_commandParameterSource);
m_commandParameterSource.PropertyChanged += CommandParameterSourceOnPropertyChanged;
}
}
if (nameSource != null && nameKey != null)
{
m_namePropertyInfo = nameSource.GetType().GetProperty(nameKey);
if (m_namePropertyInfo != null)
{
m_name = m_namePropertyInfo.GetValue(nameSource) as string;
nameSource.PropertyChanged += NameSourceOnPropertyChanged;
}
}
}
示例7: ClearPropertyBinding
/// <summary>
/// Clears the property binding.
/// </summary>
/// <param name="source">The source.</param>
/// <param name="target">The target.</param>
/// <param name="sourceProp">The source prop.</param>
/// <param name="targetProp">The target prop.</param>
public static void ClearPropertyBinding(Object source, INotifyPropertyChanged target, string sourceProp, string targetProp)
{
WeakEntry entry = new WeakEntry(source.GetType(), target.GetType(), sourceProp, targetProp);
Delegate setAction = GetExpressionAction(entry, source, true);
WeakSource.UnRegister(source, setAction, targetProp);
}
示例8: PropertyChangedIsCalled
/// <summary>
/// Asserts that property changed is called for the specified property when the value of the property is set
/// to the specified value.
/// </summary>
/// <param name="observableObject">The object that will be observed.</param>
/// <param name="propertyName">The name of the property that will be observed.</param>
/// <param name="value">The value to which the property should be set.</param>
/// <param name="isRaised">Determines wether property changed should be called or not.</param>
private static void PropertyChangedIsCalled(
INotifyPropertyChanged observableObject,
string propertyName,
object value,
bool isRaised)
{
var propertyFound = false;
var propertyChangedCalled = false;
observableObject.PropertyChanged += (sender, args) =>
{
if (args.PropertyName == propertyName)
{
propertyChangedCalled = true;
}
};
var properties = observableObject.GetType().GetProperties();
foreach (var propertyInfo in properties)
{
if (propertyInfo.Name == propertyName)
{
propertyInfo.SetValue(observableObject, value, null);
propertyFound = true;
break;
}
}
Assert.IsTrue(
propertyFound,
string.Format("The property {0} could not be found on object {1}.", propertyName, observableObject));
Assert.AreEqual(isRaised, propertyChangedCalled);
}
示例9: LocateDialogType
/// <summary>
/// Locates the dialog type representing the specified view model in a user interface.
/// </summary>
/// <param name="viewModel">The view model to find the dialog type for.</param>
/// <returns>
/// The dialog type representing the specified view model in a user interface.
/// </returns>
internal static Type LocateDialogType(INotifyPropertyChanged viewModel)
{
if (viewModel == null)
throw new ArgumentNullException("viewModel");
Type viewModelType = viewModel.GetType();
Type dialogType = Cache.Get(viewModelType);
if (dialogType != null)
{
return dialogType;
}
string dialogName = GetDialogName(viewModelType);
string dialogAssemblyName = GetAssemblyFullName(viewModelType);
string dialogFullName = "{0}, {1}".InvariantFormat(
dialogName,
dialogAssemblyName);
dialogType = Type.GetType(dialogFullName);
if (dialogType == null)
throw new Exception(Resources.DialogTypeMissing.CurrentFormat(dialogFullName));
Cache.Add(viewModelType, dialogType);
return dialogType;
}
示例10: PropertyBoundCommand
public PropertyBoundCommand(CommandExecute execute, INotifyPropertyChanged boundTo, string propertyName)
{
if (execute == null)
throw new ArgumentNullException("execute");
this.execute = execute;
if (boundTo == null)
throw new ArgumentNullException("boundTo");
this.boundTo = boundTo;
property = boundTo.GetType().GetProperty(propertyName);
if (property == null)
throw new ArgumentException("Bad propertyName");
if (property.PropertyType != typeof(bool))
throw new ArgumentException("Bad property type");
propertyGetMethod = property.GetGetMethod();
if (propertyGetMethod == null)
throw new ArgumentException("No public get-method found.");
this.propertyName = propertyName;
boundTo.PropertyChanged += new PropertyChangedEventHandler(boundTo_PropertyChanged);
}
示例11: ChangeTracker
public ChangeTracker(INotifyPropertyChanged source, PropertiesSettings settings)
{
Ensure.NotNull(source, nameof(source));
Ensure.NotNull(settings, nameof(settings));
Track.Verify.CanTrackType(source.GetType(), settings);
this.Settings = settings;
this.node = ChangeTrackerNode.GetOrCreate(source, settings, true);
this.node.Value.Changed += this.OnNodeChange;
}
示例12: POCOBinding
public POCOBinding(INotifyPropertyChanged source, string sourcePropertyName, INotifyPropertyChanged target, string targetPropertyName)
{
_source = source;
_sourceProperty = source.GetType().GetProperty(sourcePropertyName);
_target = target;
_targetProperty = target.GetType().GetProperty(targetPropertyName);
_source.PropertyChanged += SourcePropertyChanged;
_target.PropertyChanged += TargetPropertyChanged;
}
示例13: SetPropertyBinding
/// <summary>
/// Sets the property binding.
/// </summary>
/// <param name="source">The source.</param>
/// <param name="target">The target.</param>
/// <param name="sourceProp">The source prop.</param>
/// <param name="targetProp">The target prop.</param>
/// <param name="notify">if set to <c>true</c> update immediately.</param>
/// <param name="converter">The converter.</param>
/// <param name="parameter">The converter parameter.</param>
public static void SetPropertyBinding(Object source, INotifyPropertyChanged target, string sourceProp, string targetProp, bool notify = true, IDataConverter converter = null, object parameter = null)
{
WeakEntry entry = new WeakEntry(source.GetType(), target.GetType(), sourceProp, targetProp);
Delegate setAction = GetExpressionAction(entry, source, true, converter);
WeakSource wSource = WeakSource.Register(source, target, setAction, targetProp, converter, parameter);
if (notify)
{
wSource.NotifyPropertyChanged(target, targetProp);
}
}
示例14: NotifyPropertyChangedKVOHelper
NotifyPropertyChangedKVOHelper(INotifyPropertyChanged anObject)
{
TargetObject = anObject;
TargetObject.PropertyChanged += PropertyDidChange;
if (typeof(INotifyPropertyChanging).IsAssignableFrom(anObject.GetType())) {
targetSupportsPropertyChanging = true;
((INotifyPropertyChanging)anObject).PropertyChanging += PropertyWillChange;
}
}
示例15: GetHandlerField
private static void GetHandlerField(INotifyPropertyChanged changed, out CacheItem[] handlerFields)
{
handlerFields = null;
var type = changed.GetType();
Func<object, object> instanceGetter;
if (cached.ContainsKey(type)) {
handlerFields = cached[type];
}
else {
var result = new List<CacheItem>();
while (type != null) {
var handlerField = type.GetField("PropertyChanged", BindingFlags.Instance | BindingFlags.NonPublic);
if (handlerField != null) {
result.Add(new CacheItem(handlerField, x => x));
}
else {
var field = type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic).FirstOrDefault(f => f.FieldType.Name == "TrackableEntityAttribute");
if (field != null) {
var value = field.GetValue(changed);
if (value != null) {
handlerField = value.GetType().GetField("PropertyChanged", BindingFlags.Instance | BindingFlags.NonPublic);
if (handlerField != null)
{
result.Add(new CacheItem(handlerField, field, (x, ifield) => ifield.GetValue(x)));
}
}
}
}
type = type.BaseType;
}
Debug.Assert(result.Count() > 0);
handlerFields = result.ToArray();
lock (cacheLock) {
if (!cached.ContainsKey(changed.GetType()))
cached[changed.GetType()] = handlerFields;
}
}
}