public ChoAutoNotifyPropertyChangedObject(T instance) { ChoGuard.ArgumentNotNull(instance, "Instance"); _instance = instance; _type = instance.GetType(); if (_instance is INotifyPropertyChanged) { ((INotifyPropertyChanged)_instance).PropertyChanged += ((sender, e) => { PropertyChangedEventHandler propertyChanged = PropertyChanged; if (propertyChanged != null) { propertyChanged(this, e); } }); } }
public static object ConvertFrom(object target, object value, MemberInfo memberInfo, CultureInfo culture) { ChoGuard.ArgumentNotNull(target, "Target"); ChoGuard.ArgumentNotNull(memberInfo, "MemberInfo"); Type objType = null; if (target is Type) { objType = target as Type; target = null; } else { objType = target.GetType(); } return(ChoConvert.ConvertFrom(target, value, ChoType.GetMemberType(memberInfo), ChoTypeDescriptor.GetTypeConverters(memberInfo), ChoTypeDescriptor.GetTypeConverterParams(memberInfo), culture)); }
public ChoLoggableObject GetMe(Type type) { ChoGuard.ArgumentNotNull(type, "Type"); if (_singletonElement == null) { lock (SyncRoot) { if (_singletonElement == null) { _singletonElement = new ChoSingletonLoggableObject(); _singletonElement.LogDirectory = LogDirectory; _singletonElement.LogFileName = LogFileName.IsNullOrEmpty() ? ChoPath.AddExtension(type.FullName, ChoReservedFileExt.Log) : LogFileName; _singletonElement.LogCondition = LogCondition; _singletonElement.LogTimeStampFormat = LogTimeStampFormat; } } } return(_singletonElement); }
public static void RegisterConverters(MemberInfo memberInfo, TypeConverter[] typeConverters) { ChoGuard.ArgumentNotNull(memberInfo, "MemberInfo"); lock (_typeMemberTypeConverterCacheLockObject) { if (typeConverters == null) { typeConverters = EmptyTypeConverters; } if (_typeMemberTypeConverterCache.ContainsKey(memberInfo)) { _typeMemberTypeConverterCache[memberInfo] = typeConverters; } else { _typeMemberTypeConverterCache.Add(memberInfo, typeConverters); } } }
public static void RegisterConverters(Type type, TypeConverter[] typeConverters) { ChoGuard.ArgumentNotNull(type, "Type"); lock (_typeMemberTypeConverterCacheLockObject) { if (typeConverters == null) { typeConverters = EmptyTypeConverters; } if (_typeTypeConverterCache.ContainsKey(type)) { _typeTypeConverterCache[type] = typeConverters; } else { _typeTypeConverterCache.Add(type, typeConverters); } } }
public static void Run(ChoApplicationHost host, string[] args) { ChoGuard.ArgumentNotNull(host, "Host"); if (_applicationHost != null) { return; } lock (_hostLock) { if (_applicationHost == null) { _applicationHost = host; _applicationHost.Args = args; ChoApplicationHost.IsApplicationHostUsed = true; ChoFramework.Initialize(); ChoService.Initialize(); } } }
public static IChoSurrogateValidator GetValidator(MemberInfo memberInfo) { ChoGuard.ArgumentNotNull(memberInfo, "memberInfo"); if (!ChoType.IsValidObjectMember(memberInfo)) { return(null); } //If the cache doesn't have, build it if (!_objectMemberValidatorCache.ContainsKey(memberInfo)) { lock (_objectMemberValidatorCache.SyncRoot) { if (!_objectMemberValidatorCache.ContainsKey(memberInfo)) { Build(memberInfo); } } } return(_objectMemberValidatorCache[memberInfo]); }
public static void SetEnvironmentChangedEventHandlerNoCall(object key, EventHandler eventHandler) { ChoGuard.ArgumentNotNull(key, "key"); ChoGuard.ArgumentNotNull(eventHandler, "eventHandler"); OrderedDictionary eventHandlerList = _eventHandlerList; if (eventHandlerList != null) { lock (_eventHandlerListLock) { if (eventHandlerList.Contains(key)) { eventHandlerList[key] = eventHandler; } else { eventHandlerList.Add(key, eventHandler); } } } }
internal static T CreateInstance <T>(Type objType, ChoObjectConstructionType defaultObjectConstructionType, bool beforeFieldInit, out Exception exception) { exception = null; ChoGuard.ArgumentNotNull(objType, "objType"); T instance = default(T); ChoObjectConstructionType objectConstructionType = defaultObjectConstructionType; if (IsConstructing(objType)) { instance = New <T>(objType, null); if (instance != null) { ChoObjectInitializer.Initialize(instance, beforeFieldInit); } } else { try { _globalObjectBuildStateCache[objType] = ObjectBuildState.Constructing; IChoCustomObjectFactory customObjectFactory = null; ChoObjectFactoryAttribute objectFactoryAttribute = ChoType.GetAttribute(objType, typeof(ChoObjectFactoryAttribute)) as ChoObjectFactoryAttribute; if (objectFactoryAttribute != null) { objectConstructionType = objectFactoryAttribute.ObjectConstructionType; customObjectFactory = objectFactoryAttribute.CustomObjectFactory; } switch (objectConstructionType) { case ChoObjectConstructionType.Singleton: //lock (_globalObjectCache.SyncRoot) //{ if (_globalObjectCache.ContainsKey(objType)) { return((T)_globalObjectCache[objType]); } else { instance = New <T>(objType, customObjectFactory); _globalObjectCache[objType] = instance; } //} break; default: instance = New <T>(objType, customObjectFactory); break; } if (instance != null) { try { ChoObjectInitializer.Initialize(instance, beforeFieldInit); } catch (TypeInitializationException) { throw; } catch (ChoFatalApplicationException) { throw; } catch (Exception ex) { exception = ex; } } } finally { _globalObjectBuildStateCache[objType] = ObjectBuildState.Constructed; } } return(instance); }
public static object ConvertTo(object value, MemberInfo memberInfo, Type targetType, object sourceObject = null, CultureInfo culture = null) { ChoGuard.ArgumentNotNull((object)memberInfo, "MemberInfo"); return(ChoConvert.ConvertTo(value, targetType, sourceObject, ChoTypeDescriptor.GetTypeConverters(memberInfo), ChoTypeDescriptor.GetTypeConverterParams(memberInfo), culture)); }
public void Add(Type formatType, ICustomFormatter formatter) { ChoGuard.ArgumentNotNull(formatType, "FormatType"); _formatProviders.SetValue(formatType, formatter); }
public ChoBaseWaitFor(Delegate func) { ChoGuard.ArgumentNotNull(func, "Function"); FuncSignature = ChoDelegateEx.ToString(func); }
public static T GetMe <T>(Type type) where T : Attribute { ChoGuard.ArgumentNotNull(type, "Type"); return(ChoType.GetAttribute <T>(type)); }
public ChoTypeShortNameAttribute(Type type) { ChoGuard.ArgumentNotNull(type, "Type"); _name = type.Name; }
public ChoConfigurationValidatorBaseSurrogateValidator(ConfigurationValidatorBase validator) { ChoGuard.ArgumentNotNull(validator, "Validator"); _validator = validator; }
public static string ExpandProperties(object target, string inString, IChoPropertyReplacer propertyReplacer) { ChoGuard.ArgumentNotNull(propertyReplacer, "Property Replacer"); return(ExpandProperties(target, inString, new IChoPropertyReplacer[] { propertyReplacer })); }
public static string ExpandProperties(object target, string inString, char startSeperator, char endSeperator, char formatSeperator, IChoPropertyReplacer[] propertyReplacers) { if (inString.IsNullOrEmpty()) { return(inString); } ChoGuard.ArgumentNotNull(propertyReplacers, "Property Replacers"); string msg = inString; if (inString.IndexOf(startSeperator) != -1) { int index = -1; bool hasChoChar = false; StringBuilder message = new StringBuilder(); StringBuilder token = new StringBuilder(); while (++index < inString.Length) { if (!hasChoChar && inString[index] == startSeperator && index + 1 < inString.Length && inString[index + 1] == startSeperator) { hasChoChar = true; } else if (inString[index] == startSeperator) { if (hasChoChar) { bool hadEndChoChar = false; do { if (inString[index] == endSeperator && inString[index - 1] == endSeperator) { if (!hadEndChoChar) { hadEndChoChar = true; } else { message.Append(inString[index]); } continue; } message.Append(inString[index]); }while (++index < inString.Length && inString[index] != startSeperator); index--; hasChoChar = false; } else { token.Remove(0, token.Length); index++; do { if (!hasChoChar && inString[index] == endSeperator && index + 1 < inString.Length && inString[index + 1] == endSeperator) { hasChoChar = true; } else if (inString[index] == endSeperator) { if (hasChoChar) { message.Append(startSeperator); message.Append(token); message.Append(inString[index]); bool hadEndChoChar = false; do { if (inString[index] == endSeperator && inString[index - 1] == endSeperator) { if (!hadEndChoChar) { hadEndChoChar = true; } else { message.Append(inString[index]); } continue; } message.Append(inString[index]); }while (++index < inString.Length && inString[index] == endSeperator); } else { if (token.Length > 0) { string[] propertyNameNFormat = token.ToString().SplitNTrim(formatSeperator); if (!(propertyNameNFormat.Length >= 1 && ReplaceToken(propertyReplacers, message, propertyNameNFormat[0], propertyNameNFormat.Length == 2 ? propertyNameNFormat[1] : null))) { message.AppendFormat("{0}{1}{2}", startSeperator, token, endSeperator); } } } break; } else { token.Append(inString[index]); } }while (++index < inString.Length); } } else { message.Append(inString[index]); } } msg = message.ToString(); } foreach (IChoPropertyReplacer propertyReplacer in propertyReplacers) { if (!(propertyReplacer is IChoCustomPropertyReplacer)) { continue; } IChoCustomPropertyReplacer customPropertyReplacer = propertyReplacer as IChoCustomPropertyReplacer; string formattedMsg = msg; bool retVal = customPropertyReplacer.Format(target, ref formattedMsg); if (!String.IsNullOrEmpty(formattedMsg)) { msg = formattedMsg; } if (!retVal) { break; } } return(msg); }
public ChoSurrogateValidator(ChoValidator validator) { ChoGuard.ArgumentNotNull(validator, "Validator"); _validator = validator; }
internal static Dictionary <string, object> ToPersistableDictionaryCollection(ChoBaseConfigurationElement configElement, Type itemType) { ChoGuard.ArgumentNotNull(configElement, "ConfigElement"); object target = configElement.ConfigObject; ChoGuard.ArgumentNotNull(target, "Target"); Dictionary <string, object> dict = new Dictionary <string, object>(); //Dictionary<string, MemberInfo> configMemberInfos = ChoType.GetMembersDictionary(target.GetType(), typeof(ChoConfigurationPropertyAttribute)); //MemberInfo[] memberInfos = ChoType.GetMembers(target.GetType(), typeof(ChoConfigurationPropertyAttribute)); MemberInfo[] memberInfos = ChoTypeMembersCache.GetAllMemberInfos(target.GetType()); if (memberInfos == null || memberInfos.Length == 0) { return(dict); } ChoPropertyInfoAttribute memberInfoAttribute = null; string name = null; foreach (MemberInfo memberInfo in memberInfos) { if (memberInfo.GetCustomAttribute <ChoIgnorePropertyAttribute>() != null) { continue; } object memberValue = ChoType.GetMemberValue(target, memberInfo.Name); memberInfoAttribute = (ChoPropertyInfoAttribute)ChoType.GetMemberAttribute(memberInfo, typeof(ChoPropertyInfoAttribute)); name = ChoType.GetMemberName(memberInfo, memberInfoAttribute); if (target is ChoConfigurableObject && ((ChoConfigurableObject)target).RaiseBeforeConfigurationObjectMemberPersist(memberInfo.Name, name, ref memberValue)) { dict.Add(name, memberValue); } else { if (memberInfoAttribute != null && !memberInfoAttribute.Persistable) { continue; } memberValue = ChoType.GetMemberValue(target, memberInfo.Name); Type memberType = ChoConfigurationMetaDataManager.GetSourceType(configElement, name, memberInfoAttribute); if (memberType == null) { if (itemType == typeof(Object)) { memberType = ChoType.GetMemberType(memberInfo); } else { memberType = itemType; } } dict.Add(name, ChoConvert.ConvertTo(target, memberValue, memberType, ChoTypeDescriptor.GetTypeConverters(memberInfo), ChoTypeDescriptor.GetTypeConverterParams(memberInfo), null)); } } return(dict); }
public ChoAppDomainUnloadMethodAttribute(string description) { ChoGuard.ArgumentNotNull(description, "Description"); _description = description; }
public static void UnregisterMe(object target) { ChoGuard.ArgumentNotNull(target, "Target"); UnregisterMe(target.GetType()); }
public void Remove(Type formatType) { ChoGuard.ArgumentNotNull(formatType, "FormatType"); _formatProviders.RemoveValue(formatType); }
internal static bool IsDisposed(IChoDisposable obj) { ChoGuard.ArgumentNotNull(obj, "obj"); return(obj.IsDisposed); }
public ChoAnonymousDisposable(Action dispose) { ChoGuard.ArgumentNotNull(dispose, "Dispose"); this._dispose = dispose; }
public static T GetMe <T>(object target) where T : Attribute { ChoGuard.ArgumentNotNull(target, "Target"); return(GetMe <T>(target.GetType())); }
public ChoObjectNameableAttribute(Type type) { ChoGuard.ArgumentNotNull(type, "Type"); Name = type.Name; }
public ChoConfigurationValidatorAttributeSurrogateValidator(ConfigurationValidatorAttribute validationAttribute) { ChoGuard.ArgumentNotNull(validationAttribute, "ValidationAttribute"); _configurationValidatorBase = validationAttribute.ValidatorInstance; }
public ChoPostValidatorFactoryAttribute(Type externValidationManagerType) { ChoGuard.ArgumentNotNull(externValidationManagerType, "externValidationManagerType"); _externValidationManagerType = externValidationManagerType; }
public bool Remove(IChoPropertyReplacer propertyReplacer) { ChoGuard.ArgumentNotNull(propertyReplacer, "PropertyReplacer"); return(Remove(propertyReplacer.GetType().Name)); }
public ChoValidationAttributeSurrogateValidator(ValidationAttribute validationAttribute) { ChoGuard.ArgumentNotNull(validationAttribute, "ValidationAttribute"); _validationAttribute = validationAttribute; }