static ClientInfoGrid() { DicValidation.Add(new KeyValuePair <string, Func <object, string> >(StaticReflection.GetMemberName <ClientInfoGrid>(x => x.ClientInfo.FirstName), value => GenericValidator.ValidateEmptyAndLength(value, 2, 100))); DicValidation.Add(new KeyValuePair <string, Func <object, string> >(StaticReflection.GetMemberName <ClientInfoGrid>(x => x.ClientInfo.LastName), value => GenericValidator.ValidateEmptyAndLength(value, 2, 200))); DicValidation.Add(new KeyValuePair <string, Func <object, string> >(StaticReflection.GetMemberName <ClientInfoGrid>(x => x.ClientInfo.LoyaltyCode), value => GenericValidator.ValidateLength(value, 5, 14))); }
public static IMember GetMember <TTarget>(this TTarget target, Expression <Action <TTarget> > action) { return(StaticReflection.GetMember(action)); }
public static IMember GetMember <TTarget, TResult>(this TTarget target, Expression <Func <TResult> > func) { return(StaticReflection.GetMember(func)); }
protected override void ExecuteInternal(IJobExecutionContext context) { if (string.IsNullOrEmpty(Flow)) { string msg = string.Format("Required job arg {0} is not specified, check job config", StaticReflection.GetMemberName(() => Flow)); Tracer.Fatal(msg); throw new InvalidOperationException(msg); } using (Probe.Create(Flow)) { ProcessFlow(); } }
public static bool IsSet <T>(this T shortcode, Expression <Func <T, object> > expression) where T : IShortcode { var memberName = StaticReflection.GetMemberName(expression); return(shortcode.Attributes.ContainsKey(memberName)); }
public bool TrySerialize(Type objectToSerializeType, object objectToSerialize, IXmlSerializer xmlSerializer, out XElement serializedObject) { if (objectToSerializeType == null) { throw new ArgumentNullException("objectToSerializeType"); } if (xmlSerializer == null) { throw new ArgumentNullException("xmlSerializer"); } serializedObject = null; bool isArray = objectToSerializeType.IsArray; if (!objectToSerializeType.IsGenericType && !isArray) { return(false); } if (isArray) { objectToSerializeType = objectToSerializeType.GetInterfaces() .FirstOrDefault(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(ICollection <>)); if (objectToSerializeType == null) { return(false); } } Type genericType = objectToSerializeType.GetGenericTypeDefinition(); MethodInfo methodInfo; if (genericType == typeof(List <>) || genericType == typeof(ICollection <>)) { methodInfo = StaticReflection.GetGenericMethodInfo(o => SerializeCollection <object>(null, null)); } else if (genericType == typeof(Dictionary <,>)) { methodInfo = StaticReflection.GetGenericMethodInfo(o => SerializeDictionary <object, object>(null, null)); } else if (genericType == typeof(KeyValuePair <,>)) { methodInfo = StaticReflection.GetGenericMethodInfo(o => SerializeKeyValuePair(new KeyValuePair <object, object>(), null)); } else { return(false); } methodInfo = methodInfo.MakeGenericMethod(objectToSerializeType.GetGenericArguments()); XElement result = methodInfo.Invoke(null, new object[] { objectToSerialize, xmlSerializer }) as XElement; string serializedType = TypeManager.SerializeType(objectToSerializeType); result.Add(new XAttribute("type", serializedType)); serializedObject = result; return(true); }
static void DeriveNinjectConstructorArgumentFromPublic() { ConstructorArgument newArg = StaticReflection <X> .CreateConstructorArgument(new X2()); Assert.Equal("param2", newArg.Name); }
public static string MemberName <T>( this Expression <Func <T> > expression) { return(StaticReflection.GetMemberName(expression)); }
public static MemberInfo MemberInfo <T>( this T instance, Expression <Action <T> > expression) { return(StaticReflection.GetMemberInfo(instance, expression)); }
public void WhenConfiguredContainer_ThenCanResolvePolicy() { using (var container = new UnityContainer()) { this.policyData.ConfigureContainer(container); var policy = container.Resolve <RuleDrivenPolicy>("policy"); var method = new MethodImplementationInfo(StaticReflection.GetMethodInfo <object>(o => o.ToString()), StaticReflection.GetMethodInfo <object>(o => o.ToString())); Assert.AreEqual("policy", policy.Name); Assert.IsTrue(policy.Matches(method)); Assert.AreEqual(0, policy.GetHandlersFor(method, container).Count()); Assert.AreNotSame(policy, container.Resolve <RuleDrivenPolicy>("policy")); Assert.IsTrue(container.Registrations.Any(r => r.Name == "type-policy" && r.RegisteredType == typeof(IMatchingRule) && r.MappedToType == typeof(TypeMatchingRule))); } }
public static string MemberName <T>( this T instance, Expression <Action <T> > expression) { return(StaticReflection.GetMemberName(instance, expression)); }
public void WhenConfiguredContainer_ThenCanResolvePolicy() { using (var container = new UnityContainer()) { this.policyData.ConfigureContainer(container); var policy = container.Resolve <RuleDrivenPolicy>("policy"); var method = new MethodImplementationInfo(StaticReflection.GetMethodInfo <object>(o => o.ToString()), StaticReflection.GetMethodInfo <object>(o => o.ToString())); Assert.AreEqual("policy", policy.Name); Assert.IsFalse(policy.Matches(method)); Assert.AreEqual(0, policy.GetHandlersFor(method, container).Count()); } }
public void GetMemberStringLength() { var Length = StaticReflection.GetMemberName <string>(x => x.Length); Assert.AreEqual(nameof(Length), Length); }
public string GetPageSizeUrl(string pageSize) { var pageSizeProp = StaticReflection.GetMember <TableRequestModel, int>((t) => t.PageSize); return(BaseUrl + GetSeperator() + CloneValues(pageSizeProp.Name, pageSize, _urlParams).ToQueryString()); }
static AttributeBasedRoutedDataUrlMapper() { _getFilteredDataMethodInfo = StaticReflection.GetGenericMethodInfo(() => GetFilteredData <IData>(null)); _getFilteredDataQueryableMethodInfo = StaticReflection.GetGenericMethodInfo(a => GetFilteredDataQueryable <IPageRelatedData>(Guid.Empty)); }
public static MemberInfo MemberInfo <T>( this Expression <Func <T> > expression) { return(StaticReflection.GetMemberInfo(expression)); }
static AttributeBasedRoutedDataUrlMapper() { _getFilteredDataMethodInfo = StaticReflection.GetGenericMethodInfo(() => GetFilteredData <IData>(null)); }
public static MemberInfo MemberInfo(this Expression expression) { return(StaticReflection.GetMemberInfo(expression)); }
public bool TryDeserialize(XElement serializedObject, IXmlSerializer xmlSerializer, out object deserializedObject) { if (serializedObject == null) { throw new ArgumentNullException("serializedObject"); } if (xmlSerializer == null) { throw new ArgumentNullException("xmlSerializer"); } deserializedObject = null; XAttribute typeAttribute = serializedObject.Attribute("type"); if (typeAttribute == null) { return(false); } Type type = TypeManager.GetType(typeAttribute.Value); if (type.IsGenericType == false) { return(false); } Type genericType = type.GetGenericTypeDefinition(); MethodInfo methodInfo; if (genericType == typeof(List <>)) { methodInfo = StaticReflection.GetGenericMethodInfo(o => DeserializeList <object>(null, null)); } else if (genericType == typeof(Dictionary <,>)) { methodInfo = StaticReflection.GetGenericMethodInfo(o => DeserializeDictionary <object, object>(null, null)); } else if (genericType == typeof(KeyValuePair <,>)) { methodInfo = StaticReflection.GetGenericMethodInfo(o => DeserializeKeyValuePair <object, object>(null, null)); } else { return(false); } methodInfo = methodInfo.MakeGenericMethod(type.GetGenericArguments()); try { object result = methodInfo.Invoke(null, new object[] { serializedObject, xmlSerializer }); if (result != null) { deserializedObject = result; return(true); } return(false); } catch (TargetInvocationException exception) { if (exception.InnerException is DataSerilizationException) { throw exception.InnerException; } return(false); } catch (Exception) { return(false); } }
static VersionedRepository() { VersionPropertyName = StaticReflection.GetMemberInfo <IVersioned, byte[]>(v => v.EntityVersion).Name; }