public static object ChangeToCompatibleType(object value, Type destinationType) { Enforce.ArgumentNotNull(destinationType, "destinationType"); if (value == null) { if (destinationType.IsValueType) { return(Activator.CreateInstance(destinationType)); } return(null); } if (destinationType.IsAssignableFrom(value.GetType())) { return(value); } return(TypeDescriptor.GetConverter(destinationType).ConvertFrom(value)); }
public static Type FindGreatestCommonType(Type type, Type commonType) { Enforce.ArgumentNotNull <Type>(type, "type"); Enforce.ArgumentNotNull <Type>(commonType, "commonType"); if (type == typeof(object) || commonType == typeof(object)) { return(typeof(object)); } if (type == commonType || commonType.IsAssignableFrom(type)) { return(commonType); } else if (type.IsAssignableFrom(commonType)) { return(type); } else { Type candidate = FindGreatestCommonTypeInHierarchyUpwards(type, commonType); if (candidate != typeof(object) && candidate.IsAssignableFrom(commonType)) { return(candidate); } else { Type[] commonTypeInterfaces = commonType.GetInterfaces(); foreach (Type typeInterface in commonTypeInterfaces) { if (typeInterface.IsAssignableFrom(type)) { candidate = typeInterface; } } return(candidate); } } }
public ExtensionXmlSchema(XmlSchema schema) : this() { _schema = Enforce.ArgumentNotNull <XmlSchema>(schema, "schema"); }
protected ConstantParameter(object value, Predicate <ParameterInfo> predicate) { _value = value; _predicate = Enforce.ArgumentNotNull(predicate, "predicate"); }
public NamedParameter(string name, object value) : base(value, delegate(ParameterInfo pi) { return(pi.Name == name); }) { _name = Enforce.ArgumentNotNullOrEmpty(name, "name"); }
public static T TypedAs <T>(ICollection <IParameter> parameters) { Enforce.ArgumentNotNull(parameters, "parameters"); return(ConstantValue <TypedParameter, T>(parameters, delegate(TypedParameter c) { return c.Type == typeof(T); })); }
public ServiceAttribute(string nm, Type serviceInterface) { _name = nm; _serviceInterface = Enforce.ArgumentNotNull <Type>(serviceInterface, "serviceInterface"); }
public ObjectMapper(object instance) { _instance = Enforce.ArgumentNotNull(instance, "instance"); _instanceType = _instance.GetType(); }
public TypedParameter(Type type, object value) : base(value, delegate(ParameterInfo pi){ return(pi.ParameterType == type); }) { _type = Enforce.ArgumentNotNull(type, "type"); }
public NamedPropertyParameter(string name, object value) : base(value, delegate(ParameterInfo parameterInfo) { return(parameterInfo.Member.Name.Replace("set_", "") == name); }) { _name = Enforce.ArgumentNotNullOrEmpty(name, "name"); }
public MicroKernel(IServiceProvider parent) : this() { _parent = Enforce.ArgumentNotNull(parent, "parent"); _getMethodInfo = _parent.GetType().GetMethod("GetService", new Type[] { typeof(string) }); }
public ServiceKey(Type key) { typeKey = Enforce.ArgumentNotNull(key, "key"); }
public ServiceKey(string key) { stringKey = Enforce.ArgumentNotNullOrEmpty(key, "key"); }