public void InvokeNonPublicMethod() { var @class = new Class(typeof(ClassForMethodTest)); var method = @class.GetMethod("_GetFoo"); var test = new ClassForMethodTest("bar"); Assert.AreEqual("bar", method.Invoke(test)); }
public virtual void Write(Type uiItemType, string actionName, string identification, object[] parameters) { StringBuilder builder = new StringBuilder(CodeForGettingUIItem(uiItemType, identification)); builder.Append(".").Append(actionName); Class uiItemClass = new Class(uiItemType); if (uiItemClass.IsProperty(actionName)) { builder.Append(" = "); if (parameters[0] is bool) builder.Append((bool) parameters[0] ? "true" : "false"); else builder.Append("\"" + parameters[0] + "\""); } else { builder.Append("("); for (int i = 0; i < parameters.Length; i++) { builder.Append("\"").Append(parameters[i]).Append("\""); if (i != parameters.Length - 1) builder.Append(", "); } builder.Append(")"); } builder.Append(";"); code = builder.ToString(); }
public virtual void Populate(FieldMap fieldMap, Entity entity) { var fieldsWithNoValueOnEntity = new List<string>(); var @class = new Class(GetType()); @class.EachField(delegate(FieldInfo fieldInfo) { var uiItem = fieldInfo.GetValue(this) as UIItem; if (uiItem == null || !ControlDictionary.Instance.IsEditable(uiItem)) return; string fieldName = fieldMap.GetFieldNameFor(fieldInfo.Name, fieldInfo.FieldType); if (string.IsNullOrEmpty(fieldName)) return; try { EntityField entityField = entity.Field(fieldName); if (entityField == null) fieldsWithNoValueOnEntity.Add(fieldName); else entityField.SetValueOn(uiItem); } catch (TargetInvocationException e) { throw new AppScreenException( string.Format("Error assigning {0}.{1} to {2}.{3} ", entity.GetType(), fieldName, GetType(), fieldInfo.Name), e.InnerException); } }); if (fieldsWithNoValueOnEntity.Count == 0) return; string message = string.Join(",", fieldsWithNoValueOnEntity.ToArray()); WhiteLogger.Instance.WarnFormat("Mapping to screen: {0} with {1}, No value specified for fields {2}", this, entity.GetType(), message); }
public static ControlType ControlType(Type type) { var @class = new Class(type); if ([email protected](typeof (ControlTypeMappingAttribute))) throw new CustomUIItemException("ControlTypeMappingAttribute needs to be defined for this type: " + type.FullName); var controlTypeMappingAttribute = @class.Attribute<ControlTypeMappingAttribute>(); return ControlType(controlTypeMappingAttribute.CustomUIItemType); }
public void NewScreenContainingComponent() { var mocks = new MockRepository(); var window = mocks.StrictMock<Window>(); var screenRepository = mocks.StrictMock<ScreenRepository>(); mocks.ReplayAll(); var @class = new Class(typeof(ScreenClassContainingComponent)); new ScreenClass(@class).New(window, screenRepository); }
public void New_screen_containing_component() { MockRepository mocks = new MockRepository(); Window window = mocks.CreateMock<Window>(); ScreenRepository screenRepository = mocks.CreateMock<ScreenRepository>(); mocks.ReplayAll(); Class @class = new Class(typeof(ScreenClassContainingComponent)); new ScreenClass(@class).New(window, screenRepository); }
public virtual EntityField Field(string fieldName) { foreach (Entity entity in NestedEntities) { Class @class = new Class(entity.GetType()); FieldInfo field = @class.GetField(fieldName); if (null != field) return new EntityField(entity, field); } return null; }
public ReflectedObject(object o, LeafRegistry registry) { this.o = o; leafRegister = registry; if (o != null) { @class = new Class(o.GetType()); @class.IgnoreClass(ignoredType); fields = new Fields(this.o); } }
public virtual ApplicationClass ClassFor(object test) { var @class = new Class(test.GetType()); if (@class.HasAttribute(typeof (CategoryAttribute))) { List<CategoryAttribute> categoryAttributes = @class.Attributes<CategoryAttribute>(); if (ContainsName(categoryAttributes, DefaultAppClass)) return DefaultAppClass; string category = categoryAttributes[0].Name; if (categories.ContainsKey(category)) return categories[category]; } return applicationClass.Equals(ApplicationClass.None) ? DefaultAppClass : applicationClass; }
private void AllSubsclassesHaveEmptyConstructor(BricksCollection<Class> collection, Type type) { var @class = new Class(type); Classes classes = @class.SubClassesInAssembly(); foreach (Class subClass in classes) { bool hasDefaultConstructor = false; subClass.EachConstructor(delegate(ConstructorInfo constructorInfo) { if (constructorInfo.GetParameters().Length == 0 || subClass.Name.Equals(typeof(ToggleableItem).Name)) hasDefaultConstructor = true; }); if (!hasDefaultConstructor && subClass.ClassType.IsVisible && !subClass.Name.Equals("Desktop")) collection.Add(subClass); } Assert.AreEqual(0, collection.Count, collection.ToString()); }
public void EachField(Class.FieldDelegate operation) { @class.EachField(operation); }
public void NonVirtuals() { var @class = new Class(typeof(ClassForClassTest)); Assert.AreEqual(2, @class.NonVirtuals.Count); }
public void SubClasses() { var @class = new Class(typeof(ClassForClassTest)); Assert.AreEqual(1, @class.SubClassesInAssembly().Count); }
public void NewWhenObjectTypeIsSubtype() { var @class = new Class(typeof(ClassForClassTest)); @class.New(string.Empty); }
public void NewWhenTheParametersAreWrong() { var @class = new Class(typeof(ClassForClassTest)); @class.New(0, 0); }
public void SetUp() { forPropertyTest = new ForPropertyTest("bar"); @class = new Class(typeof(ForPropertyTest)); }
public void New() { var @class = new Class(typeof(ClassForClassTest)); Assert.AreNotEqual(null, @class.New()); }
public void HasAttribute() { var @class = new Class(typeof(ClassForClassTest)); Assert.AreEqual(true, @class.HasAttribute(typeof (SerializableAttribute))); Assert.AreEqual(false, @class.HasAttribute(typeof (TestFixtureAttribute))); }
public void HasAttributes() { var @class = new Class(typeof(ClassForClassTest)); bool b = @class.GetProperty("SomeProperty").HasAttribute(typeof(XmlIgnoreAttribute)); Assert.AreEqual(true, b); }
public void ShouldStoreParameterTypeOfMethod() { var @class = new Class(typeof(TestServiceForServiceCallTest)); var serviceCall = new ServiceCall(new TestServiceForServiceCallTest(), @class.GetMethod("Method").MethodInfo); Assert.AreEqual("System.String", serviceCall.ParameterTypes[0]); }
public void GetProperty() { var @class = new Class(typeof(ClassForClassTest)); Assert.AreNotEqual(null, @class.GetProperty("SomeProperty")); }
public void SetUp() { @class = new Class(typeof(TestService)); executionHistory = new ExecutionHistory(); serviceExecution = new ServiceExecution(executionHistory, new NullWorkEnvironment()); }
public void AllNonStandardTypesFromArray() { var @class = new Class(typeof(object[])); @class.AllNonAutoSerializableTypes(); }
public void AllNonStandardTypes() { var @class = new Class(typeof(ClassContainingVarietyOfTypes)); List<Type> types = @class.AllNonAutoSerializableTypes(); Assert.AreEqual(5, types.Count); Assert.AreEqual(true, types.Contains(typeof(ClassContainingVarietyOfTypes))); Assert.AreEqual(true, types.Contains(typeof(NestedClassContainingVarietyOfTypes))); Assert.AreEqual(true, types.Contains(typeof(FileOptions))); Assert.AreEqual(true, types.Contains(typeof(BaseClassForClassTest))); Assert.AreEqual(true, types.Contains(typeof(InternalConstructorClass))); }
public void AttributeValue() { Class @class = new Class(typeof(TestClass_WithAttribute)); CategoryAttribute categoryAttribute = @class.Attribute<CategoryAttribute>(); Assert.AreEqual("Normal", categoryAttribute.Name); }
public void IsProperty() { var @class = new Class(typeof(ClassForClassTest)); Assert.AreEqual(true, @class.IsProperty("StringProperty")); Assert.AreEqual(false, @class.IsProperty("ToString")); }
public void GetFieldGetsFieldsFromBaseClasses() { var @class = new Class(typeof(ClassForClassTest)); Assert.AreNotEqual(null, @class.GetField("fieldInBaseClass")); }
public ScreenClass(Class @class) { this.@class = @class; if (@class.NonVirtuals.Count != 0) throw AppScreenException.NonVirtualMethods(@class.NonVirtuals); }
public void GetMethodFromTheBaseClassToo() { var @class = new Class(typeof(ClassForClassTest)); Assert.AreNotEqual(null, @class.GetMethod("SomeBaseClassMethod")); }
private string BuildStringRepresentation(Translate translate) { StringBuilder builder = new StringBuilder(); Class @class = new Class(GetType()); @class.EachField(delegate(FieldInfo fieldInfo) { if (fieldInfo.GetCustomAttributes(typeof (ScreenIgnoreAttribute), false).Length != 1) builder.Append(translate(fieldInfo)); }); return builder.ToString(); }