public void BasicClassAttributeTest() { var assembly = System.Reflection.Assembly.UnsafeLoadFrom("FFITarget.dll"); var testClass = assembly.GetType("FFITarget.TestCSharpAttribute"); var testMethod = testClass.GetMethod("Test"); String code = @"import(""FFITarget.dll"");"; var execMirror = thisTest.RunScriptSource(code); var core =execMirror.MirrorTarget.Core; ClassMirror classMirror = new ClassMirror("TestCSharpAttribute", core); Assert.IsNotNull(classMirror); var classAttributes = classMirror.GetClassAttributes(); Assert.IsNotNull(classAttributes); var ffiClassAttribute = classAttributes as FFIClassAttributes; Assert.IsNotNull(ffiClassAttribute); var classCustomAttributes = ffiClassAttribute.Attributes; Assert.AreEqual(2, classCustomAttributes.Count()); Assert.IsTrue(classCustomAttributes.SequenceEqual(testClass.GetCustomAttributes(false))); MethodMirror methodMirror = classMirror.GetFunctions().FirstOrDefault(m => m.MethodName.Equals("Test")); var methodAttributes = methodMirror.GetMethodAttributes(); Assert.IsNotNull(methodAttributes); var ffiMethodAttributes = methodAttributes as FFIMethodAttributes; Assert.IsNotNull(ffiMethodAttributes); var methodCustomAttributes = ffiMethodAttributes.Attributes; Assert.AreEqual(2, methodCustomAttributes.Count()); Assert.IsTrue(methodCustomAttributes.SequenceEqual(testMethod.GetCustomAttributes(false))); }
public IEnumerable <String> GetMembers() { List <string> members = new List <string>(); Validity.Assert(mirrorData != null); ClassMirror type = mirrorData.Class; if (type == null) { return(members); } IEnumerable <ClassMirror> baseClasses = type.GetClassHierarchy(); foreach (var baseClass in baseClasses) { foreach (var method in baseClass.GetFunctions()) { if (!members.Contains(method.MethodName)) { members.Add(method.MethodName); } } foreach (var property in baseClass.GetProperties()) { if (!members.Contains(property.PropertyName)) { members.Add(property.PropertyName); } } } foreach (var method in type.GetFunctions()) { if (!members.Contains(method.MethodName)) { members.Add(method.MethodName); } } foreach (var property in type.GetProperties()) { if (!members.Contains(property.PropertyName)) { members.Add(property.PropertyName); } } return(members); }
public void BasicClassAttributeTest() { var assembly = System.Reflection.Assembly.UnsafeLoadFrom("FFITarget.dll"); var testClass = assembly.GetType("FFITarget.TestCSharpAttribute"); var testMethod = testClass.GetMethod("Test"); String code = @"import(""FFITarget.dll"");"; var execMirror = thisTest.RunScriptSource(code); var core = execMirror.MirrorTarget.Core; ClassMirror classMirror = new ClassMirror("TestCSharpAttribute", core); Assert.IsNotNull(classMirror); var classAttributes = classMirror.GetClassAttributes(); Assert.IsNotNull(classAttributes); var ffiClassAttribute = classAttributes as FFIClassAttributes; Assert.IsNotNull(ffiClassAttribute); var classCustomAttributes = ffiClassAttribute.Attributes; Assert.AreEqual(2, classCustomAttributes.Count()); Assert.IsTrue(classCustomAttributes.SequenceEqual(testClass.GetCustomAttributes(false))); MethodMirror methodMirror = classMirror.GetFunctions().FirstOrDefault(m => m.MethodName.Equals("Test")); var methodAttributes = methodMirror.GetMethodAttributes(); Assert.IsNotNull(methodAttributes); var ffiMethodAttributes = methodAttributes as FFIMethodAttributes; Assert.IsNotNull(ffiMethodAttributes); var methodCustomAttributes = ffiMethodAttributes.Attributes; Assert.AreEqual(2, methodCustomAttributes.Count()); Assert.IsTrue(methodCustomAttributes.SequenceEqual(testMethod.GetCustomAttributes(false))); }
private void ProcessClassItem(ClassMirror classMirror, LibraryItem classItem) { classItem.Assembly = classMirror.GetAssembly().LibraryName; foreach (MethodMirror constructorMirror in classMirror.GetConstructors()) { LibraryItem constructorItem = new LibraryItem(NodeType.Function, constructorMirror.MethodName, constructorMirror); constructorItem.ArgumentTypes = GetArgumentTypes(constructorMirror.GetArgumentTypes()); constructorItem.Assembly = classMirror.GetAssembly().LibraryName; constructorItem.Type = LibraryItem.MemberType.Constructor; classItem.AddChildItem(constructorItem); } foreach (MethodMirror methodMirror in classMirror.GetFunctions()) { if (!methodMirror.IsStatic) continue; LibraryItem staticMethodItem = new LibraryItem(NodeType.Function, methodMirror.MethodName, methodMirror); staticMethodItem.ArgumentTypes = GetArgumentTypes(methodMirror.GetArgumentTypes()); staticMethodItem.Assembly = classMirror.GetAssembly().LibraryName; staticMethodItem.Type = LibraryItem.MemberType.StaticMethod; classItem.AddChildItem(staticMethodItem); } GroupOverloadedItem(classItem); foreach (PropertyMirror propertyMirror in classMirror.GetProperties()) { if (!propertyMirror.IsStatic) continue; LibraryItem staticPropertyItem = new LibraryItem(NodeType.Function, propertyMirror.PropertyName, propertyMirror); staticPropertyItem.ArgumentTypes = string.Empty;//GetArgumentTypes(propertyMirror. staticPropertyItem.Type = LibraryItem.MemberType.StaticProperty; if (propertyMirror.IsSetter) staticPropertyItem.DisplayText += UiStrings.OverloadDisplayTextSetter; else staticPropertyItem.DisplayText += UiStrings.OverloadDisplayTextGetter; classItem.AddChildItem(staticPropertyItem); } }